neurarch 0.3.0 → 0.5.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.
- package/README.md +181 -9
- package/bin/gate.mjs +259 -0
- package/bin/neurarch.mjs +31 -6
- package/bin/scan.mjs +444 -0
- package/bin/templateCheck.mjs +102 -0
- package/bin/weightsDiff.mjs +35 -0
- package/engine.bundle.mjs +5777 -1061
- package/package.json +11 -3
- package/policy.bundle.mjs +1405 -54
package/policy.bundle.mjs
CHANGED
|
@@ -1972,7 +1972,7 @@ function stringifyFlowCollection({ items }, ctx, { flowChars, itemIndent }) {
|
|
|
1972
1972
|
str += ",";
|
|
1973
1973
|
} else if (ctx.options.trailingComma) {
|
|
1974
1974
|
if (ctx.options.lineWidth > 0) {
|
|
1975
|
-
reqNewline || (reqNewline = lines.reduce((
|
|
1975
|
+
reqNewline || (reqNewline = lines.reduce((sum2, line) => sum2 + line.length + 2, 2) + (str.length + 2) > ctx.options.lineWidth);
|
|
1976
1976
|
}
|
|
1977
1977
|
if (reqNewline) {
|
|
1978
1978
|
str += ",";
|
|
@@ -1988,7 +1988,7 @@ function stringifyFlowCollection({ items }, ctx, { flowChars, itemIndent }) {
|
|
|
1988
1988
|
return start + end;
|
|
1989
1989
|
} else {
|
|
1990
1990
|
if (!reqNewline) {
|
|
1991
|
-
const len = lines.reduce((
|
|
1991
|
+
const len = lines.reduce((sum2, line) => sum2 + line.length + 2, 2);
|
|
1992
1992
|
reqNewline = ctx.options.lineWidth > 0 && len > ctx.options.lineWidth;
|
|
1993
1993
|
}
|
|
1994
1994
|
if (reqNewline) {
|
|
@@ -5320,9 +5320,9 @@ var Lexer = class {
|
|
|
5320
5320
|
}
|
|
5321
5321
|
}
|
|
5322
5322
|
*parseQuotedScalar() {
|
|
5323
|
-
const
|
|
5324
|
-
let end = this.buffer.indexOf(
|
|
5325
|
-
if (
|
|
5323
|
+
const quote2 = this.charAt(0);
|
|
5324
|
+
let end = this.buffer.indexOf(quote2, this.pos + 1);
|
|
5325
|
+
if (quote2 === "'") {
|
|
5326
5326
|
while (end !== -1 && this.buffer[end + 1] === "'")
|
|
5327
5327
|
end = this.buffer.indexOf("'", end + 2);
|
|
5328
5328
|
} else {
|
|
@@ -5801,8 +5801,8 @@ var Parser = class {
|
|
|
5801
5801
|
return st;
|
|
5802
5802
|
}
|
|
5803
5803
|
*step() {
|
|
5804
|
-
const
|
|
5805
|
-
if (this.type === "doc-end" &&
|
|
5804
|
+
const top2 = this.peek(1);
|
|
5805
|
+
if (this.type === "doc-end" && top2?.type !== "doc-end") {
|
|
5806
5806
|
while (this.stack.length > 0)
|
|
5807
5807
|
yield* this.pop();
|
|
5808
5808
|
this.stack.push({
|
|
@@ -5812,26 +5812,26 @@ var Parser = class {
|
|
|
5812
5812
|
});
|
|
5813
5813
|
return;
|
|
5814
5814
|
}
|
|
5815
|
-
if (!
|
|
5815
|
+
if (!top2)
|
|
5816
5816
|
return yield* this.stream();
|
|
5817
|
-
switch (
|
|
5817
|
+
switch (top2.type) {
|
|
5818
5818
|
case "document":
|
|
5819
|
-
return yield* this.document(
|
|
5819
|
+
return yield* this.document(top2);
|
|
5820
5820
|
case "alias":
|
|
5821
5821
|
case "scalar":
|
|
5822
5822
|
case "single-quoted-scalar":
|
|
5823
5823
|
case "double-quoted-scalar":
|
|
5824
|
-
return yield* this.scalar(
|
|
5824
|
+
return yield* this.scalar(top2);
|
|
5825
5825
|
case "block-scalar":
|
|
5826
|
-
return yield* this.blockScalar(
|
|
5826
|
+
return yield* this.blockScalar(top2);
|
|
5827
5827
|
case "block-map":
|
|
5828
|
-
return yield* this.blockMap(
|
|
5828
|
+
return yield* this.blockMap(top2);
|
|
5829
5829
|
case "block-seq":
|
|
5830
|
-
return yield* this.blockSequence(
|
|
5830
|
+
return yield* this.blockSequence(top2);
|
|
5831
5831
|
case "flow-collection":
|
|
5832
|
-
return yield* this.flowCollection(
|
|
5832
|
+
return yield* this.flowCollection(top2);
|
|
5833
5833
|
case "doc-end":
|
|
5834
|
-
return yield* this.documentEnd(
|
|
5834
|
+
return yield* this.documentEnd(top2);
|
|
5835
5835
|
}
|
|
5836
5836
|
yield* this.pop();
|
|
5837
5837
|
}
|
|
@@ -5846,25 +5846,25 @@ var Parser = class {
|
|
|
5846
5846
|
} else if (this.stack.length === 0) {
|
|
5847
5847
|
yield token;
|
|
5848
5848
|
} else {
|
|
5849
|
-
const
|
|
5849
|
+
const top2 = this.peek(1);
|
|
5850
5850
|
if (token.type === "block-scalar") {
|
|
5851
|
-
token.indent = "indent" in
|
|
5852
|
-
} else if (token.type === "flow-collection" &&
|
|
5851
|
+
token.indent = "indent" in top2 ? top2.indent : 0;
|
|
5852
|
+
} else if (token.type === "flow-collection" && top2.type === "document") {
|
|
5853
5853
|
token.indent = 0;
|
|
5854
5854
|
}
|
|
5855
5855
|
if (token.type === "flow-collection")
|
|
5856
5856
|
fixFlowSeqItems(token);
|
|
5857
|
-
switch (
|
|
5857
|
+
switch (top2.type) {
|
|
5858
5858
|
case "document":
|
|
5859
|
-
|
|
5859
|
+
top2.value = token;
|
|
5860
5860
|
break;
|
|
5861
5861
|
case "block-scalar":
|
|
5862
|
-
|
|
5862
|
+
top2.props.push(token);
|
|
5863
5863
|
break;
|
|
5864
5864
|
case "block-map": {
|
|
5865
|
-
const it =
|
|
5865
|
+
const it = top2.items[top2.items.length - 1];
|
|
5866
5866
|
if (it.value) {
|
|
5867
|
-
|
|
5867
|
+
top2.items.push({ start: [], key: token, sep: [] });
|
|
5868
5868
|
this.onKeyLine = true;
|
|
5869
5869
|
return;
|
|
5870
5870
|
} else if (it.sep) {
|
|
@@ -5877,17 +5877,17 @@ var Parser = class {
|
|
|
5877
5877
|
break;
|
|
5878
5878
|
}
|
|
5879
5879
|
case "block-seq": {
|
|
5880
|
-
const it =
|
|
5880
|
+
const it = top2.items[top2.items.length - 1];
|
|
5881
5881
|
if (it.value)
|
|
5882
|
-
|
|
5882
|
+
top2.items.push({ start: [], value: token });
|
|
5883
5883
|
else
|
|
5884
5884
|
it.value = token;
|
|
5885
5885
|
break;
|
|
5886
5886
|
}
|
|
5887
5887
|
case "flow-collection": {
|
|
5888
|
-
const it =
|
|
5888
|
+
const it = top2.items[top2.items.length - 1];
|
|
5889
5889
|
if (!it || it.value)
|
|
5890
|
-
|
|
5890
|
+
top2.items.push({ start: [], key: token, sep: [] });
|
|
5891
5891
|
else if (it.sep)
|
|
5892
5892
|
it.value = token;
|
|
5893
5893
|
else
|
|
@@ -5899,13 +5899,13 @@ var Parser = class {
|
|
|
5899
5899
|
yield* this.pop();
|
|
5900
5900
|
yield* this.pop(token);
|
|
5901
5901
|
}
|
|
5902
|
-
if ((
|
|
5902
|
+
if ((top2.type === "document" || top2.type === "block-map" || top2.type === "block-seq") && (token.type === "block-map" || token.type === "block-seq")) {
|
|
5903
5903
|
const last = token.items[token.items.length - 1];
|
|
5904
5904
|
if (last && !last.sep && !last.value && last.start.length > 0 && findNonEmptyIndex(last.start) === -1 && (token.indent === 0 || last.start.every((st) => st.type !== "comment" || st.indent < token.indent))) {
|
|
5905
|
-
if (
|
|
5906
|
-
|
|
5905
|
+
if (top2.type === "document")
|
|
5906
|
+
top2.end = last.start;
|
|
5907
5907
|
else
|
|
5908
|
-
|
|
5908
|
+
top2.items.push({ start: last.start });
|
|
5909
5909
|
token.items.splice(-1, 1);
|
|
5910
5910
|
}
|
|
5911
5911
|
}
|
|
@@ -6276,11 +6276,11 @@ var Parser = class {
|
|
|
6276
6276
|
*flowCollection(fc) {
|
|
6277
6277
|
const it = fc.items[fc.items.length - 1];
|
|
6278
6278
|
if (this.type === "flow-error-end") {
|
|
6279
|
-
let
|
|
6279
|
+
let top2;
|
|
6280
6280
|
do {
|
|
6281
6281
|
yield* this.pop();
|
|
6282
|
-
|
|
6283
|
-
} while (
|
|
6282
|
+
top2 = this.peek(1);
|
|
6283
|
+
} while (top2?.type === "flow-collection");
|
|
6284
6284
|
} else if (fc.end.length === 0) {
|
|
6285
6285
|
switch (this.type) {
|
|
6286
6286
|
case "comma":
|
|
@@ -7231,6 +7231,7 @@ var PIN_RULE_META = {
|
|
|
7231
7231
|
"pin/hf-floating-revision": { code: "NX-PIN-002", severity: "warn", bandit: "B615", summary: "A Hugging Face download names a branch or tag (main, v1.0, refs/pr/1), which can be moved, instead of a commit." },
|
|
7232
7232
|
"pin/hf-unpinned-dynamic": { code: "NX-PIN-003", severity: "info", bandit: "B615", summary: "A Hugging Face download takes its repo id from a variable and has no revision; if the value is a Hub id, it is not pinned." }
|
|
7233
7233
|
};
|
|
7234
|
+
var KEEP_PINNED = false;
|
|
7234
7235
|
var HEX7 = /^[0-9a-fA-F]{7,}$/;
|
|
7235
7236
|
var HUB_ID = /^[A-Za-z0-9][\w.-]*(?:\/[\w.-]+)?$/;
|
|
7236
7237
|
var LOCAL = /^(?:\.{1,2}\/|\/|~)/;
|
|
@@ -7244,6 +7245,37 @@ function pinFileKind(path) {
|
|
|
7244
7245
|
if (/\.(sh|bash|zsh|slurm|sbatch)$/i.test(base) || /^Dockerfile/i.test(base) || /\.dockerfile$/i.test(base)) return "shell";
|
|
7245
7246
|
return null;
|
|
7246
7247
|
}
|
|
7248
|
+
function refFileKind(path) {
|
|
7249
|
+
const base = path.split("/").pop() ?? path;
|
|
7250
|
+
if (base === "adapter_config.json") return "adapter";
|
|
7251
|
+
return pinFileKind(path);
|
|
7252
|
+
}
|
|
7253
|
+
function engineIn(text) {
|
|
7254
|
+
const v = /vllm\/vllm-openai:v?(\d+\.\d+(?:\.\d+)?)/.exec(text) ?? /\bvllm(?:\[[\w,]+\])?==(\d+\.\d+(?:\.\d+)?)/.exec(text) ?? /(?<!lmcache\/)vllm-openai:v?(\d+\.\d+(?:\.\d+)?)/.exec(text) ?? /repository:\s*["']?(?:docker\.io\/)?vllm\/vllm-openai["']?\s*\n\s*tag:\s*["']?v?(\d+\.\d+(?:\.\d+)?)/.exec(text);
|
|
7255
|
+
if (v) return { name: "vllm", version: v[1] };
|
|
7256
|
+
const sg = /lmsysorg\/sglang:v?(\d+\.\d+(?:\.\d+)?)/.exec(text) ?? /\bsglang(?:\[[\w,]+\])?==(\d+\.\d+(?:\.\d+)?)/.exec(text);
|
|
7257
|
+
if (sg) return { name: "sglang", version: sg[1] };
|
|
7258
|
+
if (/\bvllm serve\b|vllm\.entrypoints|vllm\/vllm-openai/.test(text)) return { name: "vllm" };
|
|
7259
|
+
if (/sglang\.launch_server|lmsysorg\/sglang/.test(text)) return { name: "sglang" };
|
|
7260
|
+
return void 0;
|
|
7261
|
+
}
|
|
7262
|
+
function scanAdapterConfig(text, path) {
|
|
7263
|
+
let c;
|
|
7264
|
+
try {
|
|
7265
|
+
c = JSON.parse(text);
|
|
7266
|
+
} catch {
|
|
7267
|
+
return [];
|
|
7268
|
+
}
|
|
7269
|
+
if (!c || typeof c !== "object") return [];
|
|
7270
|
+
const o = c;
|
|
7271
|
+
const base = o.base_model_name_or_path;
|
|
7272
|
+
if (typeof base !== "string" || !base.includes("/") || looksLocal(base) || !HUB_ID.test(base)) return [];
|
|
7273
|
+
const rev = typeof o.revision === "string" && o.revision ? o.revision : void 0;
|
|
7274
|
+
const at = text.search(/"base_model_name_or_path"\s*:/);
|
|
7275
|
+
const line = at < 0 ? 1 : text.slice(0, at).split("\n").length;
|
|
7276
|
+
const pinned = !!rev && /^[0-9a-f]{40}$/.test(rev);
|
|
7277
|
+
return [{ rule: rev ? "pin/hf-floating-revision" : "pin/hf-unpinned", path, line, api: "adapter_config.json", repo: base, repoType: "model", revision: rev, syntax: "json", ...pinned ? { pinned } : {}, edge: "adapter-base" }];
|
|
7278
|
+
}
|
|
7247
7279
|
function pyTokens(src) {
|
|
7248
7280
|
const out = [];
|
|
7249
7281
|
let i = 0;
|
|
@@ -7375,7 +7407,7 @@ function pyImports(toks) {
|
|
|
7375
7407
|
}
|
|
7376
7408
|
return m;
|
|
7377
7409
|
}
|
|
7378
|
-
var HF_MODULES = ["transformers", "datasets", "huggingface_hub", "diffusers", "peft"];
|
|
7410
|
+
var HF_MODULES = ["transformers", "datasets", "huggingface_hub", "diffusers", "peft", "sentence_transformers"];
|
|
7379
7411
|
var isHfOrigin = (origin) => !!origin && HF_MODULES.includes(origin.split(".")[0]);
|
|
7380
7412
|
function pyArgs(toks, open) {
|
|
7381
7413
|
const args = [];
|
|
@@ -7419,7 +7451,13 @@ var CALLS = {
|
|
|
7419
7451
|
load_dataset: { repoKw: ["path"], repoPos: 0, repoType: "dataset" },
|
|
7420
7452
|
hf_hub_download: { repoKw: ["repo_id"], repoPos: 0, repoType: "model" },
|
|
7421
7453
|
snapshot_download: { repoKw: ["repo_id"], repoPos: 0, repoType: "model" },
|
|
7422
|
-
pipeline: { repoKw: ["model"], repoPos: 1, repoType: "model" }
|
|
7454
|
+
pipeline: { repoKw: ["model"], repoPos: 1, repoType: "model" },
|
|
7455
|
+
// sentence-transformers downloads from the Hub too, and is how most embedding
|
|
7456
|
+
// models with remote code are loaded (167 of 353 public files sampled on
|
|
7457
|
+
// 2026-11-17 that name one of the cross-repository models).
|
|
7458
|
+
SentenceTransformer: { repoKw: ["model_name_or_path"], repoPos: 0, repoType: "model" },
|
|
7459
|
+
CrossEncoder: { repoKw: ["model_name_or_path", "model_name"], repoPos: 0, repoType: "model" },
|
|
7460
|
+
SparseEncoder: { repoKw: ["model_name_or_path"], repoPos: 0, repoType: "model" }
|
|
7423
7461
|
};
|
|
7424
7462
|
var lineAt = (starts, off) => {
|
|
7425
7463
|
let lo = 0;
|
|
@@ -7437,19 +7475,255 @@ var lineStarts = (src) => {
|
|
|
7437
7475
|
return s;
|
|
7438
7476
|
};
|
|
7439
7477
|
var NOSEC = /#\s*nosec\b(?!\s*:?\s*[A-Z]\d)|#\s*nosec\b[^\n]*\bB615\b/;
|
|
7478
|
+
function pyStringConstants(toks) {
|
|
7479
|
+
const seen = /* @__PURE__ */ new Map();
|
|
7480
|
+
let depth = 0;
|
|
7481
|
+
for (let k = 0; k < toks.length; k++) {
|
|
7482
|
+
const t = toks[k];
|
|
7483
|
+
if (t.t === "op" && "([{".includes(t.v)) depth++;
|
|
7484
|
+
else if (t.t === "op" && ")]}".includes(t.v)) depth = Math.max(0, depth - 1);
|
|
7485
|
+
if (depth || t.t !== "name" || toks[k + 1]?.t !== "op" || toks[k + 1].v !== "=") continue;
|
|
7486
|
+
if (k > 0 && toks[k - 1].t === "op" && toks[k - 1].v === ".") continue;
|
|
7487
|
+
const v = toks[k + 2];
|
|
7488
|
+
const after = toks[k + 3];
|
|
7489
|
+
const single = v?.t === "str" && v.v != null && !(after?.t === "str") && !(after?.t === "op" && [".", "+", "[", "(", "%"].includes(after.v));
|
|
7490
|
+
const value = single ? v.v : null;
|
|
7491
|
+
if (!seen.has(t.v)) seen.set(t.v, value);
|
|
7492
|
+
else if (seen.get(t.v) !== value) seen.set(t.v, null);
|
|
7493
|
+
}
|
|
7494
|
+
const out = /* @__PURE__ */ new Map();
|
|
7495
|
+
for (const [k, v] of seen) if (v != null) out.set(k, v);
|
|
7496
|
+
return out;
|
|
7497
|
+
}
|
|
7498
|
+
function envFallback(toks, k) {
|
|
7499
|
+
let j = k;
|
|
7500
|
+
if (nameOf(toks[j]) === "os" && toks[j + 1]?.t === "op" && toks[j + 1].v === ".") j += 2;
|
|
7501
|
+
if (nameOf(toks[j]) === "environ" && toks[j + 1]?.t === "op" && toks[j + 1].v === "." && nameOf(toks[j + 2]) === "get") j += 2;
|
|
7502
|
+
else if (nameOf(toks[j]) !== "getenv") return void 0;
|
|
7503
|
+
if (toks[j + 1]?.t !== "op" || toks[j + 1].v !== "(") return void 0;
|
|
7504
|
+
const { args, close } = pyArgs(toks, j + 1);
|
|
7505
|
+
const fb = args.length === 2 && !args[1].kw ? literal(args[1]) : literal(args.find((a) => a.kw === "default"));
|
|
7506
|
+
return fb === void 0 ? void 0 : { value: fb, close };
|
|
7507
|
+
}
|
|
7508
|
+
function pyIdSources(toks, starts, consts) {
|
|
7509
|
+
const lineOfTok = (k) => lineAt(starts, toks[k].at);
|
|
7510
|
+
const colOfTok = (k) => toks[k].at - starts[lineOfTok(k) - 1];
|
|
7511
|
+
const scopes = [];
|
|
7512
|
+
for (let k = 0; k + 2 < toks.length; k++) {
|
|
7513
|
+
if (nameOf(toks[k]) !== "def" || toks[k + 1].t !== "name" || toks[k + 2].t !== "op" || toks[k + 2].v !== "(") continue;
|
|
7514
|
+
const { args, close } = pyArgs(toks, k + 2);
|
|
7515
|
+
const params = /* @__PURE__ */ new Map();
|
|
7516
|
+
for (const a of args) {
|
|
7517
|
+
if (a.star) continue;
|
|
7518
|
+
const name = a.kw ?? nameOf(a.toks[0]);
|
|
7519
|
+
if (!name) continue;
|
|
7520
|
+
let value = a.kw ? a : void 0;
|
|
7521
|
+
if (!a.kw) {
|
|
7522
|
+
let depth3 = 0;
|
|
7523
|
+
let eq = -1;
|
|
7524
|
+
a.toks.forEach((t, i) => {
|
|
7525
|
+
if (t.t !== "op") return;
|
|
7526
|
+
if ("([{".includes(t.v)) depth3++;
|
|
7527
|
+
else if (")]}".includes(t.v)) depth3--;
|
|
7528
|
+
else if (t.v === "=" && depth3 === 0) eq = i;
|
|
7529
|
+
});
|
|
7530
|
+
if (eq > 0) value = { toks: a.toks.slice(eq + 1) };
|
|
7531
|
+
}
|
|
7532
|
+
params.set(name, literal(value) ?? null);
|
|
7533
|
+
}
|
|
7534
|
+
const col = colOfTok(k);
|
|
7535
|
+
let to = toks.length;
|
|
7536
|
+
let depth2 = 0;
|
|
7537
|
+
for (let j = close + 1; j < toks.length; j++) {
|
|
7538
|
+
const t = toks[j];
|
|
7539
|
+
if (t.t === "op" && "([{".includes(t.v)) depth2++;
|
|
7540
|
+
else if (t.t === "op" && ")]}".includes(t.v)) depth2 = Math.max(0, depth2 - 1);
|
|
7541
|
+
else if (depth2 === 0 && lineOfTok(j) !== lineOfTok(j - 1) && lineOfTok(j) > lineOfTok(close) && colOfTok(j) <= col) {
|
|
7542
|
+
to = j;
|
|
7543
|
+
break;
|
|
7544
|
+
}
|
|
7545
|
+
}
|
|
7546
|
+
scopes.push({ from: close, to, params });
|
|
7547
|
+
}
|
|
7548
|
+
const paramDefault = (name, at) => {
|
|
7549
|
+
let best;
|
|
7550
|
+
for (const s of scopes) if (at > s.from && at < s.to && s.params.has(name) && (!best || s.from > best.from)) best = s;
|
|
7551
|
+
return best?.params.get(name) ?? void 0;
|
|
7552
|
+
};
|
|
7553
|
+
const argDefaults = /* @__PURE__ */ new Map();
|
|
7554
|
+
const setArg = (dest, v) => argDefaults.set(dest, argDefaults.has(dest) && argDefaults.get(dest) !== v ? null : v);
|
|
7555
|
+
for (let k = 1; k + 1 < toks.length; k++) {
|
|
7556
|
+
const n = nameOf(toks[k]);
|
|
7557
|
+
if (n !== "add_argument" && n !== "set_defaults" || toks[k - 1].t !== "op" || toks[k - 1].v !== "." || toks[k + 1].t !== "op" || toks[k + 1].v !== "(") continue;
|
|
7558
|
+
const { args } = pyArgs(toks, k + 1);
|
|
7559
|
+
if (n === "set_defaults") {
|
|
7560
|
+
for (const a of args) {
|
|
7561
|
+
const v = a.kw ? literal(a) : void 0;
|
|
7562
|
+
if (a.kw && v !== void 0) setArg(a.kw, v);
|
|
7563
|
+
}
|
|
7564
|
+
continue;
|
|
7565
|
+
}
|
|
7566
|
+
const dflt = literal(args.find((a) => a.kw === "default"));
|
|
7567
|
+
if (dflt === void 0) continue;
|
|
7568
|
+
const flags = args.filter((a) => !a.kw && !a.star).map((a) => literal(a)).filter((x) => x !== void 0);
|
|
7569
|
+
const dest = literal(args.find((a) => a.kw === "dest")) ?? (flags.find((f) => f.startsWith("--")) ?? flags.find((f) => !f.startsWith("-")))?.replace(/^--/, "").replace(/-/g, "_");
|
|
7570
|
+
if (dest) setArg(dest, dflt);
|
|
7571
|
+
}
|
|
7572
|
+
const envConsts = /* @__PURE__ */ new Map();
|
|
7573
|
+
const attrs = /* @__PURE__ */ new Map();
|
|
7574
|
+
let depth = 0;
|
|
7575
|
+
for (let k = 0; k < toks.length; k++) {
|
|
7576
|
+
const t = toks[k];
|
|
7577
|
+
if (t.t === "op" && "([{".includes(t.v)) depth++;
|
|
7578
|
+
else if (t.t === "op" && ")]}".includes(t.v)) depth = Math.max(0, depth - 1);
|
|
7579
|
+
if (depth || t.t !== "name") continue;
|
|
7580
|
+
const eqAt = toks[k + 1]?.t === "op" && toks[k + 1].v === "=" ? k + 1 : -1;
|
|
7581
|
+
if (eqAt < 0) continue;
|
|
7582
|
+
const isAttr = k >= 2 && toks[k - 1].t === "op" && toks[k - 1].v === "." && (nameOf(toks[k - 2]) === "self" || nameOf(toks[k - 2]) === "cls") && !(toks[k - 3]?.t === "op" && toks[k - 3].v === ".");
|
|
7583
|
+
if (k > 0 && toks[k - 1].t === "op" && toks[k - 1].v === "." && !isAttr) continue;
|
|
7584
|
+
const v = toks[eqAt + 1];
|
|
7585
|
+
if (!v) continue;
|
|
7586
|
+
const env = envFallback(toks, eqAt + 1);
|
|
7587
|
+
const endsAt = env ? env.close : eqAt + 1;
|
|
7588
|
+
const after = toks[endsAt + 1];
|
|
7589
|
+
const alone = !after || lineOfTok(endsAt + 1) !== lineOfTok(endsAt);
|
|
7590
|
+
let r = null;
|
|
7591
|
+
if (alone && env) r = { value: env.value, via: "default" };
|
|
7592
|
+
else if (alone && v.t === "str" && v.v != null) r = { value: v.v, via: "variable" };
|
|
7593
|
+
else if (alone && v.t === "name" && isAttr) {
|
|
7594
|
+
const d = paramDefault(v.v, k);
|
|
7595
|
+
const c = d === void 0 ? consts.get(v.v) : void 0;
|
|
7596
|
+
r = d !== void 0 ? { value: d, via: "default" } : c !== void 0 ? { value: c, via: "variable" } : null;
|
|
7597
|
+
}
|
|
7598
|
+
if (isAttr) attrs.set(t.v, attrs.has(t.v) && attrs.get(t.v)?.value !== r?.value ? null : r);
|
|
7599
|
+
else if (env) envConsts.set(t.v, envConsts.has(t.v) && envConsts.get(t.v) !== (alone ? env.value : null) ? null : alone ? env.value : null);
|
|
7600
|
+
}
|
|
7601
|
+
return (a, at) => {
|
|
7602
|
+
if (!a || !a.toks.length) return void 0;
|
|
7603
|
+
const ts = a.toks;
|
|
7604
|
+
const isOp = (t, v) => t?.t === "op" && t.v === v;
|
|
7605
|
+
if (ts.length === 1 && ts[0].t === "name") {
|
|
7606
|
+
const d = paramDefault(ts[0].v, at);
|
|
7607
|
+
if (d !== void 0) return { value: d, via: "default" };
|
|
7608
|
+
const e = envConsts.get(ts[0].v);
|
|
7609
|
+
if (e != null && !consts.has(ts[0].v)) return { value: e, via: "default" };
|
|
7610
|
+
const c = consts.get(ts[0].v);
|
|
7611
|
+
return c === void 0 ? void 0 : { value: c, via: "variable" };
|
|
7612
|
+
}
|
|
7613
|
+
if (ts.length === 3 && ts[0].t === "name" && isOp(ts[1], ".") && ts[2].t === "name") {
|
|
7614
|
+
if (ts[0].v === "self" || ts[0].v === "cls") {
|
|
7615
|
+
const r = attrs.get(ts[2].v);
|
|
7616
|
+
if (r) return r;
|
|
7617
|
+
const c = attrs.has(ts[2].v) ? void 0 : consts.get(ts[2].v);
|
|
7618
|
+
return c === void 0 ? void 0 : { value: c, via: "variable" };
|
|
7619
|
+
}
|
|
7620
|
+
const d = argDefaults.get(ts[2].v);
|
|
7621
|
+
return d == null ? void 0 : { value: d, via: "default" };
|
|
7622
|
+
}
|
|
7623
|
+
const last = ts[ts.length - 1];
|
|
7624
|
+
if (last.t === "str" && last.v != null && (ts.length === 3 && ts[0].t === "name" && nameOf(ts[1]) === "or" || ts.length === 5 && ts[0].t === "name" && nameOf(ts[1]) === "if" && nameOf(ts[3]) === "else")) return { value: last.v, via: "default" };
|
|
7625
|
+
const env = envFallback(ts, 0);
|
|
7626
|
+
if (env && env.close === ts.length - 1) return { value: env.value, via: "default" };
|
|
7627
|
+
return void 0;
|
|
7628
|
+
};
|
|
7629
|
+
}
|
|
7630
|
+
var WRAPPER_CALLS = {
|
|
7631
|
+
HuggingFaceEmbedding: { repoKw: ["model_name"], repoPos: 0 },
|
|
7632
|
+
// llama_index
|
|
7633
|
+
HuggingFaceEmbeddings: { repoKw: ["model_name"], repoPos: -1 },
|
|
7634
|
+
// langchain: keyword only
|
|
7635
|
+
HuggingFaceBgeEmbeddings: { repoKw: ["model_name"], repoPos: -1 }
|
|
7636
|
+
};
|
|
7637
|
+
var WRAPPER_MODULES = ["llama_index", "langchain", "langchain_huggingface", "langchain_community"];
|
|
7638
|
+
var isWrapperOrigin = (origin) => !!origin && WRAPPER_MODULES.includes(origin.split(".")[0]);
|
|
7639
|
+
var RECORD_NAME_KWS = ["name", "model", "model_name", "model_id", "repo_id", "hf_model_id", "model_name_or_path"];
|
|
7440
7640
|
function scanPython(src, path, lineOf = (l) => l) {
|
|
7441
7641
|
const toks = pyTokens(src);
|
|
7442
7642
|
const imports = pyImports(toks);
|
|
7443
|
-
const hfImported = [...imports.values()].some(isHfOrigin);
|
|
7444
|
-
if (!hfImported) return [];
|
|
7643
|
+
const hfImported = [...imports.values()].some(isHfOrigin) || KEEP_PINNED && [...imports.values()].some(isWrapperOrigin);
|
|
7644
|
+
if (!hfImported && !KEEP_PINNED) return [];
|
|
7445
7645
|
const starts = lineStarts(src);
|
|
7446
7646
|
const lines = src.split("\n");
|
|
7447
7647
|
const hits = [];
|
|
7648
|
+
const consts = KEEP_PINNED ? pyStringConstants(toks) : /* @__PURE__ */ new Map();
|
|
7649
|
+
const named = (a) => a && a.toks.length === 1 && a.toks[0].t === "name" ? consts.get(a.toks[0].v) : void 0;
|
|
7650
|
+
const idSource = KEEP_PINNED ? pyIdSources(toks, starts, consts) : void 0;
|
|
7651
|
+
const callSpan = (k, close) => [lineAt(starts, toks[k].at), lineAt(starts, toks[close]?.at ?? toks[k].at)];
|
|
7652
|
+
if (KEEP_PINNED) {
|
|
7653
|
+
for (let k = 0; k < toks.length; k++) {
|
|
7654
|
+
const t = toks[k];
|
|
7655
|
+
if (t.t !== "name" || CALLS[t.v] || toks[k + 1]?.t !== "op" || toks[k + 1].v !== "(") continue;
|
|
7656
|
+
if (k > 0 && toks[k - 1].t === "name" && toks[k - 1].v === "def") continue;
|
|
7657
|
+
const { args, close } = pyArgs(toks, k + 1);
|
|
7658
|
+
const kw = (name) => args.find((a) => a.kw === name);
|
|
7659
|
+
const revArg = kw("revision");
|
|
7660
|
+
const rev = literal(revArg) ?? named(revArg);
|
|
7661
|
+
if (!rev || !isPinnedRevision(rev)) continue;
|
|
7662
|
+
const nameArg = RECORD_NAME_KWS.map(kw).find(Boolean);
|
|
7663
|
+
const repo = literal(nameArg) ?? named(nameArg);
|
|
7664
|
+
if (!repo || !repo.includes("/") || looksLocal(repo) || !HUB_ID.test(repo)) continue;
|
|
7665
|
+
const [first, last] = callSpan(k, close);
|
|
7666
|
+
if (lines.slice(first - 1, last).some((l) => NOSEC.test(l))) continue;
|
|
7667
|
+
hits.push({ rule: "pin/hf-floating-revision", path, line: lineOf(first), api: t.v, repo, repoType: "model", revision: rev, syntax: "python", pinned: true, via: "record", ...lines.slice(first - 1, last).some((l) => /code_revision/.test(l)) ? { codeRevision: true } : {} });
|
|
7668
|
+
}
|
|
7669
|
+
}
|
|
7670
|
+
if (KEEP_PINNED) {
|
|
7671
|
+
for (let k = 0; k < toks.length; k++) {
|
|
7672
|
+
if (toks[k].t !== "op" || toks[k].v !== "{") continue;
|
|
7673
|
+
let depth = 1;
|
|
7674
|
+
let owner;
|
|
7675
|
+
let nest = 0;
|
|
7676
|
+
for (let b = k - 1; b >= 0 && b >= k - 20; b--) {
|
|
7677
|
+
const x = toks[b];
|
|
7678
|
+
if (x.t === "op" && (x.v === "]" || x.v === ")")) {
|
|
7679
|
+
nest++;
|
|
7680
|
+
continue;
|
|
7681
|
+
}
|
|
7682
|
+
if (x.t === "op" && (x.v === "[" || x.v === "(")) {
|
|
7683
|
+
if (nest > 0) {
|
|
7684
|
+
nest--;
|
|
7685
|
+
continue;
|
|
7686
|
+
}
|
|
7687
|
+
break;
|
|
7688
|
+
}
|
|
7689
|
+
if (nest > 0) continue;
|
|
7690
|
+
if (x.t === "op" && (x.v === "," || x.v === "{")) break;
|
|
7691
|
+
if (x.t === "name" && toks[b + 1]?.t === "op" && (toks[b + 1].v === "=" || toks[b + 1].v === ":") && (b === 0 || lineAt(starts, toks[b - 1].at) !== lineAt(starts, x.at))) {
|
|
7692
|
+
owner = x.v;
|
|
7693
|
+
break;
|
|
7694
|
+
}
|
|
7695
|
+
}
|
|
7696
|
+
for (let j = k + 1; j < toks.length && depth > 0; j++) {
|
|
7697
|
+
const x = toks[j];
|
|
7698
|
+
if (x.t === "op" && (x.v === "{" || x.v === "[" || x.v === "(")) {
|
|
7699
|
+
depth++;
|
|
7700
|
+
continue;
|
|
7701
|
+
}
|
|
7702
|
+
if (x.t === "op" && (x.v === "}" || x.v === "]" || x.v === ")")) {
|
|
7703
|
+
depth--;
|
|
7704
|
+
continue;
|
|
7705
|
+
}
|
|
7706
|
+
if (depth !== 1 || x.t !== "str" || x.v == null) continue;
|
|
7707
|
+
const colon = toks[j + 1];
|
|
7708
|
+
const val = toks[j + 2];
|
|
7709
|
+
const after = toks[j + 3];
|
|
7710
|
+
if (colon?.t !== "op" || colon.v !== ":" || val?.t !== "str" || val.v == null) continue;
|
|
7711
|
+
if (after && !(after.t === "op" && (after.v === "," || after.v === "}"))) continue;
|
|
7712
|
+
if (!/^[0-9a-f]{40}$/.test(val.v) || !x.v.includes("/") || looksLocal(x.v) || !HUB_ID.test(x.v)) continue;
|
|
7713
|
+
const ln = lineAt(starts, x.at);
|
|
7714
|
+
if (NOSEC.test(lines[ln - 1] ?? "")) continue;
|
|
7715
|
+
hits.push({ rule: "pin/hf-floating-revision", path, line: lineOf(ln), api: owner ?? "pin table", repo: x.v, repoType: "model", revision: val.v, syntax: "python", pinned: true, via: "record" });
|
|
7716
|
+
}
|
|
7717
|
+
}
|
|
7718
|
+
}
|
|
7719
|
+
if (!hfImported) return hits;
|
|
7448
7720
|
for (let k = 0; k < toks.length; k++) {
|
|
7449
7721
|
const t = toks[k];
|
|
7450
|
-
if (t.t !== "name"
|
|
7722
|
+
if (t.t !== "name") continue;
|
|
7723
|
+
const wrapper = KEEP_PINNED && !CALLS[t.v] ? WRAPPER_CALLS[t.v] : void 0;
|
|
7724
|
+
if (!CALLS[t.v] && !wrapper || toks[k + 1]?.t !== "op" || toks[k + 1].v !== "(") continue;
|
|
7451
7725
|
if (k > 0 && toks[k - 1].t === "name" && toks[k - 1].v === "def") continue;
|
|
7452
|
-
const spec = CALLS[t.v];
|
|
7726
|
+
const spec = wrapper ? { ...wrapper, repoType: "model" } : CALLS[t.v];
|
|
7453
7727
|
const chain = [t.v];
|
|
7454
7728
|
let r = k - 1;
|
|
7455
7729
|
while (r >= 1 && toks[r].t === "op" && toks[r].v === "." && nameOf(toks[r - 1]) !== void 0) {
|
|
@@ -7459,7 +7733,7 @@ function scanPython(src, path, lineOf = (l) => l) {
|
|
|
7459
7733
|
if (r >= 0 && toks[r].t === "op" && toks[r].v === ".") continue;
|
|
7460
7734
|
const root = chain[0];
|
|
7461
7735
|
const origin = imports.get(root);
|
|
7462
|
-
const resolvesHf = isHfOrigin(origin);
|
|
7736
|
+
const resolvesHf = wrapper ? isWrapperOrigin(origin) : isHfOrigin(origin);
|
|
7463
7737
|
if (chain.length === 1 && !resolvesHf) continue;
|
|
7464
7738
|
if (t.v === "pipeline" && !(origin ?? "").startsWith("transformers")) continue;
|
|
7465
7739
|
const { args, close } = pyArgs(toks, k + 1);
|
|
@@ -7469,31 +7743,56 @@ function scanPython(src, path, lineOf = (l) => l) {
|
|
|
7469
7743
|
const kw = (name) => args.find((a) => a.kw === name);
|
|
7470
7744
|
if (args.some((a) => a.star === "**")) continue;
|
|
7471
7745
|
if (isTrue(kw("local_files_only"))) continue;
|
|
7472
|
-
|
|
7746
|
+
let revArg = kw("revision") ?? kw("commit_id");
|
|
7747
|
+
if (wrapper && !revArg) {
|
|
7748
|
+
const mk = kw("model_kwargs");
|
|
7749
|
+
const at = mk ? mk.toks.findIndex((x, i) => x.t === "str" && x.v === "revision" && mk.toks[i + 1]?.t === "op" && mk.toks[i + 1].v === ":") : -1;
|
|
7750
|
+
if (mk && at >= 0) revArg = { toks: [mk.toks[at + 2]].filter(Boolean) };
|
|
7751
|
+
else if (mk && !(mk.toks[0]?.t === "op" && mk.toks[0].v === "{") && /['"]revision['"]/.test(src)) continue;
|
|
7752
|
+
}
|
|
7473
7753
|
let revision;
|
|
7754
|
+
let via;
|
|
7474
7755
|
if (revArg) {
|
|
7475
|
-
|
|
7756
|
+
let v = literal(revArg);
|
|
7757
|
+
if (v === void 0 && (v = named(revArg)) !== void 0) via = "variable";
|
|
7476
7758
|
if (v === void 0) continue;
|
|
7477
|
-
if (isPinnedRevision(v)) continue;
|
|
7759
|
+
if (isPinnedRevision(v) && !KEEP_PINNED) continue;
|
|
7478
7760
|
revision = v;
|
|
7479
7761
|
}
|
|
7762
|
+
const pinned = revision !== void 0 && isPinnedRevision(revision);
|
|
7480
7763
|
const positional = args.filter((a) => !a.kw && !a.star);
|
|
7481
7764
|
const peft = t.v === "from_pretrained" && /^PeftModel/.test(chain[chain.length - 2] ?? "");
|
|
7482
7765
|
const repoArg = (peft ? kw("model_id") : spec.repoKw.map(kw).find(Boolean)) ?? positional[peft ? 1 : spec.repoPos];
|
|
7483
7766
|
if (!repoArg) continue;
|
|
7484
|
-
|
|
7767
|
+
let repo = literal(repoArg);
|
|
7768
|
+
if (repo === void 0) {
|
|
7769
|
+
const r2 = idSource ? idSource(repoArg, k) : void 0;
|
|
7770
|
+
if (r2) {
|
|
7771
|
+
repo = r2.value;
|
|
7772
|
+
via = r2.via;
|
|
7773
|
+
}
|
|
7774
|
+
}
|
|
7485
7775
|
const api = chain.join(".");
|
|
7776
|
+
let trust;
|
|
7777
|
+
if (KEEP_PINNED && t.v !== "hf_hub_download" && t.v !== "snapshot_download") {
|
|
7778
|
+
const tk = kw("trust_remote_code");
|
|
7779
|
+
const mk = wrapper ? kw("model_kwargs") : void 0;
|
|
7780
|
+
if (tk) trust = !(tk.toks.length === 1 && tk.toks[0].t === "name" && tk.toks[0].v === "False");
|
|
7781
|
+
else if (mk) trust = mk.toks[0]?.t === "op" && mk.toks[0].v === "{" ? mk.toks.some((x) => x.t === "str" && x.v === "trust_remote_code") : void 0;
|
|
7782
|
+
else trust = false;
|
|
7783
|
+
}
|
|
7486
7784
|
const repoType = spec.repoType === "dataset" || kw("repo_type") && literal(kw("repo_type")) === "dataset" ? "dataset" : "model";
|
|
7487
7785
|
const line = lineOf(firstLine);
|
|
7488
7786
|
if (repo === void 0) {
|
|
7489
7787
|
if (!resolvesHf) continue;
|
|
7490
7788
|
if (localExpr(repoArg)) continue;
|
|
7789
|
+
if (pinned) continue;
|
|
7491
7790
|
hits.push({ rule: revision ? "pin/hf-floating-revision" : "pin/hf-unpinned-dynamic", path, line, api, repoType, revision, syntax: "python" });
|
|
7492
7791
|
continue;
|
|
7493
7792
|
}
|
|
7494
7793
|
if (looksLocal(repo) || !HUB_ID.test(repo)) continue;
|
|
7495
7794
|
if (t.v === "load_dataset" && BUILDERS.has(repo)) continue;
|
|
7496
|
-
hits.push({ rule: revision ? "pin/hf-floating-revision" : "pin/hf-unpinned", path, line, api, repo, repoType, revision, syntax: "python" });
|
|
7795
|
+
hits.push({ rule: revision ? "pin/hf-floating-revision" : "pin/hf-unpinned", path, line, api, repo, repoType, revision, syntax: "python", ...pinned ? { pinned } : {}, ...via ? { via } : {}, ...wrapper ? { wrapper: true } : {}, ...KEEP_PINNED && peft ? { adapter: true } : {}, ...trust !== void 0 ? { trustRemoteCode: trust } : {}, ...KEEP_PINNED && (kw("code_revision") || lines.slice(firstLine - 1, lastLine).some((l) => /code_revision/.test(l))) ? { codeRevision: true } : {} });
|
|
7497
7796
|
}
|
|
7498
7797
|
return hits;
|
|
7499
7798
|
}
|
|
@@ -7596,6 +7895,14 @@ function flagValue(words, names) {
|
|
|
7596
7895
|
}
|
|
7597
7896
|
return { present: false };
|
|
7598
7897
|
}
|
|
7898
|
+
function flagValues(words, name) {
|
|
7899
|
+
const out = [];
|
|
7900
|
+
for (let i = 0; i < words.length; i++) {
|
|
7901
|
+
if (words[i].startsWith(`${name}=`)) out.push(words[i].slice(name.length + 1));
|
|
7902
|
+
else if (words[i] === name) for (let j = i + 1; j < words.length && !words[j].startsWith("--"); j++) out.push(words[j]);
|
|
7903
|
+
}
|
|
7904
|
+
return out;
|
|
7905
|
+
}
|
|
7599
7906
|
function launchOf(words) {
|
|
7600
7907
|
for (let i = 0; i < words.length; i++) {
|
|
7601
7908
|
const w = words[i];
|
|
@@ -7624,17 +7931,36 @@ function scanShell(src, path, lineOf = (l) => l) {
|
|
|
7624
7931
|
if (/#\s*nosec\b/.test(ll.raw)) continue;
|
|
7625
7932
|
for (const words of shellCommands(ll.text)) {
|
|
7626
7933
|
const L = launchOf(words);
|
|
7934
|
+
if (KEEP_PINNED && L && L.repoType === "model" && !L.api.endsWith("download")) {
|
|
7935
|
+
const served = L.model && !L.model.startsWith("$") && !looksLocal(L.model) && HUB_ID.test(L.model) ? L.model : void 0;
|
|
7936
|
+
for (const flag of ["--lora-modules", "--lora-paths"]) {
|
|
7937
|
+
for (const v of flagValues(L.rest, flag)) {
|
|
7938
|
+
let id = v.includes("=") ? v.slice(v.indexOf("=") + 1) : v;
|
|
7939
|
+
if (v.startsWith("{")) {
|
|
7940
|
+
try {
|
|
7941
|
+
id = String(JSON.parse(v).path ?? "");
|
|
7942
|
+
} catch {
|
|
7943
|
+
id = "";
|
|
7944
|
+
}
|
|
7945
|
+
}
|
|
7946
|
+
if (!id.includes("/") || looksLocal(id) || !HUB_ID.test(id)) continue;
|
|
7947
|
+
hits.push({ rule: "pin/hf-unpinned", path, line: lineOf(ll.line), api: `${L.api} ${flag}`, repo: id, repoType: "model", syntax: "shell", adapter: true, trustRemoteCode: false, ...served ? { servedBase: served } : {} });
|
|
7948
|
+
}
|
|
7949
|
+
}
|
|
7950
|
+
}
|
|
7627
7951
|
if (!L || !L.model) continue;
|
|
7628
7952
|
const rev = flagValue(L.rest, ["--revision"]);
|
|
7629
|
-
|
|
7953
|
+
const pinned = rev.present && rev.value !== void 0 && isPinnedRevision(rev.value);
|
|
7954
|
+
if (rev.present && (rev.value === void 0 || rev.value.startsWith("$") || pinned && !KEEP_PINNED)) continue;
|
|
7630
7955
|
const line = lineOf(ll.line);
|
|
7631
7956
|
const revision = rev.present ? rev.value : void 0;
|
|
7632
7957
|
if (L.model.startsWith("$") || /[{}]/.test(L.model)) {
|
|
7958
|
+
if (pinned) continue;
|
|
7633
7959
|
hits.push({ rule: revision ? "pin/hf-floating-revision" : "pin/hf-unpinned-dynamic", path, line, api: L.api, repoType: L.repoType, revision, syntax: "shell" });
|
|
7634
7960
|
continue;
|
|
7635
7961
|
}
|
|
7636
7962
|
if (looksLocal(L.model) || !HUB_ID.test(L.model)) continue;
|
|
7637
|
-
hits.push({ rule: revision ? "pin/hf-floating-revision" : "pin/hf-unpinned", path, line, api: L.api, repo: L.model, repoType: L.repoType, revision, syntax: "shell" });
|
|
7963
|
+
hits.push({ rule: revision ? "pin/hf-floating-revision" : "pin/hf-unpinned", path, line, api: L.api, repo: L.model, repoType: L.repoType, revision, syntax: "shell", ...pinned ? { pinned } : {}, ...KEEP_PINNED && flagValue(L.rest, ["--code-revision"]).present ? { codeRevision: true } : {} });
|
|
7638
7964
|
}
|
|
7639
7965
|
}
|
|
7640
7966
|
return hits;
|
|
@@ -7642,7 +7968,7 @@ function scanShell(src, path, lineOf = (l) => l) {
|
|
|
7642
7968
|
var YAML_MODEL_KEYS = ["base_model", "model_name_or_path", "model_name", "model_id", "pretrained_model_name_or_path", "model"];
|
|
7643
7969
|
var API_PREFIXES = /* @__PURE__ */ new Set(["openai", "anthropic", "azure", "azure_ai", "bedrock", "vertex_ai", "gemini", "groq", "together_ai", "ollama", "ollama_chat", "openrouter", "mistral", "cohere", "deepseek", "fireworks_ai", "replicate", "perplexity", "xai", "huggingface", "sagemaker", "watsonx", "cloudflare", "voyage", "hosted_vllm", "text-completion-openai", "databricks", "nvidia_nim", "cerebras", "sambanova", "lm_studio"]);
|
|
7644
7970
|
var YAML_LINE = /^(\s*)(-\s+)?([A-Za-z_][\w.-]*)\s*:\s*(.*?)\s*$/;
|
|
7645
|
-
var unquote = (v) => v.replace(/\s+#.*$/, "").replace(/^(["'])(.*)\1$/, "$2");
|
|
7971
|
+
var unquote = (v) => v.replace(/\s+#.*$/, "").replace(/^&[\w-]+\s+/, "").replace(/^(["'])(.*)\1$/, "$2");
|
|
7646
7972
|
function scanYaml(src, path) {
|
|
7647
7973
|
if (/^\s*litellm_params\s*:/m.test(src)) return scanShell(src, path);
|
|
7648
7974
|
const lines = src.split(/\r?\n/);
|
|
@@ -7683,13 +8009,147 @@ function scanYaml(src, path) {
|
|
|
7683
8009
|
let revision;
|
|
7684
8010
|
if (rev) {
|
|
7685
8011
|
const v = unquote(rev.value);
|
|
7686
|
-
if (!v || /[${}]/.test(v) || isPinnedRevision(v)) continue;
|
|
8012
|
+
if (!v || /[${}]/.test(v) || isPinnedRevision(v) && !KEEP_PINNED) continue;
|
|
7687
8013
|
revision = v;
|
|
7688
8014
|
}
|
|
7689
|
-
|
|
8015
|
+
const pinned = revision !== void 0 && isPinnedRevision(revision);
|
|
8016
|
+
hits.push({ rule: revision ? "pin/hf-floating-revision" : "pin/hf-unpinned", path, line: i + 1, api: `${p.key}:`, repo: value, repoType: "model", revision, syntax: "yaml", ...pinned ? { pinned } : {} });
|
|
7690
8017
|
}
|
|
7691
8018
|
return [...hits, ...scanShell(src, path)];
|
|
7692
8019
|
}
|
|
8020
|
+
var MANIFEST_MODEL_KEYS = { model_source: "ray-serve", modelURL: "vllm-stack", hfModelId: "manifest", hf_model_id: "manifest", modelID: "manifest", modelId: "manifest" };
|
|
8021
|
+
var HF_URI = /hf:\/\/([A-Za-z0-9][\w.-]*\/[A-Za-z0-9][\w.-]*)(?:[:@]([\w.-]+))?/g;
|
|
8022
|
+
var MODEL_FLAG = /--(model[_-]id|model[_-]path|model[_-]name[_-]or[_-]path|model)(?:=|\s+|["']\s*,\s*["'])["']?([A-Za-z0-9][\w.-]*\/[A-Za-z0-9][\w.-]*)(?=["'\s,\]]|$)/g;
|
|
8023
|
+
var REVISION_FLAG = /--(?:model[_-])?revision(?:=|\s+|["']\s*,\s*["'])["']?([\w.-]+)/;
|
|
8024
|
+
var TRUST_FLAG = /--trust[_-]remote[_-]code\b(?!\s*=\s*["']?false)/i;
|
|
8025
|
+
function scanManifestModels(src, path) {
|
|
8026
|
+
const lines = src.split(/\r?\n/);
|
|
8027
|
+
const hits = [];
|
|
8028
|
+
const bare = (l) => l.replace(/\s+#.*$/, "");
|
|
8029
|
+
const templated = (s) => /\{\{|\$\{|\$\(/.test(s);
|
|
8030
|
+
const indent = (l) => l.search(/\S/);
|
|
8031
|
+
const blockAround = (i) => {
|
|
8032
|
+
const col = indent(lines[i]);
|
|
8033
|
+
let a = i;
|
|
8034
|
+
while (a > 0 && (lines[a - 1].trim() === "" || indent(lines[a - 1]) >= col || /^\s*#/.test(lines[a - 1]))) a--;
|
|
8035
|
+
a = Math.max(0, a - 2);
|
|
8036
|
+
let b = i;
|
|
8037
|
+
while (b + 1 < lines.length && (lines[b + 1].trim() === "" || indent(lines[b + 1]) >= col || /^\s*#/.test(lines[b + 1]))) b++;
|
|
8038
|
+
return lines.slice(a, b + 1).filter((l) => !/^\s*#/.test(l)).map(bare).join("\n");
|
|
8039
|
+
};
|
|
8040
|
+
const underDataset = (i) => {
|
|
8041
|
+
let col = indent(lines[i]);
|
|
8042
|
+
for (let j = i - 1; j >= 0 && col > 0; j--) {
|
|
8043
|
+
const l = lines[j];
|
|
8044
|
+
if (!l.trim() || /^\s*#/.test(l)) continue;
|
|
8045
|
+
const c = indent(l);
|
|
8046
|
+
if (c < col) {
|
|
8047
|
+
if (/^\s*-?\s*datasets?\s*:/.test(l)) return true;
|
|
8048
|
+
col = c;
|
|
8049
|
+
}
|
|
8050
|
+
}
|
|
8051
|
+
return false;
|
|
8052
|
+
};
|
|
8053
|
+
const push = (i, api, repo, rev, hint, extra = {}) => {
|
|
8054
|
+
if (looksLocal(repo) || !HUB_ID.test(repo)) return;
|
|
8055
|
+
const pinned = rev !== void 0 && isPinnedRevision(rev);
|
|
8056
|
+
hits.push({ rule: rev ? "pin/hf-floating-revision" : "pin/hf-unpinned", path, line: i + 1, api, repo, repoType: "model", revision: rev, syntax: "yaml", pinHint: hint, ...pinned ? { pinned } : {}, ...extra });
|
|
8057
|
+
};
|
|
8058
|
+
for (let i = 0; i < lines.length; i++) {
|
|
8059
|
+
if (/^\s*#/.test(lines[i]) || /#\s*nosec\b/.test(lines[i])) continue;
|
|
8060
|
+
const line = bare(lines[i]);
|
|
8061
|
+
if (templated(line)) continue;
|
|
8062
|
+
const key = YAML_LINE.exec(line);
|
|
8063
|
+
for (const m of line.matchAll(HF_URI)) {
|
|
8064
|
+
const k = key?.[3];
|
|
8065
|
+
const hint2 = k === "storageUri" ? "kserve-uri" : "uri";
|
|
8066
|
+
push(i, `${k ?? "uri"}: hf://`, m[1], m[2], hint2, underDataset(i) ? { repoType: "dataset" } : {});
|
|
8067
|
+
}
|
|
8068
|
+
for (const m of line.matchAll(MODEL_FLAG)) {
|
|
8069
|
+
const block = blockAround(i);
|
|
8070
|
+
const rev = REVISION_FLAG.exec(block)?.[1];
|
|
8071
|
+
const kserve = /model[_-]id/.test(m[1]) && /--model_name\b|modelFormat|huggingface/i.test(`${block}
|
|
8072
|
+
${src.slice(0, 4e3)}`);
|
|
8073
|
+
push(i, `--${m[1]}`, m[2], rev && !templated(rev) ? rev : void 0, kserve ? "kserve-arg" : "engine-arg", { trustRemoteCode: TRUST_FLAG.test(block) });
|
|
8074
|
+
}
|
|
8075
|
+
const hint = key && MANIFEST_MODEL_KEYS[key[3]];
|
|
8076
|
+
if (hint) {
|
|
8077
|
+
const value = unquote(key[4]);
|
|
8078
|
+
if (value.includes("/") && !value.includes("://")) push(i, `${key[3]}:`, value, void 0, hint);
|
|
8079
|
+
}
|
|
8080
|
+
}
|
|
8081
|
+
return hits;
|
|
8082
|
+
}
|
|
8083
|
+
function manifestPinFix(hint, id, sha) {
|
|
8084
|
+
switch (hint) {
|
|
8085
|
+
case "kserve-uri":
|
|
8086
|
+
return `storageUri: hf://${id}:${sha} (KServe reads hf://owner/model[:revision])`;
|
|
8087
|
+
case "uri":
|
|
8088
|
+
return `hf://${id}:${sha} where the chart passes the address to KServe's storage initializer; otherwise download that commit to a volume (hf download ${id} --revision ${sha}) and point the chart at the volume`;
|
|
8089
|
+
case "kserve-arg":
|
|
8090
|
+
return `- --model_revision=${sha} next to --model_id (the KServe Hugging Face runtime's flag)`;
|
|
8091
|
+
case "engine-arg":
|
|
8092
|
+
return `--revision ${sha} in the same argument list`;
|
|
8093
|
+
case "ray-serve":
|
|
8094
|
+
return `revision: ${sha} under engine_kwargs of this llm_config (Ray Serve passes engine_kwargs to vLLM)`;
|
|
8095
|
+
case "vllm-stack":
|
|
8096
|
+
return `"--revision", "${sha}" in this model's vllmConfig.extraArgs`;
|
|
8097
|
+
case "manifest":
|
|
8098
|
+
return `state commit ${sha} where this format takes a revision; if it takes none, download that commit to a volume (hf download ${id} --revision ${sha}) and serve from the volume`;
|
|
8099
|
+
}
|
|
8100
|
+
}
|
|
8101
|
+
var MODEL_ENV = /^(HF_|HUGGING_FACE_HUB_|VLLM_|TGI_|TEI_)?MODEL(_ID|_NAME|_REPO|_NAME_OR_PATH)?$/;
|
|
8102
|
+
var REVISION_ENV = /^(HF_|VLLM_|TGI_|TEI_)?(MODEL_)?REVISION$/;
|
|
8103
|
+
var CODE_REVISION_ENV = /CODE_REVISION$/;
|
|
8104
|
+
function envPairs(src) {
|
|
8105
|
+
const out = [];
|
|
8106
|
+
const lines = src.split(/\r?\n/);
|
|
8107
|
+
const q = (v) => unquote(v.trim());
|
|
8108
|
+
for (let i = 0; i < lines.length; i++) {
|
|
8109
|
+
const l = lines[i];
|
|
8110
|
+
if (/^\s*#/.test(l) || /#\s*nosec\b/.test(l)) continue;
|
|
8111
|
+
let m = /^\s*-\s+name\s*:\s*["']?([A-Z][A-Z0-9_]*)["']?\s*$/.exec(l);
|
|
8112
|
+
if (m) {
|
|
8113
|
+
const nx = /^\s*value\s*:\s*(.+?)\s*$/.exec(lines[i + 1] ?? "");
|
|
8114
|
+
if (nx) out.push({ key: m[1], value: q(nx[1]), line: i + 1 });
|
|
8115
|
+
continue;
|
|
8116
|
+
}
|
|
8117
|
+
if (m = /^\s*(?:-\s+)?["']?([A-Z][A-Z0-9_]*)=([^\s"']+)["']?\s*$/.exec(l)) {
|
|
8118
|
+
out.push({ key: m[1], value: q(m[2]), line: i + 1 });
|
|
8119
|
+
continue;
|
|
8120
|
+
}
|
|
8121
|
+
if (m = /^\s*([A-Z][A-Z0-9_]*)\s*:\s*(\S.*?)\s*$/.exec(l)) {
|
|
8122
|
+
out.push({ key: m[1], value: q(m[2]), line: i + 1 });
|
|
8123
|
+
continue;
|
|
8124
|
+
}
|
|
8125
|
+
if (m = /^\s*(?:ENV|export)\s+(.+)$/.exec(l)) {
|
|
8126
|
+
const body = m[1].replace(/\s*\\\s*$/, "");
|
|
8127
|
+
const kv = [...body.matchAll(/([A-Z][A-Z0-9_]*)=("[^"]*"|'[^']*'|\S+)/g)];
|
|
8128
|
+
if (kv.length) for (const x of kv) out.push({ key: x[1], value: q(x[2]), line: i + 1 });
|
|
8129
|
+
else {
|
|
8130
|
+
const sp = /^([A-Z][A-Z0-9_]*)\s+(\S+)\s*$/.exec(body);
|
|
8131
|
+
if (sp) out.push({ key: sp[1], value: q(sp[2]), line: i + 1 });
|
|
8132
|
+
}
|
|
8133
|
+
}
|
|
8134
|
+
}
|
|
8135
|
+
return out;
|
|
8136
|
+
}
|
|
8137
|
+
function scanEnvModels(src, path, syntax) {
|
|
8138
|
+
const pairs2 = envPairs(src);
|
|
8139
|
+
const rev = pairs2.find((p) => REVISION_ENV.test(p.key) && !CODE_REVISION_ENV.test(p.key));
|
|
8140
|
+
const codeRevision = pairs2.some((p) => CODE_REVISION_ENV.test(p.key));
|
|
8141
|
+
const trustRemoteCode = pairs2.some((p) => /TRUST_REMOTE_CODE$/.test(p.key) && /^(1|true|yes)$/i.test(p.value));
|
|
8142
|
+
const hits = [];
|
|
8143
|
+
for (const p of pairs2) {
|
|
8144
|
+
if (!MODEL_ENV.test(p.key)) continue;
|
|
8145
|
+
const v = p.value;
|
|
8146
|
+
if (!v.includes("/") || /[${}]/.test(v) || looksLocal(v) || !HUB_ID.test(v) || API_PREFIXES.has(v.split("/")[0].toLowerCase())) continue;
|
|
8147
|
+
const revision = rev && !/[${}]/.test(rev.value) ? rev.value : void 0;
|
|
8148
|
+
const pinned = revision !== void 0 && isPinnedRevision(revision);
|
|
8149
|
+
hits.push({ rule: revision ? "pin/hf-floating-revision" : "pin/hf-unpinned", path, line: p.line, api: `env ${p.key}`, repo: v, repoType: "model", revision, syntax, via: "env", trustRemoteCode, ...pinned ? { pinned } : {}, ...codeRevision ? { codeRevision } : {} });
|
|
8150
|
+
}
|
|
8151
|
+
return hits;
|
|
8152
|
+
}
|
|
7693
8153
|
function scanNotebook(raw, path) {
|
|
7694
8154
|
let nb;
|
|
7695
8155
|
try {
|
|
@@ -7745,8 +8205,27 @@ function scanPins(path, text) {
|
|
|
7745
8205
|
return [];
|
|
7746
8206
|
}
|
|
7747
8207
|
}
|
|
8208
|
+
function scanModelRefs(path, text) {
|
|
8209
|
+
KEEP_PINNED = true;
|
|
8210
|
+
try {
|
|
8211
|
+
if (refFileKind(path) === "adapter") return scanAdapterConfig(text, path);
|
|
8212
|
+
const kind = pinFileKind(path);
|
|
8213
|
+
const env = kind === "yaml" || kind === "shell" ? scanEnvModels(text, path, kind) : [];
|
|
8214
|
+
const manifest = kind === "yaml" ? scanManifestModels(text, path) : [];
|
|
8215
|
+
const hits = [...scanPins(path, text).filter((h) => h.repo), ...env, ...manifest];
|
|
8216
|
+
const seen = /* @__PURE__ */ new Set();
|
|
8217
|
+
return hits.filter((h) => {
|
|
8218
|
+
const k = `${h.line}|${h.repo}|${h.revision ?? ""}`;
|
|
8219
|
+
if (seen.has(k)) return false;
|
|
8220
|
+
seen.add(k);
|
|
8221
|
+
return true;
|
|
8222
|
+
});
|
|
8223
|
+
} finally {
|
|
8224
|
+
KEEP_PINNED = false;
|
|
8225
|
+
}
|
|
8226
|
+
}
|
|
7748
8227
|
function pinSpelling(syntax, sha) {
|
|
7749
|
-
return syntax === "python" ? `revision="${sha}"` : syntax === "shell" ? `--revision ${sha}` : `model_revision: ${sha}`;
|
|
8228
|
+
return syntax === "python" ? `revision="${sha}"` : syntax === "shell" ? `--revision ${sha}` : syntax === "json" ? `"revision": "${sha}"` : `model_revision: ${sha}`;
|
|
7750
8229
|
}
|
|
7751
8230
|
function fromPinCheck(hits, opts = {}) {
|
|
7752
8231
|
return hits.map((h) => {
|
|
@@ -7873,6 +8352,503 @@ Severity in this repo is set by \`.neurarch.yml\` (\`rules: { ${id}: off | info
|
|
|
7873
8352
|
};
|
|
7874
8353
|
}
|
|
7875
8354
|
|
|
8355
|
+
// src/utils/policy/adapterCheck.ts
|
|
8356
|
+
var LORA_SUFFIX = /\.(lora_A|lora_B|lora_embedding_A|lora_embedding_B|lora_magnitude_vector)(\.[\w-]+)?(\.weight)?$/;
|
|
8357
|
+
var GENERIC = /* @__PURE__ */ new Set(["model", "base_model"]);
|
|
8358
|
+
function loraModulePaths(tensorNames) {
|
|
8359
|
+
const out = /* @__PURE__ */ new Set();
|
|
8360
|
+
for (const n of tensorNames) {
|
|
8361
|
+
const m = LORA_SUFFIX.exec(n);
|
|
8362
|
+
if (!m) continue;
|
|
8363
|
+
out.add(n.slice(0, m.index).replace(/^base_model\.model\./, ""));
|
|
8364
|
+
}
|
|
8365
|
+
return [...out].sort();
|
|
8366
|
+
}
|
|
8367
|
+
var inc = (o, k) => {
|
|
8368
|
+
o[k] = (o[k] ?? 0) + 1;
|
|
8369
|
+
};
|
|
8370
|
+
var top = (o) => Object.entries(o).sort((a, b) => b[1] - a[1])[0]?.[0];
|
|
8371
|
+
var sum = (o) => Object.values(o).reduce((a, b) => a + b, 0);
|
|
8372
|
+
function adapterLayout(adapterTensors, baseTensors) {
|
|
8373
|
+
const paths = loraModulePaths(adapterTensors);
|
|
8374
|
+
const mods = /* @__PURE__ */ new Set();
|
|
8375
|
+
for (const n2 of baseTensors) mods.add(n2.replace(/\.(weight|bias)$/, ""));
|
|
8376
|
+
if (!paths.length || !mods.size) return null;
|
|
8377
|
+
const tails = /* @__PURE__ */ new Map();
|
|
8378
|
+
for (const m of mods) {
|
|
8379
|
+
const parts = m.split(".");
|
|
8380
|
+
for (let i = 0; i < parts.length; i++) {
|
|
8381
|
+
const t = parts.slice(i).join(".");
|
|
8382
|
+
if (!tails.has(t)) tails.set(t, m);
|
|
8383
|
+
}
|
|
8384
|
+
}
|
|
8385
|
+
const r = { modules: paths.length, exact: 0, sameLayout: 0, missingWrapper: {}, extraWrapper: {}, noMatch: 0, tiedHead: 0, verdict: "mixed" };
|
|
8386
|
+
const storesHead = [...mods].some((m) => m === "lm_head" || m.endsWith(".lm_head"));
|
|
8387
|
+
for (const p of paths) {
|
|
8388
|
+
if (mods.has(p)) {
|
|
8389
|
+
r.exact++;
|
|
8390
|
+
continue;
|
|
8391
|
+
}
|
|
8392
|
+
if (!storesHead && (p === "lm_head" || p.endsWith(".lm_head"))) {
|
|
8393
|
+
r.tiedHead++;
|
|
8394
|
+
continue;
|
|
8395
|
+
}
|
|
8396
|
+
const parts = p.split(".");
|
|
8397
|
+
let at = -1;
|
|
8398
|
+
let base = "";
|
|
8399
|
+
for (let i = 0; i < parts.length && parts.length - i >= 3; i++) {
|
|
8400
|
+
const hit = tails.get(parts.slice(i).join("."));
|
|
8401
|
+
if (hit) {
|
|
8402
|
+
at = i;
|
|
8403
|
+
base = hit;
|
|
8404
|
+
break;
|
|
8405
|
+
}
|
|
8406
|
+
}
|
|
8407
|
+
if (at < 0) {
|
|
8408
|
+
r.noMatch++;
|
|
8409
|
+
continue;
|
|
8410
|
+
}
|
|
8411
|
+
const bparts = base.split(".");
|
|
8412
|
+
const pa = parts.slice(0, at).filter((s) => !GENERIC.has(s));
|
|
8413
|
+
const pb = bparts.slice(0, bparts.length - (parts.length - at)).filter((s) => !GENERIC.has(s));
|
|
8414
|
+
const sa = new Set(pa);
|
|
8415
|
+
const sb = new Set(pb);
|
|
8416
|
+
if ([...pa].sort().join(".") === [...pb].sort().join(".")) r.sameLayout++;
|
|
8417
|
+
else if (pa.every((s) => sb.has(s))) inc(r.missingWrapper, [...sb].filter((s) => !sa.has(s)).sort().join("."));
|
|
8418
|
+
else if (pb.every((s) => sa.has(s))) inc(r.extraWrapper, [...sa].filter((s) => !sb.has(s)).sort().join("."));
|
|
8419
|
+
else r.noMatch++;
|
|
8420
|
+
}
|
|
8421
|
+
const missing = sum(r.missingWrapper);
|
|
8422
|
+
const extra = sum(r.extraWrapper);
|
|
8423
|
+
const n = r.modules - r.tiedHead;
|
|
8424
|
+
if (r.exact + r.sameLayout === n) r.verdict = "match";
|
|
8425
|
+
else if (r.noMatch === n) r.verdict = "no-match";
|
|
8426
|
+
else if (missing >= n * 0.9) {
|
|
8427
|
+
r.verdict = "missing-wrapper";
|
|
8428
|
+
r.wrapper = top(r.missingWrapper);
|
|
8429
|
+
} else if (extra >= n * 0.9) {
|
|
8430
|
+
r.verdict = "extra-wrapper";
|
|
8431
|
+
r.wrapper = top(r.extraWrapper);
|
|
8432
|
+
}
|
|
8433
|
+
return r;
|
|
8434
|
+
}
|
|
8435
|
+
function versionBefore(version, than) {
|
|
8436
|
+
const m = version ? /^v?(\d+)\.(\d+)(?:\.(\d+))?/.exec(version) : null;
|
|
8437
|
+
if (!m) return void 0;
|
|
8438
|
+
const v = [Number(m[1]), Number(m[2]), Number(m[3] ?? 0)];
|
|
8439
|
+
for (let i = 0; i < 3; i++) if (v[i] !== than[i]) return v[i] < than[i];
|
|
8440
|
+
return false;
|
|
8441
|
+
}
|
|
8442
|
+
var VLLM_WRAPPER_FIX = [0, 33, 0];
|
|
8443
|
+
function assessAdapter(a) {
|
|
8444
|
+
const out = [];
|
|
8445
|
+
const l = a.layout;
|
|
8446
|
+
if (l?.verdict === "missing-wrapper" && l.wrapper === "language_model") {
|
|
8447
|
+
const before = a.engine?.name === "vllm" ? versionBefore(a.engine.version, VLLM_WRAPPER_FIX) : void 0;
|
|
8448
|
+
const where2 = a.engine?.name === "vllm" && a.engine.version ? `vLLM ${a.engine.version}` : "vLLM";
|
|
8449
|
+
const what = `${l.modules} of this adapter's modules are named without the language_model level that ${a.base} keeps them under (usually because it was trained through a text-only class).`;
|
|
8450
|
+
if (before === true) out.push({ lane: "behavior", severity: "high", kind: "adapter-noop-wrapper", message: `${what} ${where2} loads it without an error and applies none of it: the output is the base model's. Fixed in vLLM 0.33.0.`, fix: "Serve on vLLM 0.33.0 or later, or merge the adapter into the base before serving.", url: "https://github.com/vllm-project/vllm/issues/34186" });
|
|
8451
|
+
else if (before === false) out.push({ lane: "behavior", severity: "low", kind: "adapter-wrapper-layout", message: `${what} ${where2} applies it (fixed in 0.33.0); earlier versions loaded it and applied none of it.`, url: "https://github.com/vllm-project/vllm/issues/34186" });
|
|
8452
|
+
else out.push({ lane: "behavior", severity: "medium", kind: "adapter-noop-wrapper", message: `${what} vLLM 0.32.0 and earlier load such an adapter without an error and apply none of it; 0.33.0 and later apply it. The engine version is not in this file.`, fix: "Check the vLLM version this is served on, and compare one output with and without the adapter before go-live.", url: "https://github.com/vllm-project/vllm/issues/34186" });
|
|
8453
|
+
} else if (l?.verdict === "missing-wrapper") {
|
|
8454
|
+
out.push({ lane: "behavior", severity: "low", kind: "adapter-wrapper-layout", message: `${l.modules} of this adapter's modules are named without the ${l.wrapper} level that ${a.base} keeps them under. PEFT resolves that through the class it was trained with; a serving engine that matches full paths may apply none of it.`, fix: "Compare one output with and without the adapter on the engine you serve with." });
|
|
8455
|
+
} else if (l?.verdict === "no-match") {
|
|
8456
|
+
out.push({ lane: "behavior", severity: "high", kind: "adapter-no-match", message: `None of this adapter's ${l.modules} target modules exists in ${a.base}. It was trained for a different model, or the base named here is the wrong one.` });
|
|
8457
|
+
} else if (l && l.noMatch > 0 && l.verdict !== "match") {
|
|
8458
|
+
out.push({ lane: "behavior", severity: "medium", kind: "adapter-partial-match", message: `${l.noMatch} of this adapter's ${l.modules} target modules ${l.noMatch === 1 ? "does" : "do"} not exist in ${a.base}.` });
|
|
8459
|
+
}
|
|
8460
|
+
if (a.recordedBase && a.recordedBase.toLowerCase() !== a.base.toLowerCase()) {
|
|
8461
|
+
out.push({ lane: "behavior", severity: "medium", kind: "adapter-base-differs", message: `adapter_config.json says this adapter was trained on ${a.recordedBase}; this file serves it on ${a.base}.`, fix: "Confirm the two are the same weights (a quantized or renamed copy is fine; a different fine-tune is not)." });
|
|
8462
|
+
}
|
|
8463
|
+
if (a.baseCommitRecorded === false) {
|
|
8464
|
+
out.push({ lane: "hygiene", severity: "low", kind: "adapter-base-unpinned", message: `The adapter's config names its base (${a.recordedBase ?? a.base}) without a commit, so nothing records which revision it was trained against.`, fix: 'Add "revision": "<base commit>" to adapter_config.json when you export the adapter.' });
|
|
8465
|
+
}
|
|
8466
|
+
return out;
|
|
8467
|
+
}
|
|
8468
|
+
|
|
8469
|
+
// src/utils/policy/gate.ts
|
|
8470
|
+
var quote = (w) => /[\s"'$`\\]/.test(w) || w === "" ? `'${w.replace(/'/g, `'\\''`)}'` : w;
|
|
8471
|
+
function launchesIn(commands) {
|
|
8472
|
+
const out = [];
|
|
8473
|
+
const seen = /* @__PURE__ */ new Set();
|
|
8474
|
+
for (const words of commands) {
|
|
8475
|
+
let start = -1;
|
|
8476
|
+
let engine = "vllm";
|
|
8477
|
+
for (let i = 0; i < words.length - 1; i++) {
|
|
8478
|
+
const w = words[i];
|
|
8479
|
+
const nx = words[i + 1];
|
|
8480
|
+
if ((w === "vllm" || w.endsWith("/vllm")) && nx === "serve") {
|
|
8481
|
+
start = i;
|
|
8482
|
+
engine = "vllm";
|
|
8483
|
+
break;
|
|
8484
|
+
}
|
|
8485
|
+
if ((w === "sglang" || w.endsWith("/sglang")) && nx === "serve") {
|
|
8486
|
+
start = i;
|
|
8487
|
+
engine = "sglang";
|
|
8488
|
+
break;
|
|
8489
|
+
}
|
|
8490
|
+
if (w === "-m" && /^vllm\.entrypoints\.(openai\.)?api_server$/.test(nx)) {
|
|
8491
|
+
start = Math.max(0, i - 1);
|
|
8492
|
+
engine = "vllm";
|
|
8493
|
+
break;
|
|
8494
|
+
}
|
|
8495
|
+
if (w === "-m" && nx === "sglang.launch_server") {
|
|
8496
|
+
start = Math.max(0, i - 1);
|
|
8497
|
+
engine = "sglang";
|
|
8498
|
+
break;
|
|
8499
|
+
}
|
|
8500
|
+
}
|
|
8501
|
+
if (start < 0) continue;
|
|
8502
|
+
const rest = words.slice(start);
|
|
8503
|
+
if (rest.some((w) => /\$\{?[A-Za-z_]|\{\{/.test(w))) continue;
|
|
8504
|
+
const flag = (names) => {
|
|
8505
|
+
for (let i = 0; i < rest.length; i++) {
|
|
8506
|
+
const eq = /^(--[\w-]+)=(.*)$/.exec(rest[i]);
|
|
8507
|
+
if (eq && names.includes(eq[1])) return eq[2];
|
|
8508
|
+
if (names.includes(rest[i])) return rest[i + 1];
|
|
8509
|
+
}
|
|
8510
|
+
return void 0;
|
|
8511
|
+
};
|
|
8512
|
+
const serveAt = rest.indexOf("serve");
|
|
8513
|
+
const positional = serveAt >= 0 && rest[serveAt + 1] && !rest[serveAt + 1].startsWith("-") ? rest[serveAt + 1] : void 0;
|
|
8514
|
+
const model = positional ?? flag(["--model", "--model-path"]);
|
|
8515
|
+
const command = rest.map(quote).join(" ");
|
|
8516
|
+
if (seen.has(command)) continue;
|
|
8517
|
+
seen.add(command);
|
|
8518
|
+
out.push({ command, engine, ...model && /^[\w.-]+\/[\w.-]+$/.test(model) ? { modelId: model } : {} });
|
|
8519
|
+
}
|
|
8520
|
+
return out;
|
|
8521
|
+
}
|
|
8522
|
+
function acceleratorsIn(text) {
|
|
8523
|
+
const sky = /^\s*accelerators\s*:\s*\{?\s*["']?([A-Za-z][\w-]*)["']?\s*:\s*(\d+)/m.exec(text);
|
|
8524
|
+
if (sky) return { card: sky[1], count: Number(sky[2]) };
|
|
8525
|
+
const k8s = /nvidia\.com\/gpu["']?\s*:\s*["']?(\d+)/.exec(text);
|
|
8526
|
+
return k8s ? { count: Number(k8s[1]) } : {};
|
|
8527
|
+
}
|
|
8528
|
+
function gateVerdict(c, opts = {}) {
|
|
8529
|
+
const blocking = [];
|
|
8530
|
+
if (c.scan.high) blocking.push(`${c.scan.high} high scan finding${c.scan.high === 1 ? "" : "s"}`);
|
|
8531
|
+
if (c.serve.block) blocking.push(`${c.serve.block} launch blocker${c.serve.block === 1 ? "" : "s"}`);
|
|
8532
|
+
if (blocking.length) return { verdict: "refuse", exit: 1, because: blocking };
|
|
8533
|
+
const toRead = [];
|
|
8534
|
+
if (c.scan.medium) toRead.push(`${c.scan.medium} medium scan finding${c.scan.medium === 1 ? "" : "s"}`);
|
|
8535
|
+
if (c.serve.warn) toRead.push(`${c.serve.warn} launch warning${c.serve.warn === 1 ? "" : "s"}`);
|
|
8536
|
+
if (c.promptDiffers) toRead.push(`${c.promptDiffers} prompt${c.promptDiffers === 1 ? "" : "s"} rendered differently from the reference`);
|
|
8537
|
+
if (c.unread) toRead.push(`${c.unread} check${c.unread === 1 ? "" : "s"} could not be read`);
|
|
8538
|
+
if (toRead.length) return { verdict: "review", exit: opts.strict ? 1 : 0, because: toRead };
|
|
8539
|
+
return { verdict: "admit", exit: 0, because: [] };
|
|
8540
|
+
}
|
|
8541
|
+
var GATE_RECORD_SCHEMA = "https://www.neurarch.com/schema/gate-record-v1.json";
|
|
8542
|
+
function buildGateRecord(input) {
|
|
8543
|
+
const { version, strict, ...rest } = input;
|
|
8544
|
+
const v = gateVerdict(rest.counts, { strict });
|
|
8545
|
+
return { $schema: GATE_RECORD_SCHEMA, tool: { name: "neurarch", version }, ...v, ...rest };
|
|
8546
|
+
}
|
|
8547
|
+
function gateSubjectFromEnv(env) {
|
|
8548
|
+
if (env.GITHUB_ACTIONS === "true" || env.GITHUB_SHA) {
|
|
8549
|
+
const repo = env.GITHUB_REPOSITORY ?? null;
|
|
8550
|
+
return {
|
|
8551
|
+
repo,
|
|
8552
|
+
commit: env.GITHUB_SHA ?? null,
|
|
8553
|
+
ref: env.GITHUB_HEAD_REF || env.GITHUB_REF_NAME || null,
|
|
8554
|
+
by: env.GITHUB_ACTOR ?? null,
|
|
8555
|
+
runUrl: repo && env.GITHUB_RUN_ID ? `${env.GITHUB_SERVER_URL ?? "https://github.com"}/${repo}/actions/runs/${env.GITHUB_RUN_ID}` : null
|
|
8556
|
+
};
|
|
8557
|
+
}
|
|
8558
|
+
if (env.GITLAB_CI === "true") {
|
|
8559
|
+
return { repo: env.CI_PROJECT_PATH ?? null, commit: env.CI_COMMIT_SHA ?? null, ref: env.CI_COMMIT_REF_NAME ?? null, by: env.GITLAB_USER_LOGIN ?? null, runUrl: env.CI_JOB_URL ?? null };
|
|
8560
|
+
}
|
|
8561
|
+
return {};
|
|
8562
|
+
}
|
|
8563
|
+
function gateLedgerRow(rec, subject = {}) {
|
|
8564
|
+
return {
|
|
8565
|
+
kind: "gate",
|
|
8566
|
+
at: rec.at,
|
|
8567
|
+
ran_at: rec.at,
|
|
8568
|
+
tool: rec.tool,
|
|
8569
|
+
subject: { repo: subject.repo ?? null, commit: subject.commit ?? null, ref: subject.ref ?? null, by: subject.by ?? null, run_url: subject.runUrl ?? null },
|
|
8570
|
+
verdict: rec.verdict,
|
|
8571
|
+
exit: rec.exit,
|
|
8572
|
+
because: rec.because,
|
|
8573
|
+
counts: { scan: rec.counts.scan, serve: rec.counts.serve, prompt_differs: rec.counts.promptDiffers, unread: rec.counts.unread },
|
|
8574
|
+
models: rec.models.map((m) => ({ id: m.id, pinned: m.pinned, resolved_to: m.resolvedTo, adapter_of: m.adapterOf ?? null })),
|
|
8575
|
+
launches: rec.launches.map((l) => ({
|
|
8576
|
+
file: l.file,
|
|
8577
|
+
model: l.model ?? null,
|
|
8578
|
+
engine: l.engine,
|
|
8579
|
+
engine_version: l.engineVersion,
|
|
8580
|
+
engine_version_assumed: !!l.engineVersionAssumed,
|
|
8581
|
+
card: l.card,
|
|
8582
|
+
gpus: l.gpus,
|
|
8583
|
+
rules: l.findings.map((f) => f.rule)
|
|
8584
|
+
})),
|
|
8585
|
+
prompts: rec.prompts.map((p) => ({ id: p.id, engine: p.engine, verdict: p.verdict, at: p.at ?? null, template_sha256: p.templateSha256 ?? null })),
|
|
8586
|
+
not_checked: rec.notChecked
|
|
8587
|
+
};
|
|
8588
|
+
}
|
|
8589
|
+
|
|
8590
|
+
// src/utils/policy/engineRecord.ts
|
|
8591
|
+
var FAMILIES = [
|
|
8592
|
+
["paligemma", /pali-?gemma/i],
|
|
8593
|
+
["gemma", /\bgemma|(?<![a-z])t5gemma|embeddinggemma/i],
|
|
8594
|
+
["qwen", /qwen|\bqwq\b/i],
|
|
8595
|
+
["llama", /llama(?!\.cpp|[-_ ]?cpp|index)/i],
|
|
8596
|
+
["deepseek", /deepseek/i],
|
|
8597
|
+
["glm", /\bglm\b|\bglm-?\d|chatglm|cogvlm|cogagent/i],
|
|
8598
|
+
["kimi", /\bkimi\b|moonshot/i],
|
|
8599
|
+
["mistral", /mistral|mixtral|ministral|devstral|magistral|voxtral|pixtral|codestral/i],
|
|
8600
|
+
["nemotron", /nemotron/i],
|
|
8601
|
+
["gpt-oss", /gpt-?oss/i],
|
|
8602
|
+
["phi", /\bphi-?\d|\bphi\b(?=[- ]?(\d|silica|mini|medium|vision))/i],
|
|
8603
|
+
["granite", /granite/i],
|
|
8604
|
+
["minicpm", /minicpm/i],
|
|
8605
|
+
["internvl", /internvl|internlm/i],
|
|
8606
|
+
["hermes", /hermes/i],
|
|
8607
|
+
["minimax", /minimax/i],
|
|
8608
|
+
["ernie", /ernie/i],
|
|
8609
|
+
["hunyuan", /hunyuan/i],
|
|
8610
|
+
["llava", /llava/i],
|
|
8611
|
+
["whisper", /whisper/i],
|
|
8612
|
+
["cohere", /\bcommand-?[ar]\b|\baya\b|cohere/i],
|
|
8613
|
+
["smol", /smol(lm|vlm)/i],
|
|
8614
|
+
["bge", /\bbge\b/i],
|
|
8615
|
+
["jina", /\bjina/i],
|
|
8616
|
+
["nomic", /nomic/i]
|
|
8617
|
+
];
|
|
8618
|
+
function familiesIn(text) {
|
|
8619
|
+
const out = [];
|
|
8620
|
+
let rest = text;
|
|
8621
|
+
for (const [name, re] of FAMILIES) {
|
|
8622
|
+
if (!re.test(rest)) continue;
|
|
8623
|
+
out.push(name);
|
|
8624
|
+
if (name === "paligemma") rest = rest.replace(/pali-?gemma/gi, " ");
|
|
8625
|
+
}
|
|
8626
|
+
return out;
|
|
8627
|
+
}
|
|
8628
|
+
function familyOf(modelId) {
|
|
8629
|
+
const [owner, name] = modelId.includes("/") ? modelId.split("/", 2) : ["", modelId];
|
|
8630
|
+
return familiesIn(name)[0] ?? familiesIn(owner)[0];
|
|
8631
|
+
}
|
|
8632
|
+
var KIND_RULES = [
|
|
8633
|
+
["adapter", /\blora\b|\bdora\b|\bpeft\b|\badapters?\b/i],
|
|
8634
|
+
["tool-calling", /tool[- _]?(call|pars|choice|use)|function[- ]call|\btool parser|reasoning[- _]pars|\bparser\b/i],
|
|
8635
|
+
["prompt", /chat[- _]?template|\btemplate\b|\brenderer\b|\btokeniz|special tokens?|\bbos\b|\beos\b|system prompt|prompt format/i],
|
|
8636
|
+
["quantization", /quanti[sz]|\bfp8\b|\bawq\b|\bgptq\b|\bgguf\b|bitsandbytes|\bint[48]\b|nvfp4|\bw4a16\b|\bw8a8\b|\bmxfp/i]
|
|
8637
|
+
];
|
|
8638
|
+
function classifyEngineChange(text, section) {
|
|
8639
|
+
if (/breaking|deprecat|before you upgrade/i.test(section)) return "breaking";
|
|
8640
|
+
if (/^security/i.test(section)) return "security";
|
|
8641
|
+
for (const [kind, re] of KIND_RULES) if (re.test(text)) return kind;
|
|
8642
|
+
for (const [kind, re] of KIND_RULES) if (re.test(section)) return kind;
|
|
8643
|
+
if (/model support|new models/i.test(section) && familiesIn(text).length) return "model";
|
|
8644
|
+
return null;
|
|
8645
|
+
}
|
|
8646
|
+
var MAX_TEXT = 240;
|
|
8647
|
+
var NUMBER_RANGE = new RegExp(`(\\d)\\s*[${String.fromCharCode(8211)}${String.fromCharCode(8212)}]\\s*(\\d)`, "g");
|
|
8648
|
+
var LONG_DASH = new RegExp(`\\s*[${String.fromCharCode(8211)}${String.fromCharCode(8212)}]\\s*`, "g");
|
|
8649
|
+
function plain(line) {
|
|
8650
|
+
const s = line.replace(/\[([^\]]+)\]\([^)]*\)/g, "$1").replace(/<[^>]+>/g, "").replace(/[*`]+/g, "").replace(NUMBER_RANGE, "$1 to $2").replace(LONG_DASH, ", ").replace(/\s+/g, " ").replace(/^[\s:,;.]+|[\s:,;]+$/g, "").trim();
|
|
8651
|
+
return s.length > MAX_TEXT ? `${s.slice(0, MAX_TEXT - 3).replace(/\s+\S*$/, "")}...` : s;
|
|
8652
|
+
}
|
|
8653
|
+
function releaseVersion(tag, name, body) {
|
|
8654
|
+
const heading = /^#\s+(?:vLLM\s+)?v?(\d+\.\d+\.\d+)\s*$/m.exec(body ?? "")?.[1];
|
|
8655
|
+
const titled = /v?(\d+\.\d+\.\d+)(?!\w)/.exec(name ?? "")?.[1];
|
|
8656
|
+
return heading ?? titled ?? /v?(\d+\.\d+\.\d+)/.exec(tag)?.[1];
|
|
8657
|
+
}
|
|
8658
|
+
var prsIn = (s) => [...new Set([...s.matchAll(/#(\d{3,6})\b/g)].map((m) => Number(m[1])))];
|
|
8659
|
+
function splitClauses(text) {
|
|
8660
|
+
const parts = [];
|
|
8661
|
+
let depth = 0;
|
|
8662
|
+
let cur = "";
|
|
8663
|
+
const refEnded = () => /\(#[^()]*\)$/.test(cur.trimEnd()) || /#\d{3,6}$/.test(cur.trimEnd());
|
|
8664
|
+
for (let i = 0; i < text.length; i++) {
|
|
8665
|
+
const ch = text[i];
|
|
8666
|
+
if (ch === "(") depth++;
|
|
8667
|
+
if (ch === ")") depth = Math.max(0, depth - 1);
|
|
8668
|
+
if (depth === 0 && (ch === ";" || ch === "," && refEnded())) {
|
|
8669
|
+
parts.push(cur);
|
|
8670
|
+
cur = "";
|
|
8671
|
+
continue;
|
|
8672
|
+
}
|
|
8673
|
+
cur += ch;
|
|
8674
|
+
if (depth === 0 && refEnded() && /^\s+and\s+/.test(text.slice(i + 1))) {
|
|
8675
|
+
parts.push(cur);
|
|
8676
|
+
cur = "";
|
|
8677
|
+
i += /^\s+and/.exec(text.slice(i + 1))[0].length;
|
|
8678
|
+
}
|
|
8679
|
+
}
|
|
8680
|
+
if (cur.trim()) parts.push(cur);
|
|
8681
|
+
const out = [];
|
|
8682
|
+
let carry2 = "";
|
|
8683
|
+
for (const p of parts) {
|
|
8684
|
+
const piece = `${carry2}${p}`;
|
|
8685
|
+
if (prsIn(p).length) {
|
|
8686
|
+
out.push(piece.trim());
|
|
8687
|
+
carry2 = "";
|
|
8688
|
+
} else carry2 = `${piece.trim()}; `;
|
|
8689
|
+
}
|
|
8690
|
+
if (carry2.trim()) {
|
|
8691
|
+
if (out.length) out[out.length - 1] += `; ${carry2.replace(/;\s*$/, "").trim()}`;
|
|
8692
|
+
else out.push(carry2.replace(/;\s*$/, "").trim());
|
|
8693
|
+
}
|
|
8694
|
+
return out.filter(Boolean);
|
|
8695
|
+
}
|
|
8696
|
+
var SKIP_SECTION = /^(release artifacts|python wheels|docker images|other artifacts|install|new contributors|contributors|dependencies|build|documentation|tl;dr|full changelog)\b/i;
|
|
8697
|
+
var SUMMARY_TOP = /^(highlights|tl;dr)\b/i;
|
|
8698
|
+
function parseEngineRelease(r) {
|
|
8699
|
+
const version = releaseVersion(r.tag, r.name, r.body);
|
|
8700
|
+
if (!version) return null;
|
|
8701
|
+
const drafts = [];
|
|
8702
|
+
const lines = (r.body ?? "").split(/\r?\n/);
|
|
8703
|
+
let top2 = "";
|
|
8704
|
+
let section = "";
|
|
8705
|
+
let depth = 0;
|
|
8706
|
+
let parent = "";
|
|
8707
|
+
const add = (label, body) => {
|
|
8708
|
+
for (const piece of splitClauses(body)) {
|
|
8709
|
+
const clause = piece.replace(/^\s*and\s+/i, "");
|
|
8710
|
+
const text = plain(label ? `${label}: ${clause}` : clause);
|
|
8711
|
+
if (!text) continue;
|
|
8712
|
+
const kind = classifyEngineChange(`${label} ${clause}`, section);
|
|
8713
|
+
if (!kind) continue;
|
|
8714
|
+
const prs = prsIn(clause);
|
|
8715
|
+
if (!prs.length && kind !== "breaking" && kind !== "security") continue;
|
|
8716
|
+
const families = familiesIn(clause);
|
|
8717
|
+
drafts.push({ version, date: r.date, section, kind, text, prs, families: families.length ? families : familiesIn(label), top: top2, depth });
|
|
8718
|
+
}
|
|
8719
|
+
};
|
|
8720
|
+
for (let i = 0; i < lines.length; i++) {
|
|
8721
|
+
const raw = lines[i];
|
|
8722
|
+
const h = /^(#{2,4})\s+(.+?)\s*$/.exec(raw);
|
|
8723
|
+
if (h) {
|
|
8724
|
+
const title = plain(h[2]);
|
|
8725
|
+
if (h[1].length === 2) {
|
|
8726
|
+
top2 = title;
|
|
8727
|
+
depth = 2;
|
|
8728
|
+
} else depth = h[1].length;
|
|
8729
|
+
section = title;
|
|
8730
|
+
parent = "";
|
|
8731
|
+
continue;
|
|
8732
|
+
}
|
|
8733
|
+
const sum2 = /<summary>(.*?)<\/summary>/i.exec(raw);
|
|
8734
|
+
if (sum2) {
|
|
8735
|
+
section = plain(sum2[1]);
|
|
8736
|
+
depth = 3;
|
|
8737
|
+
parent = "";
|
|
8738
|
+
if (SKIP_SECTION.test(top2) && /full changelog/i.test(top2)) top2 = "Changelog";
|
|
8739
|
+
continue;
|
|
8740
|
+
}
|
|
8741
|
+
if (SKIP_SECTION.test(section) || SKIP_SECTION.test(top2) && section === top2) continue;
|
|
8742
|
+
const bold = /^\*\*([^*]+?):?\*\*:?\s*$/.exec(raw.trim());
|
|
8743
|
+
if (bold && !/^\s*[*-]\s/.test(raw)) {
|
|
8744
|
+
section = plain(bold[1]);
|
|
8745
|
+
depth = Math.max(depth, 3);
|
|
8746
|
+
parent = "";
|
|
8747
|
+
continue;
|
|
8748
|
+
}
|
|
8749
|
+
if (/^\s*\|/.test(raw)) {
|
|
8750
|
+
if (/^\s*\|[\s:|-]+\|\s*$/.test(raw) || /^\s*\|[\s:|-]+\|\s*$/.test(lines[i + 1] ?? "")) continue;
|
|
8751
|
+
const cells = raw.trim().replace(/^\||\|$/g, "").split("|").map((c) => c.trim());
|
|
8752
|
+
const refs = cells.filter((c) => /^(#\d+[,\s]*)+$/.test(c)).join(" ");
|
|
8753
|
+
const words = cells.filter((c) => c && !/^(#\d+[,\s]*)+$/.test(c) && !new RegExp(`^[${String.fromCharCode(8212)}-]$`).test(c));
|
|
8754
|
+
if (!words.length) continue;
|
|
8755
|
+
const said = words.join(": ");
|
|
8756
|
+
const kind = classifyEngineChange(said, section);
|
|
8757
|
+
if (kind) drafts.push({ version, date: r.date, section, kind, text: plain(said), prs: prsIn(refs), families: familiesIn(said), top: top2, depth });
|
|
8758
|
+
continue;
|
|
8759
|
+
}
|
|
8760
|
+
const b = /^(\s*)[*-]\s+(.+)$/.exec(raw);
|
|
8761
|
+
if (!b || !section) continue;
|
|
8762
|
+
const nested = b[1].length > 0;
|
|
8763
|
+
const lab = /^\*\*(.+?)\*\*:?\s*(.*)$/.exec(b[2]);
|
|
8764
|
+
if (!nested) {
|
|
8765
|
+
if (lab) {
|
|
8766
|
+
parent = plain(lab[1]);
|
|
8767
|
+
if (lab[2].trim()) add(parent, lab[2]);
|
|
8768
|
+
} else {
|
|
8769
|
+
parent = /:\s*$/.test(b[2]) ? plain(b[2]) : "";
|
|
8770
|
+
add("", b[2]);
|
|
8771
|
+
}
|
|
8772
|
+
} else if (lab && lab[2].trim()) add(parent ? `${parent}, ${plain(lab[1])}` : plain(lab[1]), lab[2]);
|
|
8773
|
+
else add(parent, lab ? lab[1] : b[2]);
|
|
8774
|
+
}
|
|
8775
|
+
const hasTopics = drafts.some((d) => !SUMMARY_TOP.test(d.top));
|
|
8776
|
+
const isSummary = (d) => SUMMARY_TOP.test(d.top) && (hasTopics || d.depth === 2) && d.kind !== "breaking";
|
|
8777
|
+
const rows = [];
|
|
8778
|
+
const claimed = /* @__PURE__ */ new Set();
|
|
8779
|
+
const texts = /* @__PURE__ */ new Set();
|
|
8780
|
+
const keep = (d) => {
|
|
8781
|
+
if (d.prs.length ? d.prs.every((p) => claimed.has(p)) : texts.has(d.text)) return;
|
|
8782
|
+
d.prs.forEach((p) => claimed.add(p));
|
|
8783
|
+
texts.add(d.text);
|
|
8784
|
+
rows.push({ version: d.version, date: d.date, section: d.section, kind: d.kind, text: d.text, prs: d.prs, families: d.families });
|
|
8785
|
+
};
|
|
8786
|
+
drafts.filter((d) => !isSummary(d)).forEach(keep);
|
|
8787
|
+
drafts.filter(isSummary).forEach(keep);
|
|
8788
|
+
return { version, rows };
|
|
8789
|
+
}
|
|
8790
|
+
function cmp(a, b) {
|
|
8791
|
+
const x = a.split(".").map(Number);
|
|
8792
|
+
const y = b.split(".").map(Number);
|
|
8793
|
+
for (let i = 0; i < 3; i++) if ((x[i] ?? 0) !== (y[i] ?? 0)) return (x[i] ?? 0) - (y[i] ?? 0);
|
|
8794
|
+
return 0;
|
|
8795
|
+
}
|
|
8796
|
+
var norm2 = (v) => {
|
|
8797
|
+
const m = /^v?(\d+)\.(\d+)(?:\.(\d+))?/.exec(v);
|
|
8798
|
+
return m ? `${m[1]}.${m[2]}.${m[3] ?? 0}` : void 0;
|
|
8799
|
+
};
|
|
8800
|
+
function engineChangesSince(record, version, modelId, opts = {}) {
|
|
8801
|
+
const v = version ? norm2(version) : void 0;
|
|
8802
|
+
if (!v || !record.releases.length) return null;
|
|
8803
|
+
const newer = record.releases.filter((r) => cmp(r.version, v) > 0);
|
|
8804
|
+
if (!newer.length) return null;
|
|
8805
|
+
const latest = record.releases.map((r) => r.version).sort(cmp).pop();
|
|
8806
|
+
const family = familyOf(modelId);
|
|
8807
|
+
const later = record.rows.filter((r) => cmp(r.version, v) > 0);
|
|
8808
|
+
const rows = family ? later.filter((r) => r.families.includes(family)).sort((a, b) => cmp(b.version, a.version)) : [];
|
|
8809
|
+
const adapterRows = opts.adapter ? later.filter((r) => r.kind === "adapter" && !r.families.length).length : 0;
|
|
8810
|
+
const breaking = later.filter((r) => r.kind === "breaking" && !(family && r.families.includes(family))).sort((a, b) => cmp(b.version, a.version));
|
|
8811
|
+
const byKind = {};
|
|
8812
|
+
for (const r of rows) byKind[r.kind] = (byKind[r.kind] ?? 0) + 1;
|
|
8813
|
+
return { engine: "vllm", version: v, latest, behind: newer.length, family, rows, adapterRows, breaking, byKind };
|
|
8814
|
+
}
|
|
8815
|
+
var KIND_ORDER = ["tool-calling", "prompt", "adapter", "quantization", "security", "breaking", "model"];
|
|
8816
|
+
var KIND_WORD = {
|
|
8817
|
+
adapter: "adapter loading",
|
|
8818
|
+
"tool-calling": "tool calling",
|
|
8819
|
+
prompt: "prompt rendering",
|
|
8820
|
+
quantization: "quantization",
|
|
8821
|
+
breaking: "breaking change",
|
|
8822
|
+
security: "security",
|
|
8823
|
+
model: "model support"
|
|
8824
|
+
};
|
|
8825
|
+
var FAMILY_NAME = { qwen: "Qwen", llama: "Llama", gemma: "Gemma", deepseek: "DeepSeek", glm: "GLM", kimi: "Kimi", mistral: "Mistral", nemotron: "Nemotron", "gpt-oss": "gpt-oss", phi: "Phi", granite: "Granite", minicpm: "MiniCPM", internvl: "InternVL", hermes: "Hermes", minimax: "MiniMax", ernie: "ERNIE", hunyuan: "Hunyuan", llava: "LLaVA", whisper: "Whisper", cohere: "Cohere", smol: "Smol", bge: "BGE", jina: "Jina", nomic: "Nomic", paligemma: "PaliGemma" };
|
|
8826
|
+
var ENGINE_RECORD_URL = "https://www.neurarch.com/engine-changes/vllm.json";
|
|
8827
|
+
function assessEngine(since) {
|
|
8828
|
+
if (!since) return [];
|
|
8829
|
+
const { rows, adapterRows, breaking } = since;
|
|
8830
|
+
if (!rows.length && !adapterRows && !breaking.length) return [];
|
|
8831
|
+
const fam = since.family ? FAMILY_NAME[since.family] ?? since.family : "";
|
|
8832
|
+
const rank = (k) => KIND_ORDER.indexOf(k);
|
|
8833
|
+
const kinds = Object.entries(since.byKind).sort((a, b) => rank(a[0]) - rank(b[0])).map(([k, n]) => `${n} ${KIND_WORD[k]}`).join(", ");
|
|
8834
|
+
const lead = [...rows].sort((a, b) => rank(a.kind) - rank(b.kind) || cmp(b.version, a.version))[0];
|
|
8835
|
+
const parts = [];
|
|
8836
|
+
if (rows.length) parts.push(`${rows.length} change${rows.length === 1 ? "" : "s"} that name${rows.length === 1 ? "s" : ""} ${fam} (${kinds})`);
|
|
8837
|
+
if (adapterRows) parts.push(`${adapterRows} LoRA change${adapterRows === 1 ? "" : "s"} that name no model`);
|
|
8838
|
+
if (breaking.length) parts.push(`${breaking.length} breaking change${breaking.length === 1 ? "" : "s"} or removal${breaking.length === 1 ? "" : "s"}`);
|
|
8839
|
+
const said = parts.length > 1 ? `${parts.slice(0, -1).join(", ")} and ${parts[parts.length - 1]}` : parts[0];
|
|
8840
|
+
const quote2 = (r) => `${r.text}${r.prs.length && !r.text.includes(`#${r.prs[0]}`) ? ` (#${r.prs[0]})` : ""}`;
|
|
8841
|
+
const examples = [lead ? `For ${fam}, in ${lead.version}: ${quote2(lead)}.` : "", breaking[0] ? `Newest removal, in ${breaking[0].version}: ${quote2(breaking[0])}.` : ""].filter(Boolean).join(" ");
|
|
8842
|
+
return [{
|
|
8843
|
+
lane: "behavior",
|
|
8844
|
+
severity: "low",
|
|
8845
|
+
kind: "engine-changes-since",
|
|
8846
|
+
message: `Served by vLLM ${since.version}, ${since.behind} release${since.behind === 1 ? "" : "s"} behind ${since.latest}. Later release notes record ${said}. ${examples}`.replace(/\.\.+/g, ".").replace(/\s+$/, ""),
|
|
8847
|
+
fix: "Read these before moving the engine, and compare one output on the old and the new engine before go-live. The release notes say what changed, not whether it changes your outputs.",
|
|
8848
|
+
url: ENGINE_RECORD_URL
|
|
8849
|
+
}];
|
|
8850
|
+
}
|
|
8851
|
+
|
|
7876
8852
|
// src/utils/policy/report.ts
|
|
7877
8853
|
var word = (j) => j.effective === "block" ? "block" : j.effective === "warn" ? "warn " : j.effective === "info" ? "info " : "off ";
|
|
7878
8854
|
function renderPolicyText(ev, opts) {
|
|
@@ -7898,61 +8874,436 @@ function renderPolicyText(ev, opts) {
|
|
|
7898
8874
|
lines.push(` ${c.gating ? `${c.gating} blocking` : "nothing blocks"}${c.waived ? `, ${c.waived} waived` : ""}${c.existing ? `, ${c.existing} in baseline` : ""}${c.off ? `, ${c.off} off` : ""}${hidden ? ` (${hidden} not shown; --all to show)` : ""}: exit ${ev.exitCode}`);
|
|
7899
8875
|
return lines.join("\n") + "\n";
|
|
7900
8876
|
}
|
|
8877
|
+
|
|
8878
|
+
// src/utils/policy/modelScan.ts
|
|
8879
|
+
var PICKLE = /\.(bin|pt|pth|pkl|ckpt)$/i;
|
|
8880
|
+
function remoteCodeOf(info, self) {
|
|
8881
|
+
const refs = [];
|
|
8882
|
+
const take = (v) => {
|
|
8883
|
+
if (typeof v === "string") refs.push(v);
|
|
8884
|
+
else if (Array.isArray(v)) v.forEach(take);
|
|
8885
|
+
else if (v && typeof v === "object") Object.values(v).forEach(take);
|
|
8886
|
+
};
|
|
8887
|
+
take(info?.config?.auto_map);
|
|
8888
|
+
take(info?.config?.tokenizer_config?.auto_map);
|
|
8889
|
+
const crossRepo = [...new Set(refs.filter((r) => r.includes("--")).map((r) => r.split("--")[0]))].filter((r) => r !== self).sort();
|
|
8890
|
+
return { declared: refs.length > 0, crossRepo };
|
|
8891
|
+
}
|
|
8892
|
+
function codeFiles(info) {
|
|
8893
|
+
const out = {};
|
|
8894
|
+
for (const s of info?.siblings ?? []) if (s.rfilename.endsWith(".py")) out[s.rfilename] = s.blobId ?? "";
|
|
8895
|
+
return out;
|
|
8896
|
+
}
|
|
8897
|
+
function codeChanged(before, after) {
|
|
8898
|
+
const a = codeFiles(before);
|
|
8899
|
+
const b = codeFiles(after);
|
|
8900
|
+
return [.../* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)])].filter((f) => a[f] !== b[f]).sort();
|
|
8901
|
+
}
|
|
8902
|
+
var WEIGHT_FILE = /\.(safetensors|bin|pt|pth|gguf|h5|msgpack|onnx|ckpt)$/i;
|
|
8903
|
+
var TOKENIZER_FILE = /(^|\/)(tokenizer\.json|tokenizer_config\.json|special_tokens_map\.json|vocab\.json|vocab\.txt|merges\.txt|added_tokens\.json|[\w.-]*\.model|chat_template\.(jinja|json))$/i;
|
|
8904
|
+
var CONFIG_FILE = /(^|\/)(config|generation_config|preprocessor_config|processor_config)\.json$/i;
|
|
8905
|
+
var LICENCE_FILE = /(^|\/)(LICEN[CS]E|NOTICE|USE_POLICY)(\.\w+)?$/i;
|
|
8906
|
+
function fileClass(path) {
|
|
8907
|
+
if (WEIGHT_FILE.test(path) && !/training_args|optimizer/.test(path)) return "weights";
|
|
8908
|
+
if (TOKENIZER_FILE.test(path)) return "tokenizer";
|
|
8909
|
+
if (CONFIG_FILE.test(path)) return "config";
|
|
8910
|
+
if (/\.py$/i.test(path)) return "code";
|
|
8911
|
+
if (LICENCE_FILE.test(path)) return "licence";
|
|
8912
|
+
return "other";
|
|
8913
|
+
}
|
|
8914
|
+
function filesDiffer(before, after) {
|
|
8915
|
+
if (!before?.siblings?.length || !after?.siblings?.length) return null;
|
|
8916
|
+
const key = (x) => x.lfs?.sha256 ?? x.blobId;
|
|
8917
|
+
const a = new Map(before.siblings.map((x) => [x.rfilename, key(x)]));
|
|
8918
|
+
const b = new Map(after.siblings.map((x) => [x.rfilename, key(x)]));
|
|
8919
|
+
if (![...a.values()].some(Boolean) || ![...b.values()].some(Boolean)) return null;
|
|
8920
|
+
const changed = [...a.keys()].filter((f) => b.has(f) && a.get(f) && b.get(f) && a.get(f) !== b.get(f)).sort();
|
|
8921
|
+
const added = [...b.keys()].filter((f) => !a.has(f)).sort();
|
|
8922
|
+
const removed = [...a.keys()].filter((f) => !b.has(f)).sort();
|
|
8923
|
+
return { changed, added, removed };
|
|
8924
|
+
}
|
|
8925
|
+
function weightFormat(info) {
|
|
8926
|
+
const names = (info?.siblings ?? []).map((s) => s.rfilename);
|
|
8927
|
+
if (names.some((n) => n.endsWith(".safetensors") || n.endsWith(".gguf"))) return "safetensors";
|
|
8928
|
+
if (names.some((n) => PICKLE.test(n) && !n.includes("optimizer") && !n.includes("training_args"))) return "pickle-only";
|
|
8929
|
+
return "none";
|
|
8930
|
+
}
|
|
8931
|
+
function recordedSince(changes, id, pinnedSha, pinnedDate) {
|
|
8932
|
+
const mine = changes.filter((c) => c.id === id).sort((a, b) => a.date < b.date ? -1 : a.date > b.date ? 1 : 0);
|
|
8933
|
+
if (!pinnedSha) return mine;
|
|
8934
|
+
const short = pinnedSha.toLowerCase();
|
|
8935
|
+
const hit = (s) => !!s && s.toLowerCase().startsWith(short);
|
|
8936
|
+
const at = mine.findIndex((c) => hit(c.toSha));
|
|
8937
|
+
if (at >= 0) return mine.slice(at + 1);
|
|
8938
|
+
const from = mine.findIndex((c) => hit(c.fromSha));
|
|
8939
|
+
if (from >= 0) return mine.slice(from);
|
|
8940
|
+
if (pinnedDate) return mine.filter((c) => c.date > pinnedDate);
|
|
8941
|
+
return null;
|
|
8942
|
+
}
|
|
8943
|
+
var TRIGGER_KINDS = /* @__PURE__ */ new Set(["conditional-literal", "outside-safe-subset"]);
|
|
8944
|
+
var ATTN_FIELDS = ["_attn_implementation_internal", "_attn_implementation", "attn_implementation"];
|
|
8945
|
+
var HUB_REPO = /^[A-Za-z0-9][\w.-]*\/[\w.-]+(?::[\w.-]+)?$/;
|
|
8946
|
+
function attnRepoRefs(cfg) {
|
|
8947
|
+
const out = [];
|
|
8948
|
+
const visit3 = (o, prefix, depth) => {
|
|
8949
|
+
if (!o || typeof o !== "object" || Array.isArray(o)) return;
|
|
8950
|
+
for (const [k, v] of Object.entries(o)) {
|
|
8951
|
+
if (ATTN_FIELDS.includes(k) && typeof v === "string" && HUB_REPO.test(v)) out.push([prefix + k, v]);
|
|
8952
|
+
else if (depth < 1 && v && typeof v === "object") visit3(v, `${prefix}${k}.`, depth + 1);
|
|
8953
|
+
}
|
|
8954
|
+
};
|
|
8955
|
+
visit3(cfg, "", 0);
|
|
8956
|
+
return out;
|
|
8957
|
+
}
|
|
8958
|
+
var changeUrl = (c) => c.commit;
|
|
8959
|
+
function assessRef(r) {
|
|
8960
|
+
const out = [];
|
|
8961
|
+
const main = r.atMain ?? null;
|
|
8962
|
+
const pin = r.pinned ? r.atPin ?? null : main;
|
|
8963
|
+
const declared = remoteCodeOf(main ?? pin, r.id);
|
|
8964
|
+
const code = r.remoteCodeRuns === false ? { declared: false, crossRepo: [] } : declared;
|
|
8965
|
+
const moved = !!(r.pinned && main?.sha && !main.sha.toLowerCase().startsWith(r.pinned.toLowerCase()));
|
|
8966
|
+
if (code.declared && !r.pinned) {
|
|
8967
|
+
out.push({ lane: "security", severity: "high", kind: "remote-code-unpinned", message: `Loads Python from the model repository (auto_map) and is not pinned: with trust_remote_code, whatever ${r.id} has on main runs in your process.`, fix: `Pin revision= to a commit you have read${code.crossRepo.length ? `, and code_revision= for ${code.crossRepo.join(", ")}` : ""}.` });
|
|
8968
|
+
}
|
|
8969
|
+
if (code.crossRepo.length && r.codeRevision !== true) {
|
|
8970
|
+
out.push({ lane: "security", severity: r.pinned ? "high" : "medium", kind: "remote-code-cross-repo", message: `Its auto_map imports code from ${code.crossRepo.join(", ")}. Loaded with trust_remote_code=True, transformers pins that code only with code_revision=; revision= alone pins ${r.id} and still loads the other repository's main.`, fix: `Pass code_revision=<commit of ${code.crossRepo[0]}>, or vendor the module.`, url: "https://github.com/huggingface/transformers/blob/v4.57.1/src/transformers/dynamic_module_utils.py#L595-L602" });
|
|
8971
|
+
}
|
|
8972
|
+
if (moved && r.atPin && main) {
|
|
8973
|
+
const files = codeChanged(r.atPin, main);
|
|
8974
|
+
if (files.length) out.push({ lane: "security", severity: "high", kind: "remote-code-changed", message: `Python in the repository changed since your pin: ${files.join(", ")}. Moving the pin runs different code.`, fix: `Read the diff before moving the pin: https://huggingface.co/${r.id}/compare (or git diff ${r.pinned.slice(0, 12)} main in a clone).` });
|
|
8975
|
+
}
|
|
8976
|
+
const fmtNow = weightFormat(main ?? pin);
|
|
8977
|
+
if (fmtNow === "pickle-only") {
|
|
8978
|
+
const was = r.pinned && r.atPin ? weightFormat(r.atPin) : null;
|
|
8979
|
+
out.push({ lane: "security", severity: was === "safetensors" ? "high" : "medium", kind: was === "safetensors" ? "weights-to-pickle" : "weights-pickle-only", message: was === "safetensors" ? "Weights moved from safetensors to a pickle format (.bin/.pt) since your pin; loading pickle can execute code." : "Weights are only in a pickle format (.bin/.pt); loading pickle can execute code (torch.load weights_only was bypassed in CVE-2025-32434, fixed in torch 2.6.0).", fix: "Prefer a safetensors revision, or load with torch>=2.6 and weights_only=True." });
|
|
8980
|
+
}
|
|
8981
|
+
const attnNow = attnRepoRefs(r.rawConfigMain ?? (r.pinned ? r.rawConfigPin : null));
|
|
8982
|
+
const attnPin = new Set(attnRepoRefs(r.rawConfigPin).map(([k, v]) => `${k}=${v}`));
|
|
8983
|
+
for (const [field, repo] of attnNow) {
|
|
8984
|
+
const added = r.pinned && r.rawConfigPin && !attnPin.has(`${field}=${repo}`);
|
|
8985
|
+
out.push({ lane: "security", severity: "high", kind: "config-remote-attention", message: `config.json${added ? " gained" : " sets"} ${field} = "${repo}"${added ? " since your pin" : ""}: a Hub repository named as the attention implementation. transformers before 5.3.0 downloads and runs that repository's code on load, with trust_remote_code=False (CVE-2026-4372).`, fix: "Use transformers >= 5.3.0, and read why a model config names another repository before loading it.", url: "https://github.com/advisories/GHSA-29pf-2h5f-8g72" });
|
|
8986
|
+
}
|
|
8987
|
+
const pinDate = r.pinned ? r.atPin?.lastModified : void 0;
|
|
8988
|
+
for (const l of r.securityRecorded ?? []) {
|
|
8989
|
+
if (l.lane !== "security" || l.id !== r.id) continue;
|
|
8990
|
+
if (r.pinned && (!pinDate || l.date <= pinDate)) continue;
|
|
8991
|
+
if (l.kind === "remote-code-config" && attnNow.length) continue;
|
|
8992
|
+
if (l.kind === "remote-code" && r.pinned && moved) continue;
|
|
8993
|
+
const held = l.kind === "remote-code-repo" && r.codeRevision === true;
|
|
8994
|
+
out.push({ lane: "security", severity: held ? "low" : l.kind === "remote-code-config" || l.kind === "remote-code-repo" && r.pinned ? "high" : "medium", kind: `recorded-${l.kind}`, message: `${l.date.slice(0, 10)}: ${l.sentence}${held ? " Your code_revision holds the code you pinned." : ""}`, ...l.commit ? { url: l.commit } : {} });
|
|
8995
|
+
}
|
|
8996
|
+
const since = recordedSince(r.recorded ?? [], r.id, r.pinned, r.atPin?.lastModified);
|
|
8997
|
+
const relevant = (since ?? []).filter((c) => !c.formatOnly);
|
|
8998
|
+
const triggers = relevant.flatMap((c) => (c.safety ?? []).filter((s) => TRIGGER_KINDS.has(s.kind)).map(() => c));
|
|
8999
|
+
for (const c of [...new Set(triggers)]) {
|
|
9000
|
+
out.push({ lane: "security", severity: "medium", kind: "template-trigger-branch", message: `${c.date.slice(0, 10)}: the chat template gained a branch on a literal string, the shape published template backdoors use. Not evidence of one; read it. ${c.sentence}`, url: changeUrl(c) });
|
|
9001
|
+
}
|
|
9002
|
+
if (!r.pinned) {
|
|
9003
|
+
out.push({ lane: "hygiene", severity: "medium", kind: "unpinned", message: `Not pinned to a commit: every run loads whatever ${r.id} has on main that day.`, fix: main?.sha ? `revision="${main.sha}"` : "Pin revision= to a 40-character commit." });
|
|
9004
|
+
}
|
|
9005
|
+
if (r.templateVerdict === "different") {
|
|
9006
|
+
out.push({ lane: "behavior", severity: "high", kind: "template-render-changed", message: "The chat template at main renders a different prompt than at your pin (system, multi-turn or tool-call conversation).", fix: `npx neurarch template-check ${r.id} --from ${r.pinned?.slice(0, 12)}` });
|
|
9007
|
+
}
|
|
9008
|
+
if (moved && r.atPin && main) {
|
|
9009
|
+
const d = filesDiffer(r.atPin, main);
|
|
9010
|
+
if (d) {
|
|
9011
|
+
const list = (fs) => fs.slice(0, 4).join(", ") + (fs.length > 4 ? ` +${fs.length - 4}` : "");
|
|
9012
|
+
const of = (cls, fs) => fs.filter((f) => fileClass(f) === cls);
|
|
9013
|
+
const weights = [...of("weights", d.changed), ...of("weights", d.removed)];
|
|
9014
|
+
const tok = [...of("tokenizer", d.changed), ...of("tokenizer", d.added), ...of("tokenizer", d.removed)];
|
|
9015
|
+
const cfg = of("config", d.changed);
|
|
9016
|
+
const lic = [...of("licence", d.changed), ...of("licence", d.added)];
|
|
9017
|
+
if (weights.length) out.push({ lane: "behavior", severity: "high", kind: "weights-changed", message: `Weight files differ between your pin and main: ${list(weights)}. Moving the pin loads different weights under the same name.`, fix: "Re-run your evaluation at the new commit before moving the pin." });
|
|
9018
|
+
if (tok.length || cfg.length) out.push({ lane: "behavior", severity: "medium", kind: "files-changed", message: `Changed since your pin: ${list([...tok, ...cfg])}.${r.templateVerdict === "same" ? " The chat template still renders the same prompt on the fixed conversations." : ""}` });
|
|
9019
|
+
if (lic.length) out.push({ lane: "hygiene", severity: "medium", kind: "licence-file-changed", message: `The licence text changed since your pin (${list(lic)}). Read it before moving the pin.` });
|
|
9020
|
+
const model = [...d.changed, ...d.added, ...d.removed].filter((f) => fileClass(f) !== "other");
|
|
9021
|
+
if (!model.length) {
|
|
9022
|
+
const rest = [...d.changed, ...d.added, ...d.removed];
|
|
9023
|
+
out.push({ lane: "hygiene", severity: "low", kind: "pin-behind-docs-only", message: `main has moved since your pin, and no model file differs${rest.length ? ` (only ${list(rest)})` : ""}. Moving the pin loads the same weights, tokenizer, config and code.` });
|
|
9024
|
+
}
|
|
9025
|
+
}
|
|
9026
|
+
}
|
|
9027
|
+
for (const c of relevant) {
|
|
9028
|
+
const eos = c.consequence?.eos != null;
|
|
9029
|
+
const render = c.templateRender?.verdict === "rendering-changed";
|
|
9030
|
+
const sev = eos || render ? "high" : c.classes.some((k) => k === "structural" || k === "tokenizer" || k === "generation-defaults" || k === "template") ? "medium" : "low";
|
|
9031
|
+
if (r.pinned) out.push({ lane: "behavior", severity: sev, kind: `upstream-${c.classes[0] ?? "change"}`, message: c.sentence, url: changeUrl(c) });
|
|
9032
|
+
}
|
|
9033
|
+
if (!r.pinned && relevant.length) {
|
|
9034
|
+
const last = relevant[relevant.length - 1];
|
|
9035
|
+
out.push({ lane: "behavior", severity: "low", kind: "upstream-history", message: `${relevant.length} recorded upstream change${relevant.length === 1 ? "" : "s"} to ${r.id}; the latest, ${last.date.slice(0, 10)}: ${last.sentence}`, url: `https://www.neurarch.com/changes/` });
|
|
9036
|
+
}
|
|
9037
|
+
if (r.pinned && !moved && main?.sha) {
|
|
9038
|
+
out.push({ lane: "hygiene", severity: "low", kind: "pin-current", message: "Pinned at the commit main points at now." });
|
|
9039
|
+
}
|
|
9040
|
+
if (r.pinned && since === null && r.tracked) {
|
|
9041
|
+
out.push({ lane: "behavior", severity: "low", kind: "pin-not-located", message: "The pinned commit is not in the recorded history and its date could not be read, so recorded changes since it are not listed." });
|
|
9042
|
+
}
|
|
9043
|
+
const rank = { security: 0, behavior: 1, hygiene: 2 };
|
|
9044
|
+
const sevRank = { high: 0, medium: 1, low: 2 };
|
|
9045
|
+
return out.sort((a, b) => rank[a.lane] - rank[b.lane] || sevRank[a.severity] - sevRank[b.severity]);
|
|
9046
|
+
}
|
|
9047
|
+
var scanExitCode = (all) => all.some((fs) => fs.some((f) => f.severity === "high")) ? 1 : 0;
|
|
9048
|
+
function matchParen(src, open) {
|
|
9049
|
+
let depth = 0;
|
|
9050
|
+
for (let i = open; i < src.length; i++) {
|
|
9051
|
+
const c = src[i];
|
|
9052
|
+
if (c === "#") {
|
|
9053
|
+
while (i < src.length && src[i] !== "\n") i++;
|
|
9054
|
+
continue;
|
|
9055
|
+
}
|
|
9056
|
+
if (c === '"' || c === "'") {
|
|
9057
|
+
const triple = src.startsWith(c.repeat(3), i);
|
|
9058
|
+
const d = triple ? c.repeat(3) : c;
|
|
9059
|
+
i += d.length;
|
|
9060
|
+
while (i < src.length && !src.startsWith(d, i)) {
|
|
9061
|
+
if (src[i] === "\\") i++;
|
|
9062
|
+
i++;
|
|
9063
|
+
}
|
|
9064
|
+
i += d.length - 1;
|
|
9065
|
+
continue;
|
|
9066
|
+
}
|
|
9067
|
+
if (c === "(" || c === "[" || c === "{") depth++;
|
|
9068
|
+
else if (c === ")" || c === "]" || c === "}") {
|
|
9069
|
+
depth--;
|
|
9070
|
+
if (depth === 0) return i + 1;
|
|
9071
|
+
}
|
|
9072
|
+
}
|
|
9073
|
+
return -1;
|
|
9074
|
+
}
|
|
9075
|
+
function appendArgs(src, open, close, items) {
|
|
9076
|
+
const inner = src.slice(open + 1, close - 1);
|
|
9077
|
+
let end = close - 1;
|
|
9078
|
+
while (end > open + 1 && /\s/.test(src[end - 1])) end--;
|
|
9079
|
+
const multiline = inner.includes("\n");
|
|
9080
|
+
const trailingComma = src[end - 1] === ",";
|
|
9081
|
+
if (!multiline) {
|
|
9082
|
+
const sep = end === open + 1 ? "" : trailingComma ? " " : ", ";
|
|
9083
|
+
return src.slice(0, end) + sep + items.join(", ") + src.slice(end);
|
|
9084
|
+
}
|
|
9085
|
+
const lastLineStart = src.lastIndexOf("\n", end - 1) + 1;
|
|
9086
|
+
const indent = /^\s*/.exec(src.slice(lastLineStart, end))[0];
|
|
9087
|
+
const body = items.map((x) => `${indent}${x},`).join("\n");
|
|
9088
|
+
return src.slice(0, end) + (trailingComma ? "" : ",") + "\n" + body + src.slice(end);
|
|
9089
|
+
}
|
|
9090
|
+
var ST_CALLS = /(^|\.)(SentenceTransformer|CrossEncoder|SparseEncoder)$/;
|
|
9091
|
+
function fixPythonCall(src, line, api, set2) {
|
|
9092
|
+
const lines = src.split("\n");
|
|
9093
|
+
const startOfLine = lines.slice(0, line - 1).reduce((n, l) => n + l.length + 1, 0);
|
|
9094
|
+
const name = api.split(".").pop();
|
|
9095
|
+
const re = new RegExp(`\\b${name}\\s*\\(`, "g");
|
|
9096
|
+
re.lastIndex = startOfLine;
|
|
9097
|
+
const m = re.exec(src);
|
|
9098
|
+
if (!m || m.index > startOfLine + (lines[line - 1]?.length ?? 0)) return { skipped: `could not find ${api}( at line ${line}` };
|
|
9099
|
+
const open = m.index + m[0].length - 1;
|
|
9100
|
+
const close = matchParen(src, open);
|
|
9101
|
+
if (close < 0) return { skipped: "unbalanced call" };
|
|
9102
|
+
const call = src.slice(open, close);
|
|
9103
|
+
if (/\*\*\s*\w/.test(call)) return { skipped: "the call passes **kwargs; add code_revision where that dict is built" };
|
|
9104
|
+
const items = [];
|
|
9105
|
+
if (set2.revision && !/\brevision\s*=/.test(call.replace(/code_revision/g, ""))) items.push(`revision="${set2.revision}"`);
|
|
9106
|
+
let out = src;
|
|
9107
|
+
if (set2.codeRevision && !/code_revision/.test(call)) {
|
|
9108
|
+
if (ST_CALLS.test(api)) {
|
|
9109
|
+
for (const kw of ["model_kwargs", "config_kwargs"]) {
|
|
9110
|
+
const k = new RegExp(`\\b${kw}\\s*=\\s*`).exec(call);
|
|
9111
|
+
if (k) {
|
|
9112
|
+
const at = open + k.index + k[0].length;
|
|
9113
|
+
if (out[at] !== "{") return { skipped: `${kw} is not a literal dict; add "code_revision": "${set2.codeRevision}" to it` };
|
|
9114
|
+
out = out.slice(0, at + 1) + `"code_revision": "${set2.codeRevision}", ` + out.slice(at + 1);
|
|
9115
|
+
} else items.push(`${kw}={"code_revision": "${set2.codeRevision}"}`);
|
|
9116
|
+
}
|
|
9117
|
+
} else items.push(`code_revision="${set2.codeRevision}"`);
|
|
9118
|
+
}
|
|
9119
|
+
if (!items.length && out === src) return { skipped: "already holds both" };
|
|
9120
|
+
const close2 = matchParen(out, open);
|
|
9121
|
+
return { src: items.length ? appendArgs(out, open, close2, items) : out };
|
|
9122
|
+
}
|
|
9123
|
+
function fixShellLine(src, line, set2) {
|
|
9124
|
+
const lines = src.split("\n");
|
|
9125
|
+
let end = line - 1;
|
|
9126
|
+
while (end < lines.length - 1 && /\\\s*$/.test(lines[end])) end++;
|
|
9127
|
+
const logical = lines.slice(line - 1, end + 1).join("\n");
|
|
9128
|
+
const add = [];
|
|
9129
|
+
if (set2.revision && !/--revision\b/.test(logical)) add.push(`--revision ${set2.revision}`);
|
|
9130
|
+
if (set2.codeRevision && !/--code-revision\b/.test(logical)) add.push(`--code-revision ${set2.codeRevision}`);
|
|
9131
|
+
if (!add.length) return { skipped: "already holds both" };
|
|
9132
|
+
const l = lines[end];
|
|
9133
|
+
const cm = /\s+#.*$/.exec(l);
|
|
9134
|
+
const body = cm ? l.slice(0, cm.index) : l;
|
|
9135
|
+
lines[end] = `${body.replace(/\s+$/, "")} ${add.join(" ")}${cm ? cm[0] : ""}`;
|
|
9136
|
+
return { src: lines.join("\n") };
|
|
9137
|
+
}
|
|
9138
|
+
var NIST_MAP = {
|
|
9139
|
+
security: ["NIST SP 800-218A PW.4.4 (verify integrity, provenance and security of acquired AI models; scan for malicious content before use)"],
|
|
9140
|
+
behavior: ["NIST SP 800-218A PW.4.4 (verify acquired AI components, including configuration parameters, before use)"],
|
|
9141
|
+
hygiene: ["NIST SP 800-218A PS.3.1 (version and track AI models in asset inventories)", "NIST AI 600-1 GV-1.6-003 (record versions of underlying models)"]
|
|
9142
|
+
};
|
|
9143
|
+
var CVE_OF = { "config-remote-attention": "CVE-2026-4372", "weights-pickle-only": "CVE-2025-32434", "weights-to-pickle": "CVE-2025-32434" };
|
|
9144
|
+
var purl = (id, sha) => `pkg:huggingface/${id}${sha ? `@${sha.toLowerCase()}` : ""}`;
|
|
9145
|
+
function scanBom(models, meta) {
|
|
9146
|
+
const components = [];
|
|
9147
|
+
const dependencies = [];
|
|
9148
|
+
const vulnerabilities = [];
|
|
9149
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9150
|
+
for (const m of models) {
|
|
9151
|
+
const ref = purl(m.id, m.pinned ?? m.mainSha);
|
|
9152
|
+
if (seen.has(ref)) continue;
|
|
9153
|
+
seen.add(ref);
|
|
9154
|
+
components.push({
|
|
9155
|
+
"bom-ref": ref,
|
|
9156
|
+
type: "machine-learning-model",
|
|
9157
|
+
name: m.id,
|
|
9158
|
+
version: m.pinned ?? (m.mainSha ? `main@${m.mainSha}` : "main"),
|
|
9159
|
+
purl: ref,
|
|
9160
|
+
externalReferences: [{ type: "distribution", url: `https://huggingface.co/${m.id}${m.pinned ? `/tree/${m.pinned}` : ""}` }],
|
|
9161
|
+
properties: [
|
|
9162
|
+
{ name: "neurarch:pinned", value: m.pinned ? "true" : "false" },
|
|
9163
|
+
...m.mainSha ? [{ name: "neurarch:upstreamMain", value: m.mainSha }] : [],
|
|
9164
|
+
...m.sites.map((s) => ({ name: "neurarch:callSite", value: s }))
|
|
9165
|
+
]
|
|
9166
|
+
});
|
|
9167
|
+
const deps = [];
|
|
9168
|
+
for (const c of m.codeRepos ?? []) {
|
|
9169
|
+
const cref = purl(c.id, c.sha);
|
|
9170
|
+
deps.push(cref);
|
|
9171
|
+
if (!seen.has(cref)) {
|
|
9172
|
+
seen.add(cref);
|
|
9173
|
+
components.push({ "bom-ref": cref, type: "library", name: c.id, version: c.sha ?? "main", purl: cref, description: "Python modules imported through auto_map from another repository", properties: [{ name: "neurarch:codeRevisionHeld", value: c.held ? "true" : "false" }] });
|
|
9174
|
+
}
|
|
9175
|
+
}
|
|
9176
|
+
if (deps.length) dependencies.push({ ref, dependsOn: deps });
|
|
9177
|
+
for (const f of m.findings) {
|
|
9178
|
+
if (f.kind === "pin-current") continue;
|
|
9179
|
+
const cve = CVE_OF[f.kind];
|
|
9180
|
+
vulnerabilities.push({
|
|
9181
|
+
"bom-ref": `${ref}#${f.kind}-${vulnerabilities.length}`,
|
|
9182
|
+
id: cve ?? `NEURARCH-${f.kind}`,
|
|
9183
|
+
source: cve ? { name: "NVD", url: `https://nvd.nist.gov/vuln/detail/${cve}` } : { name: "neurarch", url: "https://www.neurarch.com/changes/" },
|
|
9184
|
+
ratings: [{ severity: f.severity === "high" ? "high" : f.severity === "medium" ? "medium" : "low", method: "other" }],
|
|
9185
|
+
description: f.message,
|
|
9186
|
+
...f.fix ? { recommendation: f.fix } : {},
|
|
9187
|
+
affects: [{ ref }],
|
|
9188
|
+
properties: [{ name: "neurarch:lane", value: f.lane }, ...NIST_MAP[f.lane].map((v) => ({ name: "neurarch:maps-to", value: v })), ...f.url ? [{ name: "neurarch:evidence", value: f.url }] : []]
|
|
9189
|
+
});
|
|
9190
|
+
}
|
|
9191
|
+
}
|
|
9192
|
+
return {
|
|
9193
|
+
bomFormat: "CycloneDX",
|
|
9194
|
+
specVersion: "1.6",
|
|
9195
|
+
serialNumber: meta.serial,
|
|
9196
|
+
version: 1,
|
|
9197
|
+
metadata: {
|
|
9198
|
+
timestamp: meta.timestamp,
|
|
9199
|
+
tools: { components: [{ type: "application", name: meta.tool, version: meta.version }] },
|
|
9200
|
+
properties: [
|
|
9201
|
+
{ name: "neurarch:maps-to", value: "NIST SP 800-218A PS.3.2 (provenance data for all components, e.g. in an SBOM)" },
|
|
9202
|
+
{ name: "neurarch:maps-to", value: "NIST AI 600-1 GV-1.6-003 (inventory records versions of underlying models)" },
|
|
9203
|
+
{ name: "neurarch:note", value: "The NIST items are recommendations. This BOM is evidence toward them, not a certification. Lanes: security = code that runs on load or weights that can execute; behavior = what the model receives changed, not a vulnerability; hygiene = not pinned." }
|
|
9204
|
+
]
|
|
9205
|
+
},
|
|
9206
|
+
components,
|
|
9207
|
+
dependencies,
|
|
9208
|
+
vulnerabilities
|
|
9209
|
+
};
|
|
9210
|
+
}
|
|
7901
9211
|
export {
|
|
7902
9212
|
BASELINE_PATH,
|
|
7903
9213
|
BUILTIN_PRESETS,
|
|
7904
9214
|
CHANGE_FEEDS_URL,
|
|
7905
9215
|
CHECKERS,
|
|
7906
9216
|
DEFAULT_WAIVER_DAYS,
|
|
9217
|
+
ENGINE_RECORD_URL,
|
|
9218
|
+
GATE_RECORD_SCHEMA,
|
|
9219
|
+
NIST_MAP,
|
|
7907
9220
|
PIN_RULE_META,
|
|
7908
9221
|
POLICY_FILE_NAMES,
|
|
7909
9222
|
POLICY_SCHEMA,
|
|
7910
9223
|
RENOVATE_PRESET_URL,
|
|
7911
9224
|
RULE_RENAMES,
|
|
7912
9225
|
SCHEMA_ID,
|
|
9226
|
+
VLLM_WRAPPER_FIX,
|
|
7913
9227
|
YAML_MODEL_KEYS,
|
|
9228
|
+
acceleratorsIn,
|
|
9229
|
+
adapterLayout,
|
|
7914
9230
|
addDays,
|
|
7915
9231
|
allLineHashes,
|
|
7916
9232
|
anchorLine,
|
|
9233
|
+
assessAdapter,
|
|
9234
|
+
assessEngine,
|
|
9235
|
+
assessRef,
|
|
9236
|
+
attnRepoRefs,
|
|
7917
9237
|
budgetFindings,
|
|
9238
|
+
buildGateRecord,
|
|
7918
9239
|
buildSarif,
|
|
7919
9240
|
cardMatches,
|
|
9241
|
+
classifyEngineChange,
|
|
9242
|
+
codeChanged,
|
|
9243
|
+
engineChangesSince,
|
|
9244
|
+
engineIn,
|
|
9245
|
+
envPairs,
|
|
7920
9246
|
evaluate,
|
|
9247
|
+
familiesIn,
|
|
9248
|
+
familyOf,
|
|
7921
9249
|
findingFingerprint,
|
|
9250
|
+
fixPythonCall,
|
|
9251
|
+
fixShellLine,
|
|
7922
9252
|
fromChangeGate,
|
|
7923
9253
|
fromDataFit,
|
|
7924
9254
|
fromLayout,
|
|
7925
9255
|
fromLint,
|
|
7926
9256
|
fromPinCheck,
|
|
7927
9257
|
fromServe,
|
|
9258
|
+
gateLedgerRow,
|
|
9259
|
+
gateSubjectFromEnv,
|
|
9260
|
+
gateVerdict,
|
|
7928
9261
|
globToRegExp,
|
|
7929
9262
|
isPinnedRevision,
|
|
7930
9263
|
isValidDate,
|
|
7931
9264
|
keysFor,
|
|
9265
|
+
launchesIn,
|
|
7932
9266
|
levelFor,
|
|
7933
9267
|
lineHash,
|
|
7934
9268
|
loadPolicy,
|
|
9269
|
+
loraModulePaths,
|
|
9270
|
+
manifestPinFix,
|
|
7935
9271
|
matchWaiver,
|
|
7936
9272
|
memoryFindings,
|
|
7937
9273
|
mergeBaseline,
|
|
7938
9274
|
parseChangedLines,
|
|
7939
9275
|
parseCount,
|
|
9276
|
+
parseEngineRelease,
|
|
7940
9277
|
parseInlineWaivers,
|
|
7941
9278
|
parsePolicyText,
|
|
7942
9279
|
parsePresetRef,
|
|
7943
9280
|
pinFileKind,
|
|
7944
9281
|
pinSpelling,
|
|
9282
|
+
pyStringConstants,
|
|
7945
9283
|
readBaseline,
|
|
7946
9284
|
readPolicyDoc,
|
|
9285
|
+
recordedSince,
|
|
9286
|
+
refFileKind,
|
|
9287
|
+
releaseVersion,
|
|
9288
|
+
remoteCodeOf,
|
|
7947
9289
|
renderPolicyText,
|
|
7948
9290
|
resolveCard,
|
|
7949
9291
|
resolveWaivers,
|
|
9292
|
+
scanAdapterConfig,
|
|
9293
|
+
scanBom,
|
|
9294
|
+
scanEnvModels,
|
|
9295
|
+
scanExitCode,
|
|
9296
|
+
scanManifestModels,
|
|
9297
|
+
scanModelRefs,
|
|
7950
9298
|
scanNotebook,
|
|
7951
9299
|
scanPins,
|
|
7952
9300
|
scanPython,
|
|
7953
9301
|
scanShell,
|
|
7954
9302
|
scanYaml,
|
|
9303
|
+
shellCommands,
|
|
7955
9304
|
stableHash,
|
|
7956
9305
|
today,
|
|
7957
|
-
|
|
9306
|
+
versionBefore,
|
|
9307
|
+
waiverKey,
|
|
9308
|
+
weightFormat
|
|
7958
9309
|
};
|