@vantageos/mcp-doctor 0.12.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +55 -0
- package/README.md +12 -0
- package/dist/doctor.d.ts +5 -0
- package/dist/doctor.js +1828 -105
- package/package.json +1 -1
package/dist/doctor.js
CHANGED
|
@@ -649,7 +649,7 @@ function findDiskFiles(tree, pred) {
|
|
|
649
649
|
const out = [];
|
|
650
650
|
const refused = [];
|
|
651
651
|
const base = baseOf(tree);
|
|
652
|
-
const
|
|
652
|
+
const walk3 = (dir) => {
|
|
653
653
|
let entries;
|
|
654
654
|
try {
|
|
655
655
|
entries = readdirSync2(dir);
|
|
@@ -674,7 +674,7 @@ function findDiskFiles(tree, pred) {
|
|
|
674
674
|
recordSkip(tree, full, base);
|
|
675
675
|
continue;
|
|
676
676
|
}
|
|
677
|
-
|
|
677
|
+
walk3(full);
|
|
678
678
|
} else {
|
|
679
679
|
const rel = relative2(base, full).split(sep2).join("/");
|
|
680
680
|
if (!pred(name, rel)) continue;
|
|
@@ -696,7 +696,7 @@ function findDiskFiles(tree, pred) {
|
|
|
696
696
|
}
|
|
697
697
|
}
|
|
698
698
|
};
|
|
699
|
-
|
|
699
|
+
walk3(base);
|
|
700
700
|
return Object.assign(out, { refused });
|
|
701
701
|
}
|
|
702
702
|
function readText(path) {
|
|
@@ -767,7 +767,7 @@ function enclosingBlock(file, line, col, levels = 0) {
|
|
|
767
767
|
}
|
|
768
768
|
|
|
769
769
|
// src/detectors/standardPin.ts
|
|
770
|
-
var STANDARD_PIN = "
|
|
770
|
+
var STANDARD_PIN = "c29f83d50781dcca5c99696dcbb5d19bb77ef33d";
|
|
771
771
|
|
|
772
772
|
// src/detectors/dLocalIdentity.ts
|
|
773
773
|
var CLOUD_IDENTITY_PACKAGE = "@vantageos/cloud-identity";
|
|
@@ -2808,15 +2808,15 @@ function failClosedOnUnscanned(d) {
|
|
|
2808
2808
|
run(tree) {
|
|
2809
2809
|
const r = d.run(tree);
|
|
2810
2810
|
if (r.state !== "absent") return r;
|
|
2811
|
-
const
|
|
2811
|
+
const unread2 = (tree.unscannedSource ?? []).filter(
|
|
2812
2812
|
(f) => isProductSource(f) && !/(^|\/)_?generated\//.test(f)
|
|
2813
2813
|
);
|
|
2814
|
-
if (
|
|
2815
|
-
const shown =
|
|
2816
|
-
const reason = `${
|
|
2814
|
+
if (unread2.length === 0) return r;
|
|
2815
|
+
const shown = unread2.slice(0, 5).join(", ");
|
|
2816
|
+
const reason = `${unread2.length} JavaScript/module source file(s) are not scanned (${shown}${unread2.length > 5 ? ", ..." : ""}): absence cannot be asserted from the TypeScript that was read (this run said: ${r.verdict})`;
|
|
2817
2817
|
return {
|
|
2818
2818
|
id: r.id,
|
|
2819
|
-
anchor: `${
|
|
2819
|
+
anchor: `${unread2[0]}:1`,
|
|
2820
2820
|
state: "could-not-judge",
|
|
2821
2821
|
verdict: `could not judge: ${reason}`,
|
|
2822
2822
|
reason
|
|
@@ -3071,7 +3071,7 @@ function collect(base) {
|
|
|
3071
3071
|
const out = [];
|
|
3072
3072
|
const unmeasured = [];
|
|
3073
3073
|
const relOf = (full) => relative3(base, full).split(sep3).join("/");
|
|
3074
|
-
const
|
|
3074
|
+
const walk3 = (dir, depth) => {
|
|
3075
3075
|
if (depth > 8) {
|
|
3076
3076
|
unmeasured.push(`${relOf(dir)}/ (deeper than 8 levels, not walked)`);
|
|
3077
3077
|
return;
|
|
@@ -3095,7 +3095,7 @@ function collect(base) {
|
|
|
3095
3095
|
continue;
|
|
3096
3096
|
}
|
|
3097
3097
|
if (st.isDirectory()) {
|
|
3098
|
-
if (!WALK_SKIP.has(name))
|
|
3098
|
+
if (!WALK_SKIP.has(name)) walk3(full, depth + 1);
|
|
3099
3099
|
} else if (candidate) {
|
|
3100
3100
|
if (!st.isFile()) {
|
|
3101
3101
|
unmeasured.push(`${rel} (not a regular file, not read)`);
|
|
@@ -3113,7 +3113,7 @@ function collect(base) {
|
|
|
3113
3113
|
}
|
|
3114
3114
|
}
|
|
3115
3115
|
};
|
|
3116
|
-
|
|
3116
|
+
walk3(base, 0);
|
|
3117
3117
|
return { bundles: out, unmeasured };
|
|
3118
3118
|
}
|
|
3119
3119
|
var kb = (n) => `${(n / 1024).toFixed(1)} KB gz`;
|
|
@@ -5997,7 +5997,7 @@ function untouchedParams(s, params, names, bStart, bEnd, fwdOpen, fwdClose) {
|
|
|
5997
5997
|
}
|
|
5998
5998
|
function toolRegistrations(tree) {
|
|
5999
5999
|
const regs = [];
|
|
6000
|
-
const
|
|
6000
|
+
const unread2 = [];
|
|
6001
6001
|
for (const c of callsMatching(
|
|
6002
6002
|
tree,
|
|
6003
6003
|
/^(?:[\w$]+\.)+(?:tool|registerTool|registerToolTask|setRequestHandler)$|^(?:registerTool|registerToolTask)$/
|
|
@@ -6012,7 +6012,7 @@ function toolRegistrations(tree) {
|
|
|
6012
6012
|
if (/^(?:[\w$]+\.)*[\w$]*RequestSchema$/.test(schema) && !/CallToolRequestSchema$/.test(schema))
|
|
6013
6013
|
continue;
|
|
6014
6014
|
if (!/CallToolRequestSchema$/.test(schema)) {
|
|
6015
|
-
|
|
6015
|
+
unread2.push({
|
|
6016
6016
|
anchor: c.anchor,
|
|
6017
6017
|
reason: `${c.anchor} setRequestHandler(${schema.slice(0, 30)}, ...) registers a handler for a request the scan cannot name: whether it dispatches tools/call is unread`
|
|
6018
6018
|
});
|
|
@@ -6079,7 +6079,7 @@ function toolRegistrations(tree) {
|
|
|
6079
6079
|
if (h.method !== void 0 && transparent.has(h.method)) continue;
|
|
6080
6080
|
const anchor = anchorAt(s, h.at);
|
|
6081
6081
|
const reason = h.method === void 0 ? "" : why.get(h.method);
|
|
6082
|
-
|
|
6082
|
+
unread2.push({
|
|
6083
6083
|
anchor,
|
|
6084
6084
|
reason: `${anchor} \`${s.code.slice(h.at, h.at + h.len + 12).replace(/\s+/g, "").slice(
|
|
6085
6085
|
0,
|
|
@@ -6089,7 +6089,7 @@ function toolRegistrations(tree) {
|
|
|
6089
6089
|
}
|
|
6090
6090
|
}
|
|
6091
6091
|
}
|
|
6092
|
-
return { regs, unread };
|
|
6092
|
+
return { regs, unread: unread2 };
|
|
6093
6093
|
}
|
|
6094
6094
|
function unreadSource(tree) {
|
|
6095
6095
|
return tree.skippedDirs.filter((d) => /— not read$/.test(d.reason) && isProductSource(d.path)).map((d) => ({
|
|
@@ -7103,12 +7103,12 @@ var c11Pagination = {
|
|
|
7103
7103
|
};
|
|
7104
7104
|
}
|
|
7105
7105
|
const red = [];
|
|
7106
|
-
const
|
|
7106
|
+
const unread2 = [];
|
|
7107
7107
|
const ok = [];
|
|
7108
7108
|
for (const p of probes) {
|
|
7109
7109
|
const j = judgeCursorProbe(p);
|
|
7110
7110
|
if (j.kind === "red") red.push(j.text);
|
|
7111
|
-
else if (j.kind === "unread")
|
|
7111
|
+
else if (j.kind === "unread") unread2.push(j.text);
|
|
7112
7112
|
else ok.push(j.text);
|
|
7113
7113
|
}
|
|
7114
7114
|
if (red.length > 0) {
|
|
@@ -7119,8 +7119,8 @@ var c11Pagination = {
|
|
|
7119
7119
|
verdict: `${red.join("; ")} -> an invalid cursor on a protocol list method is -32602; passed as a tool argument it is a tool result with isError: true and structuredContent.error.code "invalid_cursor" (SEP-1303) (C-11)`
|
|
7120
7120
|
};
|
|
7121
7121
|
}
|
|
7122
|
-
if (
|
|
7123
|
-
const reason = `${
|
|
7122
|
+
if (unread2.length > 0) {
|
|
7123
|
+
const reason = `${unread2.join("; ")} (C-11)`;
|
|
7124
7124
|
return {
|
|
7125
7125
|
id: this.id,
|
|
7126
7126
|
anchor,
|
|
@@ -8277,12 +8277,12 @@ var c18StructureManifestInner = {
|
|
|
8277
8277
|
let manifestName = kind === "extension" ? "extension.json" : "mcp.json";
|
|
8278
8278
|
if (kind === "server") {
|
|
8279
8279
|
const cands = rootCandidates(tree.root);
|
|
8280
|
-
const
|
|
8281
|
-
if (
|
|
8280
|
+
const unread2 = cands.find((c) => c.readError !== void 0);
|
|
8281
|
+
if (unread2) {
|
|
8282
8282
|
return couldNotJudge(
|
|
8283
8283
|
this.id,
|
|
8284
|
-
|
|
8285
|
-
`${
|
|
8284
|
+
unread2.path,
|
|
8285
|
+
`${unread2.name} is present but ${unread2.readError} \u2014 the server manifest cannot be judged (C-18)`
|
|
8286
8286
|
);
|
|
8287
8287
|
}
|
|
8288
8288
|
const bad = cands.find((c) => c.role === "unparseable");
|
|
@@ -9763,12 +9763,12 @@ var c26SubpackageLockfile = {
|
|
|
9763
9763
|
const verdicts = scope.sites.map(gateSite);
|
|
9764
9764
|
const inventory = renderCoverage(scope.sites, verdicts);
|
|
9765
9765
|
const analysed = verdicts.filter((v) => v.status === "analysed");
|
|
9766
|
-
const
|
|
9767
|
-
if (
|
|
9768
|
-
const reason = `${
|
|
9766
|
+
const unread2 = verdicts.filter((v) => v.status === "unreadable");
|
|
9767
|
+
if (unread2.length > 0 && !analysed.some((v) => v.ok === false)) {
|
|
9768
|
+
const reason = `${unread2.length} deployable site(s) could not be read \u2014 ${unread2.map((v) => v.reason).join("; ")}. Coverage: ${inventory}`;
|
|
9769
9769
|
return {
|
|
9770
9770
|
id: this.id,
|
|
9771
|
-
anchor:
|
|
9771
|
+
anchor: unread2[0].site.dir,
|
|
9772
9772
|
state: "could-not-judge",
|
|
9773
9773
|
reason,
|
|
9774
9774
|
verdict: `could not judge: ${reason}`
|
|
@@ -11435,13 +11435,13 @@ function baseIsResult(file, base, tree) {
|
|
|
11435
11435
|
}
|
|
11436
11436
|
function handRolledBuilder(tree) {
|
|
11437
11437
|
const scan = fieldWrites(tree, HANDROLLED_FIELDS);
|
|
11438
|
-
const
|
|
11438
|
+
const unread2 = [...scan.unread];
|
|
11439
11439
|
for (const k of scan.computed) {
|
|
11440
11440
|
if (objectReturned(k.file, k.object).kind !== "returned") continue;
|
|
11441
11441
|
const m = objectMembers(k.file, k.object);
|
|
11442
11442
|
const member = RESULT_ANCHOR_KEYS.find((key) => m.keys.has(key));
|
|
11443
11443
|
if (!member) continue;
|
|
11444
|
-
|
|
11444
|
+
unread2.push({
|
|
11445
11445
|
anchor: k.anchor,
|
|
11446
11446
|
reason: `the computed key \`[${k.expr.slice(0, 40)}]\` at ${k.anchor} sits in a returned result object (it carries \`${member}\`) and may write resultType / ttlMs / cacheScope: which field it writes is unread (D7)`
|
|
11447
11447
|
});
|
|
@@ -11450,7 +11450,7 @@ function handRolledBuilder(tree) {
|
|
|
11450
11450
|
const bind = w.object ? objectReturned(w.file, w.object) : w.base && identReturned(w.file, w.base) ? { kind: "returned", how: `\`${w.base}\` returned` } : { kind: "not-returned", how: w.base ? `\`${w.base}\` never returned` : "no base" };
|
|
11451
11451
|
if (bind.kind === "not-returned") continue;
|
|
11452
11452
|
if (bind.kind === "unread") {
|
|
11453
|
-
|
|
11453
|
+
unread2.push({
|
|
11454
11454
|
anchor: w.anchor,
|
|
11455
11455
|
reason: `\`${w.name}\` is written at ${w.anchor} into an object in ${bind.form}: whether a handler returns it is unread (D7)`
|
|
11456
11456
|
});
|
|
@@ -11461,7 +11461,7 @@ function handRolledBuilder(tree) {
|
|
|
11461
11461
|
const m = objectMembers(w.file, w.object);
|
|
11462
11462
|
result = RESULT_PAYLOAD_KEYS.some((k) => m.keys.has(k));
|
|
11463
11463
|
if (!result && m.spreads.length > 0) {
|
|
11464
|
-
|
|
11464
|
+
unread2.push({
|
|
11465
11465
|
anchor: w.anchor,
|
|
11466
11466
|
reason: `\`${w.name}\` is written at ${w.anchor} into an object whose other members come from \`...${m.spreads[0]}\`: whether that object is a protocol result is unread (D7)`
|
|
11467
11467
|
});
|
|
@@ -11471,10 +11471,10 @@ function handRolledBuilder(tree) {
|
|
|
11471
11471
|
result = baseIsResult(w.file, w.base, tree);
|
|
11472
11472
|
}
|
|
11473
11473
|
if (result) {
|
|
11474
|
-
return { hand: { file: w.file.rel, line: w.line, field: w.name, form: w.form }, unread };
|
|
11474
|
+
return { hand: { file: w.file.rel, line: w.line, field: w.name, form: w.form }, unread: unread2 };
|
|
11475
11475
|
}
|
|
11476
11476
|
}
|
|
11477
|
-
return { hand: null, unread };
|
|
11477
|
+
return { hand: null, unread: unread2 };
|
|
11478
11478
|
}
|
|
11479
11479
|
function controlTree2(text) {
|
|
11480
11480
|
const file = {
|
|
@@ -11536,7 +11536,7 @@ var d7Inner = {
|
|
|
11536
11536
|
};
|
|
11537
11537
|
}
|
|
11538
11538
|
if (sdk.kind === "v2") {
|
|
11539
|
-
const { hand, unread } = handRolledBuilder(tree);
|
|
11539
|
+
const { hand, unread: unread2 } = handRolledBuilder(tree);
|
|
11540
11540
|
if (hand) {
|
|
11541
11541
|
return {
|
|
11542
11542
|
id: this.id,
|
|
@@ -11545,11 +11545,11 @@ var d7Inner = {
|
|
|
11545
11545
|
verdict: `hand-rolled result builder (\`${hand.field}\` written by hand as a ${hand.form} into a result object at ${hand.file}:${hand.line}) and @vantageos/mcp-protocol-kit not a dependency -> let the SDK emit resultType/ttlMs/cacheScope (cacheHints) or adopt the kit (D7)`
|
|
11546
11546
|
};
|
|
11547
11547
|
}
|
|
11548
|
-
if (
|
|
11549
|
-
const reason = `${
|
|
11548
|
+
if (unread2.length > 0) {
|
|
11549
|
+
const reason = `${unread2.length} protocol-field write(s) could not be judged \u2014 ${unread2[0].reason}`;
|
|
11550
11550
|
return {
|
|
11551
11551
|
id: this.id,
|
|
11552
|
-
anchor:
|
|
11552
|
+
anchor: unread2[0].anchor,
|
|
11553
11553
|
state: "could-not-judge",
|
|
11554
11554
|
reason,
|
|
11555
11555
|
verdict: `could not judge: ${reason}`
|
|
@@ -12938,7 +12938,7 @@ function findExtensionManifests(tree) {
|
|
|
12938
12938
|
} catch {
|
|
12939
12939
|
return out;
|
|
12940
12940
|
}
|
|
12941
|
-
const
|
|
12941
|
+
const walk3 = (dir) => {
|
|
12942
12942
|
let entries;
|
|
12943
12943
|
try {
|
|
12944
12944
|
entries = readdirSync9(dir);
|
|
@@ -12960,7 +12960,7 @@ function findExtensionManifests(tree) {
|
|
|
12960
12960
|
recordSkip(tree, full, base);
|
|
12961
12961
|
continue;
|
|
12962
12962
|
}
|
|
12963
|
-
|
|
12963
|
+
walk3(full);
|
|
12964
12964
|
} else if (name === "extension.json") {
|
|
12965
12965
|
if (!st.isFile()) {
|
|
12966
12966
|
recordSkip(tree, full, base, "not a regular file (FIFO, socket or device) \u2014 not read");
|
|
@@ -12970,7 +12970,7 @@ function findExtensionManifests(tree) {
|
|
|
12970
12970
|
}
|
|
12971
12971
|
}
|
|
12972
12972
|
};
|
|
12973
|
-
|
|
12973
|
+
walk3(base);
|
|
12974
12974
|
return out;
|
|
12975
12975
|
}
|
|
12976
12976
|
|
|
@@ -13619,7 +13619,7 @@ function findHooksDirs(tree, unreadable, gaps) {
|
|
|
13619
13619
|
unreadable.push({ anchor, reason });
|
|
13620
13620
|
}
|
|
13621
13621
|
};
|
|
13622
|
-
const
|
|
13622
|
+
const walk3 = (dir) => {
|
|
13623
13623
|
let entries;
|
|
13624
13624
|
try {
|
|
13625
13625
|
entries = readdirSync10(dir);
|
|
@@ -13659,10 +13659,10 @@ function findHooksDirs(tree, unreadable, gaps) {
|
|
|
13659
13659
|
}
|
|
13660
13660
|
out.push({ anchor: `${name}/`, tokens });
|
|
13661
13661
|
}
|
|
13662
|
-
|
|
13662
|
+
walk3(full);
|
|
13663
13663
|
}
|
|
13664
13664
|
};
|
|
13665
|
-
|
|
13665
|
+
walk3(base);
|
|
13666
13666
|
return out;
|
|
13667
13667
|
}
|
|
13668
13668
|
var LIFECYCLE_OBJ_RE = /\blifecycle\s*:\s*\{/;
|
|
@@ -14178,7 +14178,7 @@ function collectHooksDirSources(tree, unreadable, gaps) {
|
|
|
14178
14178
|
unreadable.push({ anchor, reason });
|
|
14179
14179
|
}
|
|
14180
14180
|
};
|
|
14181
|
-
const
|
|
14181
|
+
const walk3 = (dir) => {
|
|
14182
14182
|
let entries;
|
|
14183
14183
|
try {
|
|
14184
14184
|
entries = readdirSync11(dir);
|
|
@@ -14233,10 +14233,10 @@ function collectHooksDirSources(tree, unreadable, gaps) {
|
|
|
14233
14233
|
});
|
|
14234
14234
|
}
|
|
14235
14235
|
}
|
|
14236
|
-
|
|
14236
|
+
walk3(full);
|
|
14237
14237
|
}
|
|
14238
14238
|
};
|
|
14239
|
-
|
|
14239
|
+
walk3(base);
|
|
14240
14240
|
return out;
|
|
14241
14241
|
}
|
|
14242
14242
|
var LIFECYCLE_OBJ_RE2 = /\blifecycle\s*:\s*\{/;
|
|
@@ -16124,7 +16124,7 @@ function readInstalledAs(tree) {
|
|
|
16124
16124
|
continue;
|
|
16125
16125
|
}
|
|
16126
16126
|
const files = [];
|
|
16127
|
-
const
|
|
16127
|
+
const walk3 = (d) => {
|
|
16128
16128
|
let names;
|
|
16129
16129
|
try {
|
|
16130
16130
|
names = readdirSync12(d).sort();
|
|
@@ -16145,11 +16145,11 @@ function readInstalledAs(tree) {
|
|
|
16145
16145
|
out.unread.push(`${full.slice(nm.length + 1)} (not stat'ed: ${e.message})`);
|
|
16146
16146
|
continue;
|
|
16147
16147
|
}
|
|
16148
|
-
if (st.isDirectory())
|
|
16148
|
+
if (st.isDirectory()) walk3(full);
|
|
16149
16149
|
else if (st.isFile() && SOURCE_EXT.test(n) && !n.endsWith(".d.ts")) files.push(full);
|
|
16150
16150
|
}
|
|
16151
16151
|
};
|
|
16152
|
-
|
|
16152
|
+
walk3(dir);
|
|
16153
16153
|
if (files.length >= MAX_FILES_PER_PACKAGE) {
|
|
16154
16154
|
out.unread.push(`${dep} (more than ${MAX_FILES_PER_PACKAGE} files: the rest were not read)`);
|
|
16155
16155
|
}
|
|
@@ -16232,7 +16232,7 @@ function delegatedAsElements(tree, fallbackAnchor) {
|
|
|
16232
16232
|
const owed = (what) => [
|
|
16233
16233
|
{ status: "owed", text: what, anchor: fallbackAnchor }
|
|
16234
16234
|
];
|
|
16235
|
-
const
|
|
16235
|
+
const unread2 = inst.unread.length > 0 ? ` (not read: ${inst.unread.slice(0, 3).join("; ")})` : "";
|
|
16236
16236
|
if (!inst.installed) {
|
|
16237
16237
|
const r = owed(
|
|
16238
16238
|
"the AS metadata document is written by a dependency, not by this tree, and node_modules is absent: install with the lockfile's manager and re-run, or read the served metadata (--url)"
|
|
@@ -16241,7 +16241,7 @@ function delegatedAsElements(tree, fallbackAnchor) {
|
|
|
16241
16241
|
}
|
|
16242
16242
|
if (inst.publishers.length === 0) {
|
|
16243
16243
|
const r = owed(
|
|
16244
|
-
`the AS metadata document is not written by this tree and no installed declared dependency serves ${"`/.well-known/oauth-authorization-server`"}${inst.missing.length > 0 ? ` (declared but not installed: ${inst.missing.slice(0, 5).join(", ")})` : ""}${
|
|
16244
|
+
`the AS metadata document is not written by this tree and no installed declared dependency serves ${"`/.well-known/oauth-authorization-server`"}${inst.missing.length > 0 ? ` (declared but not installed: ${inst.missing.slice(0, 5).join(", ")})` : ""}${unread2}: read the served metadata (--url)`
|
|
16245
16245
|
);
|
|
16246
16246
|
return { g: r, l: r };
|
|
16247
16247
|
}
|
|
@@ -16253,7 +16253,7 @@ function delegatedAsElements(tree, fallbackAnchor) {
|
|
|
16253
16253
|
anchor: inst.cimd.anchor
|
|
16254
16254
|
}
|
|
16255
16255
|
] : owed(
|
|
16256
|
-
`the installed ${pk} serves the AS metadata but its code does not state ${[inst.cimd ? "" : "client_id_metadata_document_supported: true", inst.none ? "" : '"none" in token_endpoint_auth_methods_supported'].filter(Boolean).join(" nor ")}${
|
|
16256
|
+
`the installed ${pk} serves the AS metadata but its code does not state ${[inst.cimd ? "" : "client_id_metadata_document_supported: true", inst.none ? "" : '"none" in token_endpoint_auth_methods_supported'].filter(Boolean).join(" nor ")}${unread2}: an installed library can prove an element, never its absence; read the served metadata (--url)`
|
|
16257
16257
|
);
|
|
16258
16258
|
const l = inst.iss ? [
|
|
16259
16259
|
{
|
|
@@ -16262,7 +16262,7 @@ function delegatedAsElements(tree, fallbackAnchor) {
|
|
|
16262
16262
|
anchor: inst.iss.anchor
|
|
16263
16263
|
}
|
|
16264
16264
|
] : owed(
|
|
16265
|
-
`the installed ${pk} serves the AS metadata but its code does not state authorization_response_iss_parameter_supported: true${
|
|
16265
|
+
`the installed ${pk} serves the AS metadata but its code does not state authorization_response_iss_parameter_supported: true${unread2}: read the served metadata (--url)`
|
|
16266
16266
|
);
|
|
16267
16267
|
return { g, l };
|
|
16268
16268
|
}
|
|
@@ -16840,29 +16840,29 @@ var s9ConfusedDeputy = {
|
|
|
16840
16840
|
`${reds.join("; ")} (S-9, positive-control OK)`
|
|
16841
16841
|
);
|
|
16842
16842
|
}
|
|
16843
|
-
const
|
|
16843
|
+
const unread2 = [];
|
|
16844
16844
|
for (const { file, rows } of proxies) {
|
|
16845
16845
|
if (!rows.some((r) => CONSENT_CHECK_RE.test(r))) {
|
|
16846
|
-
|
|
16846
|
+
unread2.push(`${file.rel}: no consent registry lookup (the word consent alone is not one)`);
|
|
16847
16847
|
}
|
|
16848
16848
|
if (!rows.some((r) => EXACT_RE.test(r))) {
|
|
16849
|
-
|
|
16849
|
+
unread2.push(
|
|
16850
16850
|
`${file.rel}: no equality or membership test of redirect_uri against registered values`
|
|
16851
16851
|
);
|
|
16852
16852
|
}
|
|
16853
16853
|
const stateRows = rows.flatMap((r, i) => STATE_CREATE_RE.test(r) ? [i] : []);
|
|
16854
16854
|
if (!stateRows.some((i) => RANDOM_RE.test(`${rows[i]}
|
|
16855
16855
|
${rows[i + 1] ?? ""}`))) {
|
|
16856
|
-
|
|
16856
|
+
unread2.push(
|
|
16857
16857
|
`${file.rel}: the state is not shown to come from a random source (randomUUID, randomBytes, nanoid ...)`
|
|
16858
16858
|
);
|
|
16859
16859
|
}
|
|
16860
16860
|
}
|
|
16861
|
-
if (
|
|
16861
|
+
if (unread2.length > 0) {
|
|
16862
16862
|
return couldNotJudge(
|
|
16863
16863
|
this.id,
|
|
16864
16864
|
`${proxies[0].file.rel}:1`,
|
|
16865
|
-
`no S-9 element is contradicted, but the tree does not show: ${
|
|
16865
|
+
`no S-9 element is contradicted, but the tree does not show: ${unread2.join("; ")} (S-9)`
|
|
16866
16866
|
);
|
|
16867
16867
|
}
|
|
16868
16868
|
return presentResult(
|
|
@@ -17220,14 +17220,14 @@ var s12ListPagination = {
|
|
|
17220
17220
|
const anchor = `${runtime.root} (served list responses)`;
|
|
17221
17221
|
const methods = declaredListMethods(served.capabilities);
|
|
17222
17222
|
const red = [];
|
|
17223
|
-
const
|
|
17223
|
+
const unread2 = [];
|
|
17224
17224
|
const ok = [];
|
|
17225
17225
|
for (const m of methods) {
|
|
17226
17226
|
const l = served.lists.find((x) => x.method === m);
|
|
17227
17227
|
if (!l) {
|
|
17228
|
-
|
|
17228
|
+
unread2.push(`${m}: no record of it in this run`);
|
|
17229
17229
|
} else if (l.outcome !== "answered") {
|
|
17230
|
-
|
|
17230
|
+
unread2.push(
|
|
17231
17231
|
`${m}: ${l.outcome === "refused" ? "refused" : "no answer"} (${l.detail ?? "no detail"})`
|
|
17232
17232
|
);
|
|
17233
17233
|
} else if (l.nextCursor === void 0) {
|
|
@@ -17239,7 +17239,7 @@ var s12ListPagination = {
|
|
|
17239
17239
|
`${m} serves a nextCursor that is not a non-empty string (${JSON.stringify(l.nextCursor)})`
|
|
17240
17240
|
);
|
|
17241
17241
|
} else if (!l.followUp || l.followUp.outcome === "no-answer") {
|
|
17242
|
-
|
|
17242
|
+
unread2.push(
|
|
17243
17243
|
`${m}: the served cursor was not presented back (${l.followUp?.detail ?? "no follow-up recorded"})`
|
|
17244
17244
|
);
|
|
17245
17245
|
} else if (l.followUp.outcome === "refused") {
|
|
@@ -17259,11 +17259,11 @@ var s12ListPagination = {
|
|
|
17259
17259
|
};
|
|
17260
17260
|
}
|
|
17261
17261
|
const note = undeclaredProbeNote(served.capabilities);
|
|
17262
|
-
if (
|
|
17262
|
+
if (unread2.length > 0 || note) {
|
|
17263
17263
|
return couldNotJudge(
|
|
17264
17264
|
this.id,
|
|
17265
17265
|
anchor,
|
|
17266
|
-
`served pagination read on ${ok.length > 0 ? ok.join("; ") : "no list method"}; unread: ${[...
|
|
17266
|
+
`served pagination read on ${ok.length > 0 ? ok.join("; ") : "no list method"}; unread: ${[...unread2, ...note ? [note] : []].join("; ")} (S-12)`
|
|
17267
17267
|
);
|
|
17268
17268
|
}
|
|
17269
17269
|
return {
|
|
@@ -17833,7 +17833,7 @@ var s15CompletionSecurity = {
|
|
|
17833
17833
|
);
|
|
17834
17834
|
}
|
|
17835
17835
|
const reds = [];
|
|
17836
|
-
const
|
|
17836
|
+
const unread2 = [];
|
|
17837
17837
|
let read = 0;
|
|
17838
17838
|
for (const h of handlers) {
|
|
17839
17839
|
let text = "";
|
|
@@ -17850,7 +17850,7 @@ var s15CompletionSecurity = {
|
|
|
17850
17850
|
text = b ? b.text : "";
|
|
17851
17851
|
}
|
|
17852
17852
|
if (text === "") {
|
|
17853
|
-
|
|
17853
|
+
unread2.push(h.anchor);
|
|
17854
17854
|
continue;
|
|
17855
17855
|
}
|
|
17856
17856
|
read++;
|
|
@@ -17875,7 +17875,7 @@ var s15CompletionSecurity = {
|
|
|
17875
17875
|
return couldNotJudge(
|
|
17876
17876
|
this.id,
|
|
17877
17877
|
where,
|
|
17878
|
-
`the completions surface is present (${where}); handlers read: ${read}${read > 0 ? ", each with input validation and a rate limit" : ""}; sites not read (no body to read): ${
|
|
17878
|
+
`the completions surface is present (${where}); handlers read: ${read}${read > 0 ? ", each with input validation and a rate limit" : ""}; sites not read (no body to read): ${unread2.length > 0 ? unread2.join(", ") : "none"}; owed (dynamic): no disclosure \u2014 a completion never suggests a value the caller is not authorized to see (S-15)`
|
|
17879
17879
|
);
|
|
17880
17880
|
}
|
|
17881
17881
|
};
|
|
@@ -17994,8 +17994,8 @@ function documentsFootprint(manifestText) {
|
|
|
17994
17994
|
} catch {
|
|
17995
17995
|
return false;
|
|
17996
17996
|
}
|
|
17997
|
-
const
|
|
17998
|
-
if (Array.isArray(v)) return v.some(
|
|
17997
|
+
const walk3 = (v) => {
|
|
17998
|
+
if (Array.isArray(v)) return v.some(walk3);
|
|
17999
17999
|
if (v === null || typeof v !== "object") return false;
|
|
18000
18000
|
for (const [k, val] of Object.entries(v)) {
|
|
18001
18001
|
if (k === "footprint") {
|
|
@@ -18003,11 +18003,11 @@ function documentsFootprint(manifestText) {
|
|
|
18003
18003
|
if (Array.isArray(val) && val.length > 0) return true;
|
|
18004
18004
|
if (val !== null && typeof val === "object" && Object.keys(val).length > 0) return true;
|
|
18005
18005
|
}
|
|
18006
|
-
if (
|
|
18006
|
+
if (walk3(val)) return true;
|
|
18007
18007
|
}
|
|
18008
18008
|
return false;
|
|
18009
18009
|
};
|
|
18010
|
-
return
|
|
18010
|
+
return walk3(json);
|
|
18011
18011
|
}
|
|
18012
18012
|
|
|
18013
18013
|
// src/detectors/s17-forward-auth.ts
|
|
@@ -19144,7 +19144,7 @@ function resultTypeValue(w) {
|
|
|
19144
19144
|
function mrtrRounds(tree) {
|
|
19145
19145
|
const scan = fieldWrites(tree, ["resultType"]);
|
|
19146
19146
|
const rounds = [];
|
|
19147
|
-
const
|
|
19147
|
+
const unread2 = [...scan.unread];
|
|
19148
19148
|
for (const k of scan.computed) {
|
|
19149
19149
|
const at = computedValueAt(k.file, k.line, k.col);
|
|
19150
19150
|
if (!at) continue;
|
|
@@ -19158,7 +19158,7 @@ function mrtrRounds(tree) {
|
|
|
19158
19158
|
}
|
|
19159
19159
|
}
|
|
19160
19160
|
if (value !== MRTR_VALUE) continue;
|
|
19161
|
-
|
|
19161
|
+
unread2.push({
|
|
19162
19162
|
anchor: k.anchor,
|
|
19163
19163
|
reason: `the computed key \`[${k.expr.slice(0, 40)}]\` at ${k.anchor} is written "${MRTR_VALUE}": whether that key is \`resultType\` (an MRTR input round) is unread (S-27)`
|
|
19164
19164
|
});
|
|
@@ -19166,13 +19166,13 @@ function mrtrRounds(tree) {
|
|
|
19166
19166
|
for (const w of scan.writes) {
|
|
19167
19167
|
const v = resultTypeValue(w);
|
|
19168
19168
|
if (v.kind === "unread") {
|
|
19169
|
-
|
|
19169
|
+
unread2.push({
|
|
19170
19170
|
anchor: w.anchor,
|
|
19171
19171
|
reason: `\`resultType\` at ${w.anchor} is written as ${v.form}: whether it is "${MRTR_VALUE}" (an MRTR input round) is unread (S-27)`
|
|
19172
19172
|
});
|
|
19173
19173
|
} else if (v.value === MRTR_VALUE) rounds.push(w.anchor);
|
|
19174
19174
|
}
|
|
19175
|
-
return { rounds, unread };
|
|
19175
|
+
return { rounds, unread: unread2 };
|
|
19176
19176
|
}
|
|
19177
19177
|
function controlTree3(text) {
|
|
19178
19178
|
const file = {
|
|
@@ -19214,7 +19214,7 @@ var s27ElicitationFloor = {
|
|
|
19214
19214
|
const reds = [];
|
|
19215
19215
|
const product = { ...tree, files: tree.files.filter((f) => isProductSource(f.rel)) };
|
|
19216
19216
|
const mrtrScan = mrtrRounds(product);
|
|
19217
|
-
const
|
|
19217
|
+
const unread2 = mrtrScan.unread;
|
|
19218
19218
|
mrtr = mrtrScan.rounds.length;
|
|
19219
19219
|
for (const file of tree.files) {
|
|
19220
19220
|
if (!isProductSource(file.rel)) continue;
|
|
@@ -19244,7 +19244,7 @@ var s27ElicitationFloor = {
|
|
|
19244
19244
|
});
|
|
19245
19245
|
}
|
|
19246
19246
|
first = mrtrScan.rounds[0] ?? first;
|
|
19247
|
-
if (elicitation + mrtr === 0 &&
|
|
19247
|
+
if (elicitation + mrtr === 0 && unread2.length === 0) {
|
|
19248
19248
|
return absentResult(
|
|
19249
19249
|
this.id,
|
|
19250
19250
|
"-",
|
|
@@ -19263,11 +19263,11 @@ var s27ElicitationFloor = {
|
|
|
19263
19263
|
`${reds.join("; ")} (S-27, positive-control OK)`
|
|
19264
19264
|
);
|
|
19265
19265
|
}
|
|
19266
|
-
if (
|
|
19266
|
+
if (unread2.length > 0) {
|
|
19267
19267
|
return couldNotJudge(
|
|
19268
19268
|
this.id,
|
|
19269
|
-
|
|
19270
|
-
`${
|
|
19269
|
+
unread2[0].anchor,
|
|
19270
|
+
`${unread2.length} resultType value(s) could not be read \u2014 ${unread2.map((u) => u.reason).join("; ")}. ${elicitation} elicitation site(s) and ${mrtr} MRTR round(s) read, no sensitive field requested (S-27)`
|
|
19271
19271
|
);
|
|
19272
19272
|
}
|
|
19273
19273
|
return couldNotJudge(
|
|
@@ -19338,12 +19338,12 @@ function splitTop2(m, from, to) {
|
|
|
19338
19338
|
if (start < to && m.slice(start, to).trim() !== "") parts.push([start, to]);
|
|
19339
19339
|
return parts;
|
|
19340
19340
|
}
|
|
19341
|
-
function listTs(dir,
|
|
19341
|
+
function listTs(dir, unread2, out = []) {
|
|
19342
19342
|
let names;
|
|
19343
19343
|
try {
|
|
19344
19344
|
names = readdirSync13(dir);
|
|
19345
19345
|
} catch (err) {
|
|
19346
|
-
|
|
19346
|
+
unread2.push(`${dir} could not be listed (${fsErrorCode(err)})`);
|
|
19347
19347
|
return out;
|
|
19348
19348
|
}
|
|
19349
19349
|
for (const n of names) {
|
|
@@ -19353,12 +19353,12 @@ function listTs(dir, unread, out = []) {
|
|
|
19353
19353
|
try {
|
|
19354
19354
|
st = statSync20(p);
|
|
19355
19355
|
} catch (err) {
|
|
19356
|
-
|
|
19356
|
+
unread2.push(`${p} could not be read (${fsErrorCode(err)})`);
|
|
19357
19357
|
continue;
|
|
19358
19358
|
}
|
|
19359
|
-
if (st.isDirectory()) listTs(p,
|
|
19359
|
+
if (st.isDirectory()) listTs(p, unread2, out);
|
|
19360
19360
|
else if (n.endsWith(".ts") && !n.endsWith(".test.ts") && !n.endsWith(".d.ts")) {
|
|
19361
|
-
if (!st.isFile())
|
|
19361
|
+
if (!st.isFile()) unread2.push(`${p} is not a regular file \u2014 not read`);
|
|
19362
19362
|
else out.push(p);
|
|
19363
19363
|
}
|
|
19364
19364
|
}
|
|
@@ -19380,14 +19380,14 @@ function discoverBackend(root) {
|
|
|
19380
19380
|
}
|
|
19381
19381
|
return void 0;
|
|
19382
19382
|
}
|
|
19383
|
-
function readDoors(backendRoot,
|
|
19383
|
+
function readDoors(backendRoot, unread2) {
|
|
19384
19384
|
const doors = /* @__PURE__ */ new Map();
|
|
19385
|
-
for (const path of listTs(backendRoot,
|
|
19385
|
+
for (const path of listTs(backendRoot, unread2)) {
|
|
19386
19386
|
let text;
|
|
19387
19387
|
try {
|
|
19388
19388
|
text = readFileSync14(path, "utf8");
|
|
19389
19389
|
} catch (err) {
|
|
19390
|
-
|
|
19390
|
+
unread2.push(`${path} could not be read (${fsErrorCode(err)})`);
|
|
19391
19391
|
continue;
|
|
19392
19392
|
}
|
|
19393
19393
|
const file = {
|
|
@@ -19509,9 +19509,9 @@ function scanS28(tree) {
|
|
|
19509
19509
|
const scan = { violate: [], conform: [], cnj: [], calls: 0, backend: void 0 };
|
|
19510
19510
|
const backendRoot = tree.backendRoot ?? discoverBackend(tree.root);
|
|
19511
19511
|
scan.backend = backendRoot;
|
|
19512
|
-
const
|
|
19513
|
-
const doors = backendRoot ? readDoors(backendRoot,
|
|
19514
|
-
const unreadNote =
|
|
19512
|
+
const unread2 = [];
|
|
19513
|
+
const doors = backendRoot ? readDoors(backendRoot, unread2) : void 0;
|
|
19514
|
+
const unreadNote = unread2.length > 0 ? `; backend source NOT read: ${unread2.join("; ")}` : "";
|
|
19515
19515
|
const files = tree.files.map((f) => ({ f, text: rawText(f), m: masked(f) }));
|
|
19516
19516
|
const actorDoors = /* @__PURE__ */ new Set();
|
|
19517
19517
|
for (const { text } of files) {
|
|
@@ -22509,6 +22509,1726 @@ var s41LakeReader = {
|
|
|
22509
22509
|
}
|
|
22510
22510
|
};
|
|
22511
22511
|
|
|
22512
|
+
// src/detectors/s43-union-input.ts
|
|
22513
|
+
var ID = "S43 union-input";
|
|
22514
|
+
var RULE = "S-43";
|
|
22515
|
+
var MARKER_RE = /\/\/\s*allow-union-input:\s*(.*)$/;
|
|
22516
|
+
var MIN_REASON = 6;
|
|
22517
|
+
var FILE_SPAN = 1e9;
|
|
22518
|
+
var nextBase = 0;
|
|
22519
|
+
var fileByBase = /* @__PURE__ */ new Map();
|
|
22520
|
+
function locate(off) {
|
|
22521
|
+
const base = Math.floor(off / FILE_SPAN) * FILE_SPAN;
|
|
22522
|
+
const file = fileByBase.get(base);
|
|
22523
|
+
if (!file) return null;
|
|
22524
|
+
const lx = lex(file);
|
|
22525
|
+
return { file, line: lineOfOffset(lx.lineStarts, off - base) };
|
|
22526
|
+
}
|
|
22527
|
+
var PUNCT3 = ["===", "!==", "**=", "...", "<<=", ">>=", ">>>", "&&=", "||=", "??="];
|
|
22528
|
+
var PUNCT2 = [
|
|
22529
|
+
"=>",
|
|
22530
|
+
"==",
|
|
22531
|
+
"!=",
|
|
22532
|
+
"<=",
|
|
22533
|
+
">=",
|
|
22534
|
+
"&&",
|
|
22535
|
+
"||",
|
|
22536
|
+
"??",
|
|
22537
|
+
"?.",
|
|
22538
|
+
"++",
|
|
22539
|
+
"--",
|
|
22540
|
+
"+=",
|
|
22541
|
+
"-=",
|
|
22542
|
+
"*=",
|
|
22543
|
+
"/=",
|
|
22544
|
+
"%=",
|
|
22545
|
+
"&=",
|
|
22546
|
+
"|=",
|
|
22547
|
+
"^=",
|
|
22548
|
+
"<<",
|
|
22549
|
+
">>",
|
|
22550
|
+
"**"
|
|
22551
|
+
];
|
|
22552
|
+
var REGEX_AFTER_WORDS = /* @__PURE__ */ new Set([
|
|
22553
|
+
"return",
|
|
22554
|
+
"typeof",
|
|
22555
|
+
"case",
|
|
22556
|
+
"do",
|
|
22557
|
+
"else",
|
|
22558
|
+
"in",
|
|
22559
|
+
"of",
|
|
22560
|
+
"new",
|
|
22561
|
+
"delete",
|
|
22562
|
+
"void",
|
|
22563
|
+
"throw",
|
|
22564
|
+
"instanceof",
|
|
22565
|
+
"yield",
|
|
22566
|
+
"await"
|
|
22567
|
+
]);
|
|
22568
|
+
var lexCache = /* @__PURE__ */ new WeakMap();
|
|
22569
|
+
function lex(file) {
|
|
22570
|
+
const cached = lexCache.get(file);
|
|
22571
|
+
if (cached) return cached;
|
|
22572
|
+
const text = file.lines.map((l) => l.raw).join("\n");
|
|
22573
|
+
const lineStarts = [0];
|
|
22574
|
+
for (let i2 = 0; i2 < text.length; i2++) if (text[i2] === "\n") lineStarts.push(i2 + 1);
|
|
22575
|
+
const lineAt4 = (off) => lineOfOffset(lineStarts, off);
|
|
22576
|
+
const toks = [];
|
|
22577
|
+
const comments = /* @__PURE__ */ new Map();
|
|
22578
|
+
const addComment = (from, to) => {
|
|
22579
|
+
let a = from;
|
|
22580
|
+
while (a < to) {
|
|
22581
|
+
const nl = text.indexOf("\n", a);
|
|
22582
|
+
const end = nl < 0 || nl > to ? to : nl;
|
|
22583
|
+
const ln = lineAt4(a);
|
|
22584
|
+
comments.set(ln, (comments.get(ln) ?? "") + text.slice(a, end));
|
|
22585
|
+
a = end + 1;
|
|
22586
|
+
}
|
|
22587
|
+
};
|
|
22588
|
+
const regexAllowed = () => {
|
|
22589
|
+
const prev = toks[toks.length - 1];
|
|
22590
|
+
if (!prev) return true;
|
|
22591
|
+
if (prev.t === "id") return REGEX_AFTER_WORDS.has(prev.v);
|
|
22592
|
+
if (prev.t !== "p") return false;
|
|
22593
|
+
return !(prev.v === ")" || prev.v === "]" || prev.v === "}");
|
|
22594
|
+
};
|
|
22595
|
+
let i = 0;
|
|
22596
|
+
while (i < text.length) {
|
|
22597
|
+
const c = text[i];
|
|
22598
|
+
if (c === " " || c === " " || c === "\n" || c === "\r") {
|
|
22599
|
+
i++;
|
|
22600
|
+
continue;
|
|
22601
|
+
}
|
|
22602
|
+
if (c === "/" && text[i + 1] === "/") {
|
|
22603
|
+
const nl = text.indexOf("\n", i);
|
|
22604
|
+
const end = nl < 0 ? text.length : nl;
|
|
22605
|
+
addComment(i, end);
|
|
22606
|
+
i = end;
|
|
22607
|
+
continue;
|
|
22608
|
+
}
|
|
22609
|
+
if (c === "/" && text[i + 1] === "*") {
|
|
22610
|
+
const e = text.indexOf("*/", i + 2);
|
|
22611
|
+
const end = e < 0 ? text.length : e + 2;
|
|
22612
|
+
addComment(i, end);
|
|
22613
|
+
i = end;
|
|
22614
|
+
continue;
|
|
22615
|
+
}
|
|
22616
|
+
if (c === '"' || c === "'") {
|
|
22617
|
+
let j = i + 1;
|
|
22618
|
+
let v = "";
|
|
22619
|
+
while (j < text.length && text[j] !== c && text[j] !== "\n") {
|
|
22620
|
+
if (text[j] === "\\") {
|
|
22621
|
+
v += text[j + 1] ?? "";
|
|
22622
|
+
j += 2;
|
|
22623
|
+
continue;
|
|
22624
|
+
}
|
|
22625
|
+
v += text[j];
|
|
22626
|
+
j++;
|
|
22627
|
+
}
|
|
22628
|
+
toks.push({ t: "str", v, s: i });
|
|
22629
|
+
i = j + 1;
|
|
22630
|
+
continue;
|
|
22631
|
+
}
|
|
22632
|
+
if (c === "`") {
|
|
22633
|
+
let j = i + 1;
|
|
22634
|
+
let v = "";
|
|
22635
|
+
let interp = false;
|
|
22636
|
+
while (j < text.length && text[j] !== "`") {
|
|
22637
|
+
if (text[j] === "\\") {
|
|
22638
|
+
v += text[j + 1] ?? "";
|
|
22639
|
+
j += 2;
|
|
22640
|
+
continue;
|
|
22641
|
+
}
|
|
22642
|
+
if (text[j] === "$" && text[j + 1] === "{") {
|
|
22643
|
+
interp = true;
|
|
22644
|
+
let depth = 1;
|
|
22645
|
+
j += 2;
|
|
22646
|
+
while (j < text.length && depth > 0) {
|
|
22647
|
+
if (text[j] === "{") depth++;
|
|
22648
|
+
else if (text[j] === "}") depth--;
|
|
22649
|
+
else if (text[j] === "`") {
|
|
22650
|
+
j++;
|
|
22651
|
+
while (j < text.length && text[j] !== "`") j += text[j] === "\\" ? 2 : 1;
|
|
22652
|
+
}
|
|
22653
|
+
j++;
|
|
22654
|
+
}
|
|
22655
|
+
continue;
|
|
22656
|
+
}
|
|
22657
|
+
v += text[j];
|
|
22658
|
+
j++;
|
|
22659
|
+
}
|
|
22660
|
+
toks.push(interp ? { t: "tpl", v: "", s: i } : { t: "str", v, s: i });
|
|
22661
|
+
i = j + 1;
|
|
22662
|
+
continue;
|
|
22663
|
+
}
|
|
22664
|
+
if (c === "/" && regexAllowed()) {
|
|
22665
|
+
let j = i + 1;
|
|
22666
|
+
let inClass = false;
|
|
22667
|
+
while (j < text.length && text[j] !== "\n") {
|
|
22668
|
+
if (text[j] === "\\") {
|
|
22669
|
+
j += 2;
|
|
22670
|
+
continue;
|
|
22671
|
+
}
|
|
22672
|
+
if (text[j] === "[") inClass = true;
|
|
22673
|
+
else if (text[j] === "]") inClass = false;
|
|
22674
|
+
else if (text[j] === "/" && !inClass) break;
|
|
22675
|
+
j++;
|
|
22676
|
+
}
|
|
22677
|
+
j++;
|
|
22678
|
+
while (j < text.length && /[a-z]/i.test(text[j])) j++;
|
|
22679
|
+
toks.push({ t: "re", v: text.slice(i, j), s: i });
|
|
22680
|
+
i = j;
|
|
22681
|
+
continue;
|
|
22682
|
+
}
|
|
22683
|
+
if (/[A-Za-z_$]/.test(c)) {
|
|
22684
|
+
let j = i + 1;
|
|
22685
|
+
while (j < text.length && /[\w$]/.test(text[j])) j++;
|
|
22686
|
+
toks.push({ t: "id", v: text.slice(i, j), s: i });
|
|
22687
|
+
i = j;
|
|
22688
|
+
continue;
|
|
22689
|
+
}
|
|
22690
|
+
if (/[0-9]/.test(c) || c === "." && /[0-9]/.test(text[i + 1] ?? "")) {
|
|
22691
|
+
let j = i + 1;
|
|
22692
|
+
while (j < text.length && /[\w.]/.test(text[j])) j++;
|
|
22693
|
+
toks.push({ t: "num", v: text.slice(i, j), s: i });
|
|
22694
|
+
i = j;
|
|
22695
|
+
continue;
|
|
22696
|
+
}
|
|
22697
|
+
const three = text.slice(i, i + 3);
|
|
22698
|
+
const two = text.slice(i, i + 2);
|
|
22699
|
+
const p = PUNCT3.includes(three) ? three : PUNCT2.includes(two) ? two : c;
|
|
22700
|
+
toks.push({ t: "p", v: p, s: i });
|
|
22701
|
+
i += p.length;
|
|
22702
|
+
}
|
|
22703
|
+
nextBase += FILE_SPAN;
|
|
22704
|
+
const base = nextBase;
|
|
22705
|
+
for (const t of toks) t.s += base;
|
|
22706
|
+
fileByBase.set(base, file);
|
|
22707
|
+
const out = { text, toks, comments, lineStarts, base };
|
|
22708
|
+
lexCache.set(file, out);
|
|
22709
|
+
return out;
|
|
22710
|
+
}
|
|
22711
|
+
function lineOfOffset(lineStarts, off) {
|
|
22712
|
+
let lo = 0;
|
|
22713
|
+
let hi = lineStarts.length - 1;
|
|
22714
|
+
while (lo < hi) {
|
|
22715
|
+
const mid = lo + hi + 1 >> 1;
|
|
22716
|
+
if (lineStarts[mid] <= off) lo = mid;
|
|
22717
|
+
else hi = mid - 1;
|
|
22718
|
+
}
|
|
22719
|
+
return lo + 1;
|
|
22720
|
+
}
|
|
22721
|
+
var OPEN2 = { "(": ")", "[": "]", "{": "}" };
|
|
22722
|
+
var STOP = /* @__PURE__ */ new Set([",", ")", "]", "}", ";"]);
|
|
22723
|
+
var Parser = class _Parser {
|
|
22724
|
+
constructor(lx, i) {
|
|
22725
|
+
this.lx = lx;
|
|
22726
|
+
this.i = i;
|
|
22727
|
+
}
|
|
22728
|
+
lx;
|
|
22729
|
+
i;
|
|
22730
|
+
get toks() {
|
|
22731
|
+
return this.lx.toks;
|
|
22732
|
+
}
|
|
22733
|
+
peek(o = 0) {
|
|
22734
|
+
return this.toks[this.i + o];
|
|
22735
|
+
}
|
|
22736
|
+
isP(v, o = 0) {
|
|
22737
|
+
const t = this.peek(o);
|
|
22738
|
+
return t !== void 0 && t.t === "p" && t.v === v;
|
|
22739
|
+
}
|
|
22740
|
+
/** Index just past the bracket group opening at `i`. */
|
|
22741
|
+
skipGroup(i) {
|
|
22742
|
+
const open = this.toks[i];
|
|
22743
|
+
if (!open || open.t !== "p" || !OPEN2[open.v]) return i + 1;
|
|
22744
|
+
let depth = 0;
|
|
22745
|
+
for (let j = i; j < this.toks.length; j++) {
|
|
22746
|
+
const t = this.toks[j];
|
|
22747
|
+
if (t.t !== "p") continue;
|
|
22748
|
+
if (OPEN2[t.v]) depth++;
|
|
22749
|
+
else if (t.v === ")" || t.v === "]" || t.v === "}") {
|
|
22750
|
+
depth--;
|
|
22751
|
+
if (depth === 0) return j + 1;
|
|
22752
|
+
}
|
|
22753
|
+
}
|
|
22754
|
+
return this.toks.length;
|
|
22755
|
+
}
|
|
22756
|
+
/** Skip to the next top-level stop token (exclusive); returns whether every token was a string or `+`. */
|
|
22757
|
+
skipToStop() {
|
|
22758
|
+
let onlyStr = true;
|
|
22759
|
+
while (this.i < this.toks.length) {
|
|
22760
|
+
const t = this.toks[this.i];
|
|
22761
|
+
if (t.t === "p" && STOP.has(t.v)) break;
|
|
22762
|
+
if (t.t === "p" && OPEN2[t.v]) {
|
|
22763
|
+
onlyStr = false;
|
|
22764
|
+
this.i = this.skipGroup(this.i);
|
|
22765
|
+
continue;
|
|
22766
|
+
}
|
|
22767
|
+
if (!(t.t === "str" || t.t === "p" && t.v === "+")) onlyStr = false;
|
|
22768
|
+
this.i++;
|
|
22769
|
+
}
|
|
22770
|
+
return onlyStr;
|
|
22771
|
+
}
|
|
22772
|
+
/** Skip a type annotation (`as T`, `satisfies T`, `: T`): angle brackets nest. */
|
|
22773
|
+
skipType() {
|
|
22774
|
+
let angle = 0;
|
|
22775
|
+
while (this.i < this.toks.length) {
|
|
22776
|
+
const t = this.toks[this.i];
|
|
22777
|
+
if (t.t === "p") {
|
|
22778
|
+
if (t.v === "<") angle++;
|
|
22779
|
+
else if (t.v === ">" && angle > 0) angle--;
|
|
22780
|
+
else if (t.v === ">>" && angle > 0) angle = Math.max(0, angle - 2);
|
|
22781
|
+
else if (angle === 0 && (STOP.has(t.v) || t.v === "=" || t.v === "=>")) return;
|
|
22782
|
+
else if (OPEN2[t.v]) {
|
|
22783
|
+
this.i = this.skipGroup(this.i);
|
|
22784
|
+
continue;
|
|
22785
|
+
}
|
|
22786
|
+
}
|
|
22787
|
+
this.i++;
|
|
22788
|
+
}
|
|
22789
|
+
}
|
|
22790
|
+
/** Skip a type-parameter list `<T extends X<Y>, U = Z>` starting at the current `<`. */
|
|
22791
|
+
skipTypeParams() {
|
|
22792
|
+
let angle = 0;
|
|
22793
|
+
while (this.i < this.toks.length) {
|
|
22794
|
+
const t = this.toks[this.i];
|
|
22795
|
+
this.i++;
|
|
22796
|
+
if (t.t !== "p") continue;
|
|
22797
|
+
if (t.v === "<") angle++;
|
|
22798
|
+
else if (t.v === ">") angle--;
|
|
22799
|
+
else if (t.v === ">>") angle -= 2;
|
|
22800
|
+
if (angle <= 0) return;
|
|
22801
|
+
}
|
|
22802
|
+
}
|
|
22803
|
+
parseExpr() {
|
|
22804
|
+
const start = this.i;
|
|
22805
|
+
const s = this.peek()?.s ?? 0;
|
|
22806
|
+
const fn = this.tryArrow();
|
|
22807
|
+
if (fn) return fn;
|
|
22808
|
+
const node = this.parsePostfix();
|
|
22809
|
+
for (; ; ) {
|
|
22810
|
+
const t = this.peek();
|
|
22811
|
+
if (!t) return node;
|
|
22812
|
+
if (t.t === "id" && (t.v === "as" || t.v === "satisfies")) {
|
|
22813
|
+
this.i++;
|
|
22814
|
+
this.skipType();
|
|
22815
|
+
continue;
|
|
22816
|
+
}
|
|
22817
|
+
if (t.t === "p" && t.v === "!" && !this.isP("=", 1)) {
|
|
22818
|
+
this.i++;
|
|
22819
|
+
continue;
|
|
22820
|
+
}
|
|
22821
|
+
if (t.t === "p" && STOP.has(t.v)) return node;
|
|
22822
|
+
if (t.t === "p" && t.v === ":") return node;
|
|
22823
|
+
this.i = start;
|
|
22824
|
+
const onlyStr = this.skipToStop();
|
|
22825
|
+
return { k: "other", form: this.sliceText(start), strConcat: onlyStr, s };
|
|
22826
|
+
}
|
|
22827
|
+
}
|
|
22828
|
+
sliceText(fromTok) {
|
|
22829
|
+
const a = this.toks[fromTok]?.s ?? 0;
|
|
22830
|
+
const lastTok = this.toks[this.i - 1];
|
|
22831
|
+
const b = lastTok ? lastTok.s + Math.max(lastTok.v.length, 1) : a;
|
|
22832
|
+
const raw = this.lx.text.slice(a - this.lx.base, b - this.lx.base).replace(/\s+/g, " ").trim();
|
|
22833
|
+
return raw.length > 60 ? `${raw.slice(0, 57)}...` : raw;
|
|
22834
|
+
}
|
|
22835
|
+
tryArrow() {
|
|
22836
|
+
const start = this.i;
|
|
22837
|
+
const s = this.peek()?.s ?? 0;
|
|
22838
|
+
if (this.peek()?.t === "id" && this.peek()?.v === "async") this.i++;
|
|
22839
|
+
let params = null;
|
|
22840
|
+
if (this.isP("<")) this.skipTypeParams();
|
|
22841
|
+
const t = this.peek();
|
|
22842
|
+
if (t?.t === "id" && this.isP("=>", 1)) {
|
|
22843
|
+
params = [t.v];
|
|
22844
|
+
this.i += 1;
|
|
22845
|
+
} else if (t?.t === "p" && t.v === "(") {
|
|
22846
|
+
const end = this.skipGroup(this.i);
|
|
22847
|
+
let j = end;
|
|
22848
|
+
if (this.toks[j]?.t === "p" && this.toks[j]?.v === ":") {
|
|
22849
|
+
const save = this.i;
|
|
22850
|
+
this.i = j + 1;
|
|
22851
|
+
this.skipType();
|
|
22852
|
+
j = this.i;
|
|
22853
|
+
this.i = save;
|
|
22854
|
+
}
|
|
22855
|
+
if (this.toks[j]?.t === "p" && this.toks[j]?.v === "=>") {
|
|
22856
|
+
params = this.paramNames(this.i + 1, end - 1);
|
|
22857
|
+
this.i = j;
|
|
22858
|
+
}
|
|
22859
|
+
} else if (t?.t === "id" && t.v === "function") {
|
|
22860
|
+
this.i++;
|
|
22861
|
+
if (this.peek()?.t === "id") this.i++;
|
|
22862
|
+
if (this.isP("<")) this.skipTypeParams();
|
|
22863
|
+
if (!this.isP("(")) {
|
|
22864
|
+
this.i = start;
|
|
22865
|
+
return null;
|
|
22866
|
+
}
|
|
22867
|
+
const end = this.skipGroup(this.i);
|
|
22868
|
+
const ps = this.paramNames(this.i + 1, end - 1);
|
|
22869
|
+
this.i = end;
|
|
22870
|
+
if (this.isP(":")) {
|
|
22871
|
+
this.i++;
|
|
22872
|
+
this.skipType();
|
|
22873
|
+
}
|
|
22874
|
+
return { k: "fn", params: ps, body: this.isP("{") ? this.blockReturn() : null, s };
|
|
22875
|
+
}
|
|
22876
|
+
if (params === null) {
|
|
22877
|
+
this.i = start;
|
|
22878
|
+
return null;
|
|
22879
|
+
}
|
|
22880
|
+
this.i++;
|
|
22881
|
+
if (this.isP("{")) return { k: "fn", params, body: this.blockReturn(), s };
|
|
22882
|
+
return { k: "fn", params, body: this.parseExpr(), s };
|
|
22883
|
+
}
|
|
22884
|
+
/** The expression of the single top-level `return` of a block at `{`, or null; consumes the block. */
|
|
22885
|
+
blockReturn() {
|
|
22886
|
+
const open = this.i;
|
|
22887
|
+
const end = this.skipGroup(open);
|
|
22888
|
+
const returns = [];
|
|
22889
|
+
let depth = 0;
|
|
22890
|
+
for (let j = open; j < end; j++) {
|
|
22891
|
+
const t = this.toks[j];
|
|
22892
|
+
if (t.t === "p" && OPEN2[t.v]) depth++;
|
|
22893
|
+
else if (t.t === "p" && (t.v === ")" || t.v === "]" || t.v === "}")) depth--;
|
|
22894
|
+
else if (t.t === "id" && t.v === "return" && depth === 1) returns.push(j);
|
|
22895
|
+
}
|
|
22896
|
+
this.i = end;
|
|
22897
|
+
if (returns.length !== 1) return null;
|
|
22898
|
+
const sub = new _Parser(this.lx, returns[0] + 1);
|
|
22899
|
+
return sub.parseExpr();
|
|
22900
|
+
}
|
|
22901
|
+
paramNames(from, to) {
|
|
22902
|
+
const names = [];
|
|
22903
|
+
let depth = 0;
|
|
22904
|
+
let expectName = true;
|
|
22905
|
+
for (let j = from; j < to; j++) {
|
|
22906
|
+
const t = this.toks[j];
|
|
22907
|
+
if (t.t === "p" && OPEN2[t.v]) depth++;
|
|
22908
|
+
else if (t.t === "p" && (t.v === ")" || t.v === "]" || t.v === "}")) depth--;
|
|
22909
|
+
if (depth === 0 && t.t === "p" && t.v === ",") {
|
|
22910
|
+
expectName = true;
|
|
22911
|
+
continue;
|
|
22912
|
+
}
|
|
22913
|
+
if (depth === 0 && expectName && t.t === "id") {
|
|
22914
|
+
names.push(t.v);
|
|
22915
|
+
expectName = false;
|
|
22916
|
+
}
|
|
22917
|
+
}
|
|
22918
|
+
return names;
|
|
22919
|
+
}
|
|
22920
|
+
parsePostfix() {
|
|
22921
|
+
let node = this.parsePrimary();
|
|
22922
|
+
for (; ; ) {
|
|
22923
|
+
if (this.isP(".") || this.isP("?.")) {
|
|
22924
|
+
const nt = this.peek(1);
|
|
22925
|
+
if (nt?.t === "id") {
|
|
22926
|
+
this.i += 2;
|
|
22927
|
+
node = { k: "member", obj: node, prop: nt.v, s: node.s };
|
|
22928
|
+
continue;
|
|
22929
|
+
}
|
|
22930
|
+
if (this.isP("?.") && (this.isP("(", 1) || this.isP("[", 1))) {
|
|
22931
|
+
this.i++;
|
|
22932
|
+
continue;
|
|
22933
|
+
}
|
|
22934
|
+
return node;
|
|
22935
|
+
}
|
|
22936
|
+
if (this.isP("(")) {
|
|
22937
|
+
node = { k: "call", callee: node, args: this.parseList(")"), s: node.s };
|
|
22938
|
+
continue;
|
|
22939
|
+
}
|
|
22940
|
+
if (this.isP("[")) {
|
|
22941
|
+
const end = this.skipGroup(this.i);
|
|
22942
|
+
this.i = end;
|
|
22943
|
+
node = { k: "member", obj: node, prop: "[computed]", s: node.s };
|
|
22944
|
+
continue;
|
|
22945
|
+
}
|
|
22946
|
+
if (this.isP("<") && node.k === "member") {
|
|
22947
|
+
const save = this.i;
|
|
22948
|
+
this.i++;
|
|
22949
|
+
this.skipType();
|
|
22950
|
+
if (this.isP(">")) {
|
|
22951
|
+
this.i++;
|
|
22952
|
+
if (this.isP("(")) continue;
|
|
22953
|
+
}
|
|
22954
|
+
this.i = save;
|
|
22955
|
+
return node;
|
|
22956
|
+
}
|
|
22957
|
+
return node;
|
|
22958
|
+
}
|
|
22959
|
+
}
|
|
22960
|
+
/** Comma-separated expressions inside the group opening at the current token. */
|
|
22961
|
+
parseList(close) {
|
|
22962
|
+
const end = this.skipGroup(this.i);
|
|
22963
|
+
this.i++;
|
|
22964
|
+
const out = [];
|
|
22965
|
+
while (this.i < end - 1) {
|
|
22966
|
+
if (this.isP(",")) {
|
|
22967
|
+
this.i++;
|
|
22968
|
+
continue;
|
|
22969
|
+
}
|
|
22970
|
+
if (this.isP(close)) break;
|
|
22971
|
+
if (this.isP("...")) {
|
|
22972
|
+
const s = this.peek()?.s ?? 0;
|
|
22973
|
+
this.i++;
|
|
22974
|
+
const inner = this.parseExpr();
|
|
22975
|
+
out.push({ k: "other", form: `...${describeNode(inner)}`, strConcat: false, s });
|
|
22976
|
+
} else {
|
|
22977
|
+
const before = this.i;
|
|
22978
|
+
out.push(this.parseExpr());
|
|
22979
|
+
if (this.i === before) this.i++;
|
|
22980
|
+
}
|
|
22981
|
+
while (this.i < end - 1 && !this.isP(",")) this.i++;
|
|
22982
|
+
}
|
|
22983
|
+
this.i = end;
|
|
22984
|
+
return out;
|
|
22985
|
+
}
|
|
22986
|
+
parsePrimary() {
|
|
22987
|
+
const t = this.peek();
|
|
22988
|
+
if (!t) return { k: "other", form: "end of file", strConcat: false, s: 0 };
|
|
22989
|
+
const s = t.s;
|
|
22990
|
+
if (t.t === "str") {
|
|
22991
|
+
this.i++;
|
|
22992
|
+
return { k: "lit", v: t.v, s };
|
|
22993
|
+
}
|
|
22994
|
+
if (t.t === "num") {
|
|
22995
|
+
this.i++;
|
|
22996
|
+
return { k: "lit", v: Number(t.v), s };
|
|
22997
|
+
}
|
|
22998
|
+
if (t.t === "tpl") {
|
|
22999
|
+
this.i++;
|
|
23000
|
+
return { k: "other", form: "template literal with interpolation", strConcat: false, s };
|
|
23001
|
+
}
|
|
23002
|
+
if (t.t === "re") {
|
|
23003
|
+
this.i++;
|
|
23004
|
+
return { k: "other", form: "regular expression", strConcat: false, s };
|
|
23005
|
+
}
|
|
23006
|
+
if (t.t === "id") {
|
|
23007
|
+
this.i++;
|
|
23008
|
+
if (t.v === "true" || t.v === "false") return { k: "lit", v: t.v === "true", s };
|
|
23009
|
+
if (t.v === "null" || t.v === "undefined") return { k: "lit", v: null, s };
|
|
23010
|
+
if (t.v === "new") {
|
|
23011
|
+
this.parsePostfix();
|
|
23012
|
+
return { k: "other", form: "new expression", strConcat: false, s };
|
|
23013
|
+
}
|
|
23014
|
+
return { k: "id", name: t.v, s };
|
|
23015
|
+
}
|
|
23016
|
+
if (t.v === "(") {
|
|
23017
|
+
const end = this.skipGroup(this.i);
|
|
23018
|
+
this.i++;
|
|
23019
|
+
const inner = this.parseExpr();
|
|
23020
|
+
this.i = end;
|
|
23021
|
+
return inner;
|
|
23022
|
+
}
|
|
23023
|
+
if (t.v === "[") {
|
|
23024
|
+
return { k: "arr", items: this.parseList("]"), s };
|
|
23025
|
+
}
|
|
23026
|
+
if (t.v === "{") return this.parseObject();
|
|
23027
|
+
if (t.v === "-" && this.peek(1)?.t === "num") {
|
|
23028
|
+
this.i += 2;
|
|
23029
|
+
return { k: "lit", v: -Number(this.toks[this.i - 1].v), s };
|
|
23030
|
+
}
|
|
23031
|
+
this.i++;
|
|
23032
|
+
return { k: "other", form: `token ${t.v}`, strConcat: false, s };
|
|
23033
|
+
}
|
|
23034
|
+
parseObject() {
|
|
23035
|
+
const s = this.peek()?.s ?? 0;
|
|
23036
|
+
const end = this.skipGroup(this.i);
|
|
23037
|
+
this.i++;
|
|
23038
|
+
const entries = [];
|
|
23039
|
+
while (this.i < end - 1) {
|
|
23040
|
+
const t = this.peek();
|
|
23041
|
+
if (!t) break;
|
|
23042
|
+
if (t.t === "p" && t.v === ",") {
|
|
23043
|
+
this.i++;
|
|
23044
|
+
continue;
|
|
23045
|
+
}
|
|
23046
|
+
if (t.t === "p" && t.v === "...") {
|
|
23047
|
+
this.i++;
|
|
23048
|
+
entries.push({ kind: "spread", value: this.parseExpr(), s: t.s });
|
|
23049
|
+
} else if (t.t === "p" && t.v === "[") {
|
|
23050
|
+
this.i = this.skipGroup(this.i);
|
|
23051
|
+
entries.push({ kind: "unread", form: "computed key", s: t.s });
|
|
23052
|
+
if (this.isP(":")) {
|
|
23053
|
+
this.i++;
|
|
23054
|
+
this.parseExpr();
|
|
23055
|
+
}
|
|
23056
|
+
} else if (t.t === "id" || t.t === "str" || t.t === "num") {
|
|
23057
|
+
let key = t.v;
|
|
23058
|
+
let at = this.i;
|
|
23059
|
+
if (t.t === "id" && (t.v === "get" || t.v === "set" || t.v === "async") && (this.peek(1)?.t === "id" || this.peek(1)?.t === "str")) {
|
|
23060
|
+
at = this.i + 1;
|
|
23061
|
+
key = this.toks[at].v;
|
|
23062
|
+
}
|
|
23063
|
+
this.i = at + 1;
|
|
23064
|
+
if (this.isP("?")) this.i++;
|
|
23065
|
+
if (this.isP(":")) {
|
|
23066
|
+
this.i++;
|
|
23067
|
+
entries.push({ kind: "prop", key, value: this.parseExpr(), s: t.s });
|
|
23068
|
+
} else if (this.isP("(")) {
|
|
23069
|
+
this.i = this.skipGroup(this.i);
|
|
23070
|
+
if (this.isP(":")) {
|
|
23071
|
+
this.i++;
|
|
23072
|
+
this.skipType();
|
|
23073
|
+
}
|
|
23074
|
+
if (this.isP("{")) this.i = this.skipGroup(this.i);
|
|
23075
|
+
entries.push({
|
|
23076
|
+
kind: "prop",
|
|
23077
|
+
key,
|
|
23078
|
+
value: { k: "fn", params: [], body: null, s: t.s },
|
|
23079
|
+
s: t.s
|
|
23080
|
+
});
|
|
23081
|
+
} else {
|
|
23082
|
+
entries.push({ kind: "prop", key, value: { k: "id", name: key, s: t.s }, s: t.s });
|
|
23083
|
+
}
|
|
23084
|
+
} else {
|
|
23085
|
+
this.i++;
|
|
23086
|
+
}
|
|
23087
|
+
while (this.i < end - 1 && !this.isP(",")) this.i++;
|
|
23088
|
+
}
|
|
23089
|
+
this.i = end;
|
|
23090
|
+
return { k: "obj", entries, s };
|
|
23091
|
+
}
|
|
23092
|
+
};
|
|
23093
|
+
function describeNode(n) {
|
|
23094
|
+
switch (n.k) {
|
|
23095
|
+
case "id":
|
|
23096
|
+
return n.name;
|
|
23097
|
+
case "lit":
|
|
23098
|
+
return JSON.stringify(n.v);
|
|
23099
|
+
case "member":
|
|
23100
|
+
return `${describeNode(n.obj)}.${n.prop}`;
|
|
23101
|
+
case "call":
|
|
23102
|
+
return `${describeNode(n.callee)}(...)`;
|
|
23103
|
+
case "obj":
|
|
23104
|
+
return "{...}";
|
|
23105
|
+
case "arr":
|
|
23106
|
+
return "[...]";
|
|
23107
|
+
case "fn":
|
|
23108
|
+
return "function";
|
|
23109
|
+
case "other":
|
|
23110
|
+
return n.form;
|
|
23111
|
+
}
|
|
23112
|
+
}
|
|
23113
|
+
var bindingCache = /* @__PURE__ */ new WeakMap();
|
|
23114
|
+
function bracePairs(toks, open) {
|
|
23115
|
+
const pairs = [];
|
|
23116
|
+
let j = open + 1;
|
|
23117
|
+
while (j < toks.length && toks[j].v !== "}") {
|
|
23118
|
+
const tk = toks[j];
|
|
23119
|
+
if (tk.t === "id" && tk.v === "type" && toks[j + 1]?.t === "id" && toks[j + 1].v !== "as") {
|
|
23120
|
+
j++;
|
|
23121
|
+
continue;
|
|
23122
|
+
}
|
|
23123
|
+
if (tk.t === "id" || tk.t === "str") {
|
|
23124
|
+
if (toks[j + 1]?.v === "as" && toks[j + 2]) {
|
|
23125
|
+
pairs.push([tk.v, toks[j + 2].v]);
|
|
23126
|
+
j += 3;
|
|
23127
|
+
continue;
|
|
23128
|
+
}
|
|
23129
|
+
pairs.push([tk.v, tk.v]);
|
|
23130
|
+
}
|
|
23131
|
+
j++;
|
|
23132
|
+
}
|
|
23133
|
+
return { pairs, end: j };
|
|
23134
|
+
}
|
|
23135
|
+
function bindingsOf(file) {
|
|
23136
|
+
const cached = bindingCache.get(file);
|
|
23137
|
+
if (cached) return cached;
|
|
23138
|
+
const lx = lex(file);
|
|
23139
|
+
const toks = lx.toks;
|
|
23140
|
+
const decls = /* @__PURE__ */ new Map();
|
|
23141
|
+
const imports = /* @__PURE__ */ new Map();
|
|
23142
|
+
const reexports = [];
|
|
23143
|
+
const zod = /* @__PURE__ */ new Set();
|
|
23144
|
+
const add = (name, node) => decls.set(name, [...decls.get(name) ?? [], node]);
|
|
23145
|
+
const fromAfter = (j) => toks[j]?.t === "id" && toks[j].v === "from" && toks[j + 1]?.t === "str" ? toks[j + 1].v : null;
|
|
23146
|
+
for (let i = 0; i < toks.length; i++) {
|
|
23147
|
+
const t = toks[i];
|
|
23148
|
+
if (t.t !== "id") continue;
|
|
23149
|
+
const memberAccess = i > 0 && (toks[i - 1].v === "." || toks[i - 1].v === "?.");
|
|
23150
|
+
if (t.v === "import" && !memberAccess && toks[i + 1]?.v !== "(") {
|
|
23151
|
+
let j = i + 1;
|
|
23152
|
+
if (toks[j]?.v === "type") j++;
|
|
23153
|
+
const local = [];
|
|
23154
|
+
if (toks[j]?.t === "id" && toks[j].v !== "from") {
|
|
23155
|
+
local.push(["default", toks[j].v]);
|
|
23156
|
+
j++;
|
|
23157
|
+
if (toks[j]?.v === ",") j++;
|
|
23158
|
+
}
|
|
23159
|
+
if (toks[j]?.v === "{") {
|
|
23160
|
+
const bp = bracePairs(toks, j);
|
|
23161
|
+
local.push(...bp.pairs);
|
|
23162
|
+
j = bp.end + 1;
|
|
23163
|
+
} else if (toks[j]?.v === "*" && toks[j + 1]?.v === "as" && toks[j + 2]?.t === "id") {
|
|
23164
|
+
local.push(["*", toks[j + 2].v]);
|
|
23165
|
+
j += 3;
|
|
23166
|
+
}
|
|
23167
|
+
const mod = fromAfter(j);
|
|
23168
|
+
if (mod !== null) {
|
|
23169
|
+
for (const [orig, name] of local) {
|
|
23170
|
+
imports.set(name, { mod, orig });
|
|
23171
|
+
if (/^zod(\/|$)/.test(mod)) zod.add(name);
|
|
23172
|
+
}
|
|
23173
|
+
}
|
|
23174
|
+
continue;
|
|
23175
|
+
}
|
|
23176
|
+
if (t.v === "export" && !memberAccess) {
|
|
23177
|
+
let j = i + 1;
|
|
23178
|
+
if (toks[j]?.v === "type") j++;
|
|
23179
|
+
if (toks[j]?.v === "{") {
|
|
23180
|
+
const bp = bracePairs(toks, j);
|
|
23181
|
+
const mod = fromAfter(bp.end + 1);
|
|
23182
|
+
if (mod !== null)
|
|
23183
|
+
for (const [orig, exported] of bp.pairs) reexports.push({ mod, exported, orig });
|
|
23184
|
+
} else if (toks[j]?.v === "*" && toks[j + 1]?.v !== "as") {
|
|
23185
|
+
const mod = fromAfter(j + 1);
|
|
23186
|
+
if (mod !== null) reexports.push({ mod, exported: null, orig: null });
|
|
23187
|
+
}
|
|
23188
|
+
continue;
|
|
23189
|
+
}
|
|
23190
|
+
if ((t.v === "const" || t.v === "let" || t.v === "var") && toks[i + 1]?.t === "id") {
|
|
23191
|
+
const name = toks[i + 1].v;
|
|
23192
|
+
const p = new Parser(lx, i + 2);
|
|
23193
|
+
if (p.isP(":")) {
|
|
23194
|
+
p.i++;
|
|
23195
|
+
p.skipType();
|
|
23196
|
+
}
|
|
23197
|
+
if (p.isP("=")) {
|
|
23198
|
+
p.i++;
|
|
23199
|
+
add(name, p.parseExpr());
|
|
23200
|
+
}
|
|
23201
|
+
continue;
|
|
23202
|
+
}
|
|
23203
|
+
if (t.v === "function" && toks[i + 1]?.t === "id" && !memberAccess) {
|
|
23204
|
+
const name = toks[i + 1].v;
|
|
23205
|
+
const p = new Parser(lx, i);
|
|
23206
|
+
add(name, p.parseExpr());
|
|
23207
|
+
}
|
|
23208
|
+
}
|
|
23209
|
+
const out = { decls, imports, reexports, zod };
|
|
23210
|
+
bindingCache.set(file, out);
|
|
23211
|
+
return out;
|
|
23212
|
+
}
|
|
23213
|
+
var unread = (form, at) => ({
|
|
23214
|
+
k: "unread",
|
|
23215
|
+
form,
|
|
23216
|
+
at
|
|
23217
|
+
});
|
|
23218
|
+
var SCALAR = { k: "scalar", name: "scalar" };
|
|
23219
|
+
var SCALAR_FACTORIES = /* @__PURE__ */ new Set([
|
|
23220
|
+
// string formats
|
|
23221
|
+
"string",
|
|
23222
|
+
"email",
|
|
23223
|
+
"guid",
|
|
23224
|
+
"uuid",
|
|
23225
|
+
"uuidv4",
|
|
23226
|
+
"uuidv6",
|
|
23227
|
+
"uuidv7",
|
|
23228
|
+
"url",
|
|
23229
|
+
"httpUrl",
|
|
23230
|
+
"emoji",
|
|
23231
|
+
"nanoid",
|
|
23232
|
+
"cuid",
|
|
23233
|
+
"cuid2",
|
|
23234
|
+
"ulid",
|
|
23235
|
+
"xid",
|
|
23236
|
+
"ksuid",
|
|
23237
|
+
"ipv4",
|
|
23238
|
+
"mac",
|
|
23239
|
+
"ipv6",
|
|
23240
|
+
"cidrv4",
|
|
23241
|
+
"cidrv6",
|
|
23242
|
+
"base64",
|
|
23243
|
+
"base64url",
|
|
23244
|
+
"e164",
|
|
23245
|
+
"creditCard",
|
|
23246
|
+
"iban",
|
|
23247
|
+
"jwt",
|
|
23248
|
+
"stringFormat",
|
|
23249
|
+
"hostname",
|
|
23250
|
+
"hex",
|
|
23251
|
+
"currencyCode",
|
|
23252
|
+
"hash",
|
|
23253
|
+
// number / bigint formats
|
|
23254
|
+
"number",
|
|
23255
|
+
"int",
|
|
23256
|
+
"float32",
|
|
23257
|
+
"float64",
|
|
23258
|
+
"int32",
|
|
23259
|
+
"uint32",
|
|
23260
|
+
"bigint",
|
|
23261
|
+
"int64",
|
|
23262
|
+
"uint64",
|
|
23263
|
+
// other scalars
|
|
23264
|
+
"boolean",
|
|
23265
|
+
"symbol",
|
|
23266
|
+
"date",
|
|
23267
|
+
"nan",
|
|
23268
|
+
"file",
|
|
23269
|
+
"literal",
|
|
23270
|
+
"enum",
|
|
23271
|
+
"nativeEnum",
|
|
23272
|
+
"keyof",
|
|
23273
|
+
"templateLiteral",
|
|
23274
|
+
"stringbool"
|
|
23275
|
+
]);
|
|
23276
|
+
var ISO_FACTORIES = /* @__PURE__ */ new Set(["datetime", "date", "time", "duration"]);
|
|
23277
|
+
var COERCE_FACTORIES = /* @__PURE__ */ new Set(["string", "number", "boolean", "bigint", "date"]);
|
|
23278
|
+
var ANY_FACTORIES = /* @__PURE__ */ new Set(["any", "unknown", "custom", "instanceof", "json"]);
|
|
23279
|
+
var NULL_FACTORIES = /* @__PURE__ */ new Set(["null", "undefined", "void", "never"]);
|
|
23280
|
+
var IDENTITY_METHODS = /* @__PURE__ */ new Set([
|
|
23281
|
+
"optional",
|
|
23282
|
+
"exactOptional",
|
|
23283
|
+
"nonoptional",
|
|
23284
|
+
"describe",
|
|
23285
|
+
"default",
|
|
23286
|
+
"prefault",
|
|
23287
|
+
"catch",
|
|
23288
|
+
"min",
|
|
23289
|
+
"max",
|
|
23290
|
+
"length",
|
|
23291
|
+
"size",
|
|
23292
|
+
"nonempty",
|
|
23293
|
+
"regex",
|
|
23294
|
+
"int",
|
|
23295
|
+
"positive",
|
|
23296
|
+
"negative",
|
|
23297
|
+
"nonnegative",
|
|
23298
|
+
"nonpositive",
|
|
23299
|
+
"finite",
|
|
23300
|
+
"safe",
|
|
23301
|
+
"multipleOf",
|
|
23302
|
+
"step",
|
|
23303
|
+
"gt",
|
|
23304
|
+
"gte",
|
|
23305
|
+
"lt",
|
|
23306
|
+
"lte",
|
|
23307
|
+
"email",
|
|
23308
|
+
"url",
|
|
23309
|
+
"uuid",
|
|
23310
|
+
"cuid",
|
|
23311
|
+
"cuid2",
|
|
23312
|
+
"ulid",
|
|
23313
|
+
"nanoid",
|
|
23314
|
+
"emoji",
|
|
23315
|
+
"base64",
|
|
23316
|
+
"jwt",
|
|
23317
|
+
"ip",
|
|
23318
|
+
"cidr",
|
|
23319
|
+
"trim",
|
|
23320
|
+
"toLowerCase",
|
|
23321
|
+
"toUpperCase",
|
|
23322
|
+
"lowercase",
|
|
23323
|
+
"uppercase",
|
|
23324
|
+
"normalize",
|
|
23325
|
+
"startsWith",
|
|
23326
|
+
"endsWith",
|
|
23327
|
+
"includes",
|
|
23328
|
+
"datetime",
|
|
23329
|
+
"date",
|
|
23330
|
+
"time",
|
|
23331
|
+
"duration",
|
|
23332
|
+
"refine",
|
|
23333
|
+
"superRefine",
|
|
23334
|
+
"check",
|
|
23335
|
+
"transform",
|
|
23336
|
+
"overwrite",
|
|
23337
|
+
"brand",
|
|
23338
|
+
"readonly",
|
|
23339
|
+
"meta",
|
|
23340
|
+
"register",
|
|
23341
|
+
"strict",
|
|
23342
|
+
"strictObject",
|
|
23343
|
+
"passthrough",
|
|
23344
|
+
"loose",
|
|
23345
|
+
"strip",
|
|
23346
|
+
"nonstrict",
|
|
23347
|
+
"catchall",
|
|
23348
|
+
"partial",
|
|
23349
|
+
"required",
|
|
23350
|
+
"deepPartial",
|
|
23351
|
+
"pipe"
|
|
23352
|
+
]);
|
|
23353
|
+
function moduleCtx(file, tree, from) {
|
|
23354
|
+
return {
|
|
23355
|
+
file,
|
|
23356
|
+
b: bindingsOf(file),
|
|
23357
|
+
tree,
|
|
23358
|
+
params: /* @__PURE__ */ new Map(),
|
|
23359
|
+
depth: from ? from.depth + 1 : 0,
|
|
23360
|
+
resolving: from ? from.resolving : /* @__PURE__ */ new Set()
|
|
23361
|
+
};
|
|
23362
|
+
}
|
|
23363
|
+
function flatten(branches) {
|
|
23364
|
+
const out = [];
|
|
23365
|
+
for (const b of branches) {
|
|
23366
|
+
if (b.k === "union") out.push(...flatten(b.branches));
|
|
23367
|
+
else out.push(b);
|
|
23368
|
+
}
|
|
23369
|
+
return out;
|
|
23370
|
+
}
|
|
23371
|
+
function nullable(s, at) {
|
|
23372
|
+
return { k: "union", branches: [s, { k: "null" }], at };
|
|
23373
|
+
}
|
|
23374
|
+
var isUnread = (r) => "k" in r && r.k === "unread";
|
|
23375
|
+
function resolveModule(tree, from, spec) {
|
|
23376
|
+
const dir = from.path.slice(0, from.path.lastIndexOf("/"));
|
|
23377
|
+
const parts = `${dir}/${spec}`.split("/");
|
|
23378
|
+
const out = [];
|
|
23379
|
+
for (const p of parts) {
|
|
23380
|
+
if (p === "..") out.pop();
|
|
23381
|
+
else if (p !== ".") out.push(p);
|
|
23382
|
+
}
|
|
23383
|
+
const base = out.join("/");
|
|
23384
|
+
const stem = base.replace(/\.(?:m|c)?js$/, "").replace(/\.jsx$/, "");
|
|
23385
|
+
const candidates = [
|
|
23386
|
+
base,
|
|
23387
|
+
`${stem}.ts`,
|
|
23388
|
+
`${stem}.tsx`,
|
|
23389
|
+
`${stem}.mts`,
|
|
23390
|
+
`${stem}.cts`,
|
|
23391
|
+
`${stem}/index.ts`,
|
|
23392
|
+
`${stem}/index.tsx`
|
|
23393
|
+
];
|
|
23394
|
+
for (const c of candidates) {
|
|
23395
|
+
const f = tree.files.find((x) => x.path === c);
|
|
23396
|
+
if (f) return f;
|
|
23397
|
+
}
|
|
23398
|
+
return null;
|
|
23399
|
+
}
|
|
23400
|
+
function resolveExport(file, name, at, ctx, chain) {
|
|
23401
|
+
const key = `${file.path}#${name}`;
|
|
23402
|
+
if (chain.includes(key))
|
|
23403
|
+
return unread(
|
|
23404
|
+
`import cycle: ${[...chain, key].map((k) => k.slice(k.lastIndexOf("/") + 1)).join(" -> ")}`,
|
|
23405
|
+
at
|
|
23406
|
+
);
|
|
23407
|
+
const b = bindingsOf(file);
|
|
23408
|
+
const decls = b.decls.get(name);
|
|
23409
|
+
if (decls && decls.length === 1) return { node: decls[0], ctx: moduleCtx(file, ctx.tree, ctx) };
|
|
23410
|
+
if (decls && decls.length > 1)
|
|
23411
|
+
return unread(`identifier ${name} declared ${decls.length} times in ${file.rel}`, at);
|
|
23412
|
+
const imp = b.imports.get(name);
|
|
23413
|
+
const viaChain = [...chain, key];
|
|
23414
|
+
if (imp) return followImport(file, name, imp, at, ctx, viaChain);
|
|
23415
|
+
const named = b.reexports.find((r) => r.exported === name);
|
|
23416
|
+
if (named)
|
|
23417
|
+
return followImport(
|
|
23418
|
+
file,
|
|
23419
|
+
name,
|
|
23420
|
+
{ mod: named.mod, orig: named.orig ?? name },
|
|
23421
|
+
at,
|
|
23422
|
+
ctx,
|
|
23423
|
+
viaChain
|
|
23424
|
+
);
|
|
23425
|
+
for (const star of b.reexports.filter((r) => r.exported === null)) {
|
|
23426
|
+
const r = followImport(file, name, { mod: star.mod, orig: name }, at, ctx, viaChain);
|
|
23427
|
+
if (!isUnread(r) || /cycle/.test(r.form)) return r;
|
|
23428
|
+
}
|
|
23429
|
+
return unread(`identifier ${name} not exported by ${file.rel}`, at);
|
|
23430
|
+
}
|
|
23431
|
+
function followImport(file, name, imp, at, ctx, chain) {
|
|
23432
|
+
if (!imp.mod.startsWith("."))
|
|
23433
|
+
return unread(`identifier ${name} imported from package "${imp.mod}"`, at);
|
|
23434
|
+
if (imp.orig === "*")
|
|
23435
|
+
return unread(`namespace import ${name} from "${imp.mod}" (not followed)`, at);
|
|
23436
|
+
if (imp.orig === "default")
|
|
23437
|
+
return unread(`default import ${name} from "${imp.mod}" (not followed)`, at);
|
|
23438
|
+
const target = ctx.tree ? resolveModule(ctx.tree, file, imp.mod) : null;
|
|
23439
|
+
if (!target)
|
|
23440
|
+
return unread(
|
|
23441
|
+
`identifier ${name} imported from "${imp.mod}": the module is not in the scanned tree`,
|
|
23442
|
+
at
|
|
23443
|
+
);
|
|
23444
|
+
return resolveExport(target, imp.orig, at, ctx, chain);
|
|
23445
|
+
}
|
|
23446
|
+
function resolveRef(name, at, ctx) {
|
|
23447
|
+
if (ctx.params.has(name)) {
|
|
23448
|
+
const bound = ctx.params.get(name);
|
|
23449
|
+
if (!bound) return unread(`parameter ${name} (no argument at the call site)`, at);
|
|
23450
|
+
return {
|
|
23451
|
+
node: bound.node,
|
|
23452
|
+
ctx: { ...bound.ctx, depth: ctx.depth + 1, resolving: ctx.resolving }
|
|
23453
|
+
};
|
|
23454
|
+
}
|
|
23455
|
+
return resolveExport(ctx.file, name, at, ctx, []);
|
|
23456
|
+
}
|
|
23457
|
+
function isZodRoot(n, ctx) {
|
|
23458
|
+
return n.k === "id" && ctx.b.zod.has(n.name) && !ctx.params.has(n.name) && !ctx.b.decls.has(n.name);
|
|
23459
|
+
}
|
|
23460
|
+
function evalZod(n, ctx) {
|
|
23461
|
+
if (ctx.depth > 40) return unread("schema nested deeper than 40 resolutions", n.s);
|
|
23462
|
+
const sub = { ...ctx, depth: ctx.depth + 1 };
|
|
23463
|
+
switch (n.k) {
|
|
23464
|
+
case "obj":
|
|
23465
|
+
return evalShape(n, sub);
|
|
23466
|
+
case "id": {
|
|
23467
|
+
const r = resolveRef(n.name, n.s, ctx);
|
|
23468
|
+
if (isUnread(r)) return r;
|
|
23469
|
+
const key = `${r.ctx.file.path}#${describeNode(r.node)}@${r.node.s}`;
|
|
23470
|
+
if (ctx.resolving.has(key)) return unread(`identifier cycle through ${n.name}`, n.s);
|
|
23471
|
+
return evalZod(r.node, {
|
|
23472
|
+
...r.ctx,
|
|
23473
|
+
depth: ctx.depth + 1,
|
|
23474
|
+
resolving: /* @__PURE__ */ new Set([...ctx.resolving, key])
|
|
23475
|
+
});
|
|
23476
|
+
}
|
|
23477
|
+
case "member": {
|
|
23478
|
+
if (n.prop === "shape") {
|
|
23479
|
+
const base = evalZod(n.obj, sub);
|
|
23480
|
+
return base.k === "object" || base.k === "unread" ? base : unread(`${describeNode(n)}`, n.s);
|
|
23481
|
+
}
|
|
23482
|
+
if (n.prop === "element") {
|
|
23483
|
+
const base = evalZod(n.obj, sub);
|
|
23484
|
+
if (base.k === "array") return base.items ?? { k: "any" };
|
|
23485
|
+
return base.k === "unread" ? base : unread(describeNode(n), n.s);
|
|
23486
|
+
}
|
|
23487
|
+
return unread(`member ${describeNode(n)}`, n.s);
|
|
23488
|
+
}
|
|
23489
|
+
case "call":
|
|
23490
|
+
return evalCall(n, sub);
|
|
23491
|
+
case "fn":
|
|
23492
|
+
return unread("function value", n.s);
|
|
23493
|
+
case "lit":
|
|
23494
|
+
return unread(`literal ${JSON.stringify(n.v)}`, n.s);
|
|
23495
|
+
case "arr":
|
|
23496
|
+
return unread("array literal", n.s);
|
|
23497
|
+
case "other":
|
|
23498
|
+
return unread(n.form, n.s);
|
|
23499
|
+
}
|
|
23500
|
+
}
|
|
23501
|
+
function evalShape(n, ctx) {
|
|
23502
|
+
const props = [];
|
|
23503
|
+
for (const e of n.entries) {
|
|
23504
|
+
if (e.kind === "prop") {
|
|
23505
|
+
props.push({ label: e.key, schema: evalZod(e.value, ctx), at: e.s });
|
|
23506
|
+
} else if (e.kind === "spread") {
|
|
23507
|
+
const spread = evalZod(e.value, ctx);
|
|
23508
|
+
if (spread.k === "object") props.push(...spread.props);
|
|
23509
|
+
else
|
|
23510
|
+
props.push({
|
|
23511
|
+
label: "(spread)",
|
|
23512
|
+
schema: unread(
|
|
23513
|
+
`spread ...${describeNode(e.value)}${spread.k === "unread" ? ` (${spread.form})` : ""}`,
|
|
23514
|
+
e.s
|
|
23515
|
+
),
|
|
23516
|
+
at: e.s
|
|
23517
|
+
});
|
|
23518
|
+
} else {
|
|
23519
|
+
props.push({ label: "[computed]", schema: unread(e.form, e.s), at: e.s });
|
|
23520
|
+
}
|
|
23521
|
+
}
|
|
23522
|
+
return { k: "object", props, at: n.s };
|
|
23523
|
+
}
|
|
23524
|
+
function unionArgs(arg, ctx, at) {
|
|
23525
|
+
let a = arg;
|
|
23526
|
+
let actx = ctx;
|
|
23527
|
+
if (a?.k === "id") {
|
|
23528
|
+
const r = resolveRef(a.name, a.s, ctx);
|
|
23529
|
+
if (isUnread(r)) return r;
|
|
23530
|
+
a = r.node;
|
|
23531
|
+
actx = r.ctx;
|
|
23532
|
+
}
|
|
23533
|
+
if (!a || a.k !== "arr") return unread(`union options ${a ? describeNode(a) : "missing"}`, at);
|
|
23534
|
+
return { k: "union", branches: a.items.map((x) => evalZod(x, actx)), at };
|
|
23535
|
+
}
|
|
23536
|
+
function evalCall(n, ctx) {
|
|
23537
|
+
const callee = n.callee;
|
|
23538
|
+
if (callee.k === "member") {
|
|
23539
|
+
const m = callee.prop;
|
|
23540
|
+
if (isZodRoot(callee.obj, ctx)) return zodFactory(m, n, ctx);
|
|
23541
|
+
if (callee.obj.k === "member" && isZodRoot(callee.obj.obj, ctx)) {
|
|
23542
|
+
const ns = callee.obj.prop;
|
|
23543
|
+
const known = ns === "iso" ? ISO_FACTORIES : ns === "coerce" ? COERCE_FACTORIES : null;
|
|
23544
|
+
if (known?.has(m)) return SCALAR;
|
|
23545
|
+
return unread(`z.${ns}.${m}() (not a builder of zod 4.6.7 the reader knows)`, n.s);
|
|
23546
|
+
}
|
|
23547
|
+
if (callee.obj.k === "id" && callee.obj.name === "Object" && m === "fromEntries")
|
|
23548
|
+
return unread("Object.fromEntries(...): keys and schemas built at run time", n.s);
|
|
23549
|
+
const base = evalZod(callee.obj, ctx);
|
|
23550
|
+
return zodMethod(base, m, n, ctx);
|
|
23551
|
+
}
|
|
23552
|
+
if (callee.k === "id") {
|
|
23553
|
+
const r = resolveRef(callee.name, callee.s, ctx);
|
|
23554
|
+
if (isUnread(r)) return { ...r, form: `call ${callee.name}(...): ${r.form}` };
|
|
23555
|
+
const fn = r.node;
|
|
23556
|
+
if (fn.k !== "fn" || fn.body === null)
|
|
23557
|
+
return unread(`call ${callee.name}(...): its body is not a single returned expression`, n.s);
|
|
23558
|
+
const key = `${r.ctx.file.path}#call@${fn.s}`;
|
|
23559
|
+
if (ctx.resolving.has(key)) return unread(`recursive call ${callee.name}(...)`, n.s);
|
|
23560
|
+
const params = /* @__PURE__ */ new Map();
|
|
23561
|
+
fn.params.forEach((p, i) => params.set(p, n.args[i] ? { node: n.args[i], ctx } : null));
|
|
23562
|
+
return evalZod(fn.body, {
|
|
23563
|
+
...r.ctx,
|
|
23564
|
+
params,
|
|
23565
|
+
depth: ctx.depth + 1,
|
|
23566
|
+
resolving: /* @__PURE__ */ new Set([...ctx.resolving, key])
|
|
23567
|
+
});
|
|
23568
|
+
}
|
|
23569
|
+
return unread(`call ${describeNode(callee)}(...)`, n.s);
|
|
23570
|
+
}
|
|
23571
|
+
function zodFactory(m, n, ctx) {
|
|
23572
|
+
const a = n.args;
|
|
23573
|
+
if (SCALAR_FACTORIES.has(m)) return SCALAR;
|
|
23574
|
+
if (ANY_FACTORIES.has(m)) return { k: "any" };
|
|
23575
|
+
if (NULL_FACTORIES.has(m)) return { k: "null" };
|
|
23576
|
+
switch (m) {
|
|
23577
|
+
case "array":
|
|
23578
|
+
case "set":
|
|
23579
|
+
return { k: "array", items: a[0] ? evalZod(a[0], ctx) : { k: "any" }, prefix: [], at: n.s };
|
|
23580
|
+
case "tuple": {
|
|
23581
|
+
const items = a[0]?.k === "arr" ? a[0].items.map((x) => evalZod(x, ctx)) : [];
|
|
23582
|
+
return { k: "array", items: null, prefix: items, at: n.s };
|
|
23583
|
+
}
|
|
23584
|
+
case "object":
|
|
23585
|
+
case "strictObject":
|
|
23586
|
+
case "looseObject":
|
|
23587
|
+
return a[0] ? evalZod(a[0], ctx) : { k: "object", props: [], at: n.s };
|
|
23588
|
+
case "record":
|
|
23589
|
+
case "partialRecord":
|
|
23590
|
+
case "looseRecord":
|
|
23591
|
+
case "map": {
|
|
23592
|
+
const v = a[a.length - 1];
|
|
23593
|
+
return {
|
|
23594
|
+
k: "object",
|
|
23595
|
+
props: [{ label: "*", schema: v ? evalZod(v, ctx) : { k: "any" }, at: n.s }],
|
|
23596
|
+
at: n.s
|
|
23597
|
+
};
|
|
23598
|
+
}
|
|
23599
|
+
case "union":
|
|
23600
|
+
case "xor":
|
|
23601
|
+
return unionArgs(a[0], ctx, n.s);
|
|
23602
|
+
case "discriminatedUnion":
|
|
23603
|
+
return unionArgs(a[1] ?? a[0], ctx, n.s);
|
|
23604
|
+
case "optional":
|
|
23605
|
+
case "exactOptional":
|
|
23606
|
+
case "nonoptional":
|
|
23607
|
+
case "readonly":
|
|
23608
|
+
case "prefault":
|
|
23609
|
+
case "catch":
|
|
23610
|
+
case "success":
|
|
23611
|
+
case "codec":
|
|
23612
|
+
return a[0] ? evalZod(a[0], ctx) : unread(`z.${m}() with no argument`, n.s);
|
|
23613
|
+
case "nullable":
|
|
23614
|
+
case "nullish":
|
|
23615
|
+
return a[0] ? nullable(evalZod(a[0], ctx), n.s) : unread(`z.${m}() with no argument`, n.s);
|
|
23616
|
+
case "intersection":
|
|
23617
|
+
return { k: "all", parts: a.map((x) => evalZod(x, ctx)) };
|
|
23618
|
+
case "preprocess":
|
|
23619
|
+
return a[1] ? evalZod(a[1], ctx) : unread("z.preprocess() with no schema", n.s);
|
|
23620
|
+
case "pipe":
|
|
23621
|
+
return a[0] ? evalZod(a[0], ctx) : unread("z.pipe() with no schema", n.s);
|
|
23622
|
+
case "lazy": {
|
|
23623
|
+
const f = a[0];
|
|
23624
|
+
if (f?.k === "fn" && f.body) return evalZod(f.body, ctx);
|
|
23625
|
+
return unread("z.lazy() whose body is not a single returned expression", n.s);
|
|
23626
|
+
}
|
|
23627
|
+
default:
|
|
23628
|
+
return unread(`z.${m}()`, n.s);
|
|
23629
|
+
}
|
|
23630
|
+
}
|
|
23631
|
+
function zodMethod(base, m, n, ctx) {
|
|
23632
|
+
if (base.k === "unread") return base;
|
|
23633
|
+
if (IDENTITY_METHODS.has(m)) return base;
|
|
23634
|
+
const a = n.args;
|
|
23635
|
+
switch (m) {
|
|
23636
|
+
case "nullable":
|
|
23637
|
+
case "nullish":
|
|
23638
|
+
return nullable(base, n.s);
|
|
23639
|
+
case "or":
|
|
23640
|
+
return {
|
|
23641
|
+
k: "union",
|
|
23642
|
+
branches: [base, a[0] ? evalZod(a[0], ctx) : unread(".or() with no argument", n.s)],
|
|
23643
|
+
at: n.s
|
|
23644
|
+
};
|
|
23645
|
+
case "and":
|
|
23646
|
+
return {
|
|
23647
|
+
k: "all",
|
|
23648
|
+
parts: [base, a[0] ? evalZod(a[0], ctx) : unread(".and() with no argument", n.s)]
|
|
23649
|
+
};
|
|
23650
|
+
case "array":
|
|
23651
|
+
return { k: "array", items: base, prefix: [], at: n.s };
|
|
23652
|
+
case "unwrap":
|
|
23653
|
+
return base.k === "union" ? { ...base, branches: base.branches.filter((b) => b.k !== "null") } : base;
|
|
23654
|
+
case "extend":
|
|
23655
|
+
case "merge":
|
|
23656
|
+
case "safeExtend": {
|
|
23657
|
+
if (base.k !== "object") return unread(`.${m}() on a non-object schema`, n.s);
|
|
23658
|
+
const more = a[0] ? evalZod(a[0], ctx) : unread(`.${m}() with no argument`, n.s);
|
|
23659
|
+
if (more.k === "object") return { ...base, props: [...base.props, ...more.props] };
|
|
23660
|
+
return { ...base, props: [...base.props, { label: "(spread)", schema: more, at: n.s }] };
|
|
23661
|
+
}
|
|
23662
|
+
case "pick":
|
|
23663
|
+
case "omit": {
|
|
23664
|
+
if (base.k !== "object" || a[0]?.k !== "obj")
|
|
23665
|
+
return unread(`.${m}() with a mask the reader cannot read`, n.s);
|
|
23666
|
+
const keys = new Set(
|
|
23667
|
+
a[0].entries.filter((e) => e.kind === "prop").map((e) => e.key)
|
|
23668
|
+
);
|
|
23669
|
+
return {
|
|
23670
|
+
...base,
|
|
23671
|
+
props: base.props.filter((p) => m === "pick" ? keys.has(p.label) : !keys.has(p.label))
|
|
23672
|
+
};
|
|
23673
|
+
}
|
|
23674
|
+
case "keyof":
|
|
23675
|
+
return SCALAR;
|
|
23676
|
+
default:
|
|
23677
|
+
return unread(`method .${m}()`, n.s);
|
|
23678
|
+
}
|
|
23679
|
+
}
|
|
23680
|
+
var UNREAD_KEY = "__s43_unread__";
|
|
23681
|
+
var jsonOffsets = /* @__PURE__ */ new WeakMap();
|
|
23682
|
+
var jsonKeyOffsets = /* @__PURE__ */ new WeakMap();
|
|
23683
|
+
function literalValue(n, ctx, depth = 0) {
|
|
23684
|
+
if (depth > 30) return { [UNREAD_KEY]: "literal nested deeper than 30" };
|
|
23685
|
+
switch (n.k) {
|
|
23686
|
+
case "lit":
|
|
23687
|
+
return n.v;
|
|
23688
|
+
case "arr": {
|
|
23689
|
+
const out = n.items.map((x) => literalValue(x, ctx, depth + 1));
|
|
23690
|
+
jsonOffsets.set(out, n.s);
|
|
23691
|
+
return out;
|
|
23692
|
+
}
|
|
23693
|
+
case "obj": {
|
|
23694
|
+
const out = {};
|
|
23695
|
+
const keys = /* @__PURE__ */ new Map();
|
|
23696
|
+
for (const e of n.entries) {
|
|
23697
|
+
if (e.kind === "prop") {
|
|
23698
|
+
out[e.key] = literalValue(e.value, ctx, depth + 1);
|
|
23699
|
+
keys.set(e.key, e.s);
|
|
23700
|
+
} else if (e.kind === "spread") {
|
|
23701
|
+
const v = literalValue(e.value, ctx, depth + 1);
|
|
23702
|
+
if (v && typeof v === "object" && !Array.isArray(v) && !(UNREAD_KEY in v))
|
|
23703
|
+
Object.assign(out, v);
|
|
23704
|
+
else out[UNREAD_KEY] = `spread ...${describeNode(e.value)}`;
|
|
23705
|
+
} else out[UNREAD_KEY] = e.form;
|
|
23706
|
+
}
|
|
23707
|
+
jsonOffsets.set(out, n.s);
|
|
23708
|
+
jsonKeyOffsets.set(out, keys);
|
|
23709
|
+
return out;
|
|
23710
|
+
}
|
|
23711
|
+
case "id": {
|
|
23712
|
+
const r = resolveRef(n.name, n.s, ctx);
|
|
23713
|
+
if (isUnread(r)) return { [UNREAD_KEY]: r.form };
|
|
23714
|
+
return literalValue(r.node, r.ctx, depth + 1);
|
|
23715
|
+
}
|
|
23716
|
+
default:
|
|
23717
|
+
return { [UNREAD_KEY]: describeNode(n) };
|
|
23718
|
+
}
|
|
23719
|
+
}
|
|
23720
|
+
function isObj(v) {
|
|
23721
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
23722
|
+
}
|
|
23723
|
+
function jsonToS(v, root, seen, depth = 0) {
|
|
23724
|
+
if (depth > 40) return unread("JSON schema nested deeper than 40");
|
|
23725
|
+
if (typeof v === "boolean") return { k: "any" };
|
|
23726
|
+
if (!isObj(v)) return unread(`JSON schema value ${Array.isArray(v) ? "array" : typeof v}`);
|
|
23727
|
+
const at = jsonOffsets.get(v);
|
|
23728
|
+
if (UNREAD_KEY in v) return unread(String(v[UNREAD_KEY]), at);
|
|
23729
|
+
const parts = [];
|
|
23730
|
+
const ref = v.$ref;
|
|
23731
|
+
if (ref !== void 0) {
|
|
23732
|
+
if (typeof ref !== "string") return unread("$ref that is not a string", at);
|
|
23733
|
+
const m = ref.match(/^#\/(\$defs|definitions)\/(.+)$/);
|
|
23734
|
+
if (!m) return unread(`$ref ${ref} (not a local #/$defs or #/definitions reference)`, at);
|
|
23735
|
+
if (seen.has(ref)) return { k: "any" };
|
|
23736
|
+
const defs = isObj(root.root) ? root.root[m[1]] : void 0;
|
|
23737
|
+
const target = isObj(defs) ? defs[m[2].replace(/~1/g, "/").replace(/~0/g, "~")] : void 0;
|
|
23738
|
+
if (target === void 0) return unread(`$ref ${ref} unresolvable`, at);
|
|
23739
|
+
parts.push(jsonToS(target, root, /* @__PURE__ */ new Set([...seen, ref]), depth + 1));
|
|
23740
|
+
}
|
|
23741
|
+
const sub = (x) => jsonToS(x, root, seen, depth + 1);
|
|
23742
|
+
for (const kw of ["anyOf", "oneOf"]) {
|
|
23743
|
+
const opts = v[kw];
|
|
23744
|
+
if (opts === void 0) continue;
|
|
23745
|
+
if (!Array.isArray(opts)) parts.push(unread(`${kw} that is not an array`, at));
|
|
23746
|
+
else parts.push({ k: "union", branches: opts.map(sub), at });
|
|
23747
|
+
}
|
|
23748
|
+
if (v.allOf !== void 0) {
|
|
23749
|
+
if (!Array.isArray(v.allOf)) parts.push(unread("allOf that is not an array", at));
|
|
23750
|
+
else parts.push({ k: "all", parts: v.allOf.map(sub) });
|
|
23751
|
+
}
|
|
23752
|
+
const typed = (t) => {
|
|
23753
|
+
if (t === "array") {
|
|
23754
|
+
const items = v.items;
|
|
23755
|
+
const prefix = v.prefixItems;
|
|
23756
|
+
return {
|
|
23757
|
+
k: "array",
|
|
23758
|
+
items: Array.isArray(items) ? null : items === void 0 ? null : sub(items),
|
|
23759
|
+
prefix: Array.isArray(prefix) ? prefix.map(sub) : Array.isArray(items) ? items.map(sub) : [],
|
|
23760
|
+
at
|
|
23761
|
+
};
|
|
23762
|
+
}
|
|
23763
|
+
if (t === "object") return objectOf();
|
|
23764
|
+
if (t === "null") return { k: "null" };
|
|
23765
|
+
return { k: "scalar", name: t };
|
|
23766
|
+
};
|
|
23767
|
+
const objectOf = () => {
|
|
23768
|
+
const props = [];
|
|
23769
|
+
const keyAt = jsonKeyOffsets.get(isObj(v.properties) ? v.properties : {}) ?? /* @__PURE__ */ new Map();
|
|
23770
|
+
if (isObj(v.properties))
|
|
23771
|
+
for (const [k, s] of Object.entries(v.properties))
|
|
23772
|
+
props.push({ label: k, schema: sub(s), at: keyAt.get(k) });
|
|
23773
|
+
else if (v.properties !== void 0)
|
|
23774
|
+
props.push({ label: "properties", schema: unread("properties that is not an object", at) });
|
|
23775
|
+
if (isObj(v.additionalProperties))
|
|
23776
|
+
props.push({ label: "*", schema: sub(v.additionalProperties), at });
|
|
23777
|
+
if (isObj(v.patternProperties))
|
|
23778
|
+
for (const s of Object.values(v.patternProperties))
|
|
23779
|
+
props.push({ label: "*", schema: sub(s), at });
|
|
23780
|
+
return { k: "object", props, at };
|
|
23781
|
+
};
|
|
23782
|
+
const type = v.type;
|
|
23783
|
+
if (Array.isArray(type)) {
|
|
23784
|
+
parts.push({
|
|
23785
|
+
k: "union",
|
|
23786
|
+
branches: type.map(
|
|
23787
|
+
(t) => typeof t === "string" ? typed(t) : unread("type entry that is not a string", at)
|
|
23788
|
+
),
|
|
23789
|
+
at
|
|
23790
|
+
});
|
|
23791
|
+
} else if (typeof type === "string") {
|
|
23792
|
+
parts.push(typed(type));
|
|
23793
|
+
} else if (type !== void 0) {
|
|
23794
|
+
parts.push(unread("type that is neither a string nor an array", at));
|
|
23795
|
+
} else if (v.properties !== void 0 || v.additionalProperties !== void 0 || v.patternProperties !== void 0) {
|
|
23796
|
+
parts.push(objectOf());
|
|
23797
|
+
} else if (v.items !== void 0 || v.prefixItems !== void 0) {
|
|
23798
|
+
parts.push(typed("array"));
|
|
23799
|
+
}
|
|
23800
|
+
if (parts.length === 0)
|
|
23801
|
+
return v.enum !== void 0 || v.const !== void 0 ? SCALAR : { k: "any" };
|
|
23802
|
+
return parts.length === 1 ? parts[0] : { k: "all", parts };
|
|
23803
|
+
}
|
|
23804
|
+
function walk2(s, path, useAt, out, loc) {
|
|
23805
|
+
const offsetsFor = (...offs) => offs.filter((o) => o !== void 0);
|
|
23806
|
+
switch (s.k) {
|
|
23807
|
+
case "union": {
|
|
23808
|
+
const branches = flatten(s.branches);
|
|
23809
|
+
const arrays = branches.filter((b) => b.k === "array").length;
|
|
23810
|
+
const others = branches.filter(
|
|
23811
|
+
(b) => b.k !== "array" && b.k !== "null" && b.k !== "unread"
|
|
23812
|
+
).length;
|
|
23813
|
+
const unreadB = branches.filter((b) => b.k === "unread");
|
|
23814
|
+
if (arrays > 0 && others > 0) {
|
|
23815
|
+
const use = loc(useAt ?? s.at);
|
|
23816
|
+
const origin = loc(s.at ?? useAt);
|
|
23817
|
+
out.push({
|
|
23818
|
+
path,
|
|
23819
|
+
kind: "violation",
|
|
23820
|
+
offsets: offsetsFor(useAt, s.at),
|
|
23821
|
+
anchor: use.anchor,
|
|
23822
|
+
...origin.anchor !== use.anchor ? { origin: origin.anchor } : {}
|
|
23823
|
+
});
|
|
23824
|
+
} else if (unreadB.length > 0) {
|
|
23825
|
+
out.push({
|
|
23826
|
+
path,
|
|
23827
|
+
kind: "unread",
|
|
23828
|
+
form: `union branch ${unreadB.map((b) => b.form).join(", ")}`,
|
|
23829
|
+
offsets: [],
|
|
23830
|
+
anchor: loc(unreadB[0].at ?? s.at ?? useAt).anchor
|
|
23831
|
+
});
|
|
23832
|
+
}
|
|
23833
|
+
for (const b of branches) if (b.k !== "unread") walk2(b, path, useAt, out, loc);
|
|
23834
|
+
return;
|
|
23835
|
+
}
|
|
23836
|
+
case "array":
|
|
23837
|
+
if (s.items) walk2(s.items, `${path}[]`, useAt, out, loc);
|
|
23838
|
+
s.prefix.forEach((p, i) => walk2(p, `${path}[${i}]`, useAt, out, loc));
|
|
23839
|
+
return;
|
|
23840
|
+
case "object":
|
|
23841
|
+
for (const p of s.props) walk2(p.schema, `${path}.${p.label}`, p.at ?? useAt, out, loc);
|
|
23842
|
+
return;
|
|
23843
|
+
case "all":
|
|
23844
|
+
for (const p of s.parts) walk2(p, path, useAt, out, loc);
|
|
23845
|
+
return;
|
|
23846
|
+
case "unread":
|
|
23847
|
+
out.push({
|
|
23848
|
+
path,
|
|
23849
|
+
kind: "unread",
|
|
23850
|
+
form: s.form,
|
|
23851
|
+
offsets: [],
|
|
23852
|
+
anchor: loc(s.at ?? useAt).anchor
|
|
23853
|
+
});
|
|
23854
|
+
return;
|
|
23855
|
+
default:
|
|
23856
|
+
return;
|
|
23857
|
+
}
|
|
23858
|
+
}
|
|
23859
|
+
var ANNOTATION_KEYS = /* @__PURE__ */ new Set([
|
|
23860
|
+
"title",
|
|
23861
|
+
"readOnlyHint",
|
|
23862
|
+
"destructiveHint",
|
|
23863
|
+
"idempotentHint",
|
|
23864
|
+
"openWorldHint"
|
|
23865
|
+
]);
|
|
23866
|
+
function isJsonLiteral(n) {
|
|
23867
|
+
if (n.k !== "obj") return false;
|
|
23868
|
+
for (const e of n.entries) {
|
|
23869
|
+
if (e.kind !== "prop") continue;
|
|
23870
|
+
if (e.key === "type" && e.value.k === "lit" && typeof e.value.v === "string") return true;
|
|
23871
|
+
if ((e.key === "anyOf" || e.key === "oneOf" || e.key === "allOf") && e.value.k === "arr")
|
|
23872
|
+
return true;
|
|
23873
|
+
if ((e.key === "properties" || e.key === "$defs") && e.value.k === "obj") return true;
|
|
23874
|
+
}
|
|
23875
|
+
return false;
|
|
23876
|
+
}
|
|
23877
|
+
function schemaValue(n) {
|
|
23878
|
+
return isJsonLiteral(n) ? { kind: "json", node: n } : { kind: "zod", node: n };
|
|
23879
|
+
}
|
|
23880
|
+
function fromConfig(obj, ctx) {
|
|
23881
|
+
const props = obj.entries.filter((e) => e.kind === "prop");
|
|
23882
|
+
const input = props.find((e) => e.key === "inputSchema");
|
|
23883
|
+
if (input) return schemaValue(input.value);
|
|
23884
|
+
const literalValued = (e) => isStringish(e.value, ctx) || e.value.k === "lit" && typeof e.value.v !== "string";
|
|
23885
|
+
if (props.some((e) => (e.key === "description" || e.key === "title") && isStringish(e.value, ctx)))
|
|
23886
|
+
return { kind: "none" };
|
|
23887
|
+
if (props.some((e) => e.key === "outputSchema" || e.key === "annotations" || e.key === "_meta"))
|
|
23888
|
+
return { kind: "none" };
|
|
23889
|
+
if (props.length > 0 && props.every((e) => ANNOTATION_KEYS.has(e.key) && literalValued(e)))
|
|
23890
|
+
return { kind: "none" };
|
|
23891
|
+
return null;
|
|
23892
|
+
}
|
|
23893
|
+
function isStringish(n, ctx) {
|
|
23894
|
+
if (n.k === "lit" && typeof n.v === "string") return true;
|
|
23895
|
+
if (n.k === "other") return n.strConcat || n.form.startsWith("template");
|
|
23896
|
+
if (n.k === "id") {
|
|
23897
|
+
const d = ctx.b.decls.get(n.name);
|
|
23898
|
+
if (d && d.length === 1) return isStringish(d[0], ctx);
|
|
23899
|
+
}
|
|
23900
|
+
return false;
|
|
23901
|
+
}
|
|
23902
|
+
function locateSchema(file, toolName, anchorLine) {
|
|
23903
|
+
const lx = lex(file);
|
|
23904
|
+
const ctx = moduleCtx(file, null);
|
|
23905
|
+
const lineStart = lx.base + (lx.lineStarts[anchorLine - 1] ?? 0);
|
|
23906
|
+
const toks = lx.toks;
|
|
23907
|
+
const isName = (t) => {
|
|
23908
|
+
if (t.t === "str") return t.v === toolName;
|
|
23909
|
+
if (t.t !== "id") return false;
|
|
23910
|
+
const d = ctx.b.decls.get(t.v);
|
|
23911
|
+
return d !== void 0 && d.length === 1 && d[0].k === "lit" && d[0].v === toolName;
|
|
23912
|
+
};
|
|
23913
|
+
let nameIdx = -1;
|
|
23914
|
+
const anchorEnd = lx.base + (lx.lineStarts[anchorLine] ?? lx.text.length);
|
|
23915
|
+
for (let i = 0; i < toks.length && nameIdx < 0; i++) {
|
|
23916
|
+
const t = toks[i];
|
|
23917
|
+
if (t.s < lineStart) continue;
|
|
23918
|
+
if (t.s >= anchorEnd) break;
|
|
23919
|
+
if (t.t !== "p" || t.v !== "(" || toks[i - 1]?.t !== "id") continue;
|
|
23920
|
+
const end = new Parser(lx, i).skipGroup(i);
|
|
23921
|
+
let depth2 = 0;
|
|
23922
|
+
for (let j = i; j < end; j++) {
|
|
23923
|
+
const tj = toks[j];
|
|
23924
|
+
if (tj.t === "p" && OPEN2[tj.v]) depth2++;
|
|
23925
|
+
else if (tj.t === "p" && (tj.v === ")" || tj.v === "]" || tj.v === "}")) depth2--;
|
|
23926
|
+
else if (depth2 === 1 && isName(tj) && (toks[j - 1].v === "(" || toks[j - 1].v === ",")) {
|
|
23927
|
+
nameIdx = j;
|
|
23928
|
+
break;
|
|
23929
|
+
}
|
|
23930
|
+
}
|
|
23931
|
+
}
|
|
23932
|
+
for (let i = 0; i < toks.length && nameIdx < 0; i++) {
|
|
23933
|
+
const t = toks[i];
|
|
23934
|
+
if (t.s < lineStart) continue;
|
|
23935
|
+
if (t.s >= anchorEnd) break;
|
|
23936
|
+
if (isName(t)) nameIdx = i;
|
|
23937
|
+
}
|
|
23938
|
+
if (nameIdx < 0)
|
|
23939
|
+
return {
|
|
23940
|
+
kind: "unread",
|
|
23941
|
+
form: `registration of ${toolName}: the name argument was not found`,
|
|
23942
|
+
at: lineStart
|
|
23943
|
+
};
|
|
23944
|
+
let depth = 0;
|
|
23945
|
+
let openIdx = -1;
|
|
23946
|
+
for (let j = nameIdx - 1; j >= 0; j--) {
|
|
23947
|
+
const t = toks[j];
|
|
23948
|
+
if (t.t !== "p") continue;
|
|
23949
|
+
if (t.v === ")" || t.v === "]" || t.v === "}") depth++;
|
|
23950
|
+
else if (t.v === "(" || t.v === "[" || t.v === "{") {
|
|
23951
|
+
if (depth === 0) {
|
|
23952
|
+
openIdx = j;
|
|
23953
|
+
break;
|
|
23954
|
+
}
|
|
23955
|
+
depth--;
|
|
23956
|
+
}
|
|
23957
|
+
}
|
|
23958
|
+
if (openIdx < 0)
|
|
23959
|
+
return {
|
|
23960
|
+
kind: "unread",
|
|
23961
|
+
form: `registration of ${toolName}: no enclosing call or object`,
|
|
23962
|
+
at: toks[nameIdx].s
|
|
23963
|
+
};
|
|
23964
|
+
const open = toks[openIdx];
|
|
23965
|
+
if (open.v === "{") {
|
|
23966
|
+
const obj = new Parser(lx, openIdx).parseExpr();
|
|
23967
|
+
if (obj.k !== "obj") return { kind: "unread", form: `descriptor of ${toolName}`, at: open.s };
|
|
23968
|
+
const input = obj.entries.find((e) => e.kind === "prop" && e.key === "inputSchema");
|
|
23969
|
+
return input && input.kind === "prop" ? schemaValue(input.value) : { kind: "none" };
|
|
23970
|
+
}
|
|
23971
|
+
if (open.v !== "(")
|
|
23972
|
+
return { kind: "unread", form: `registration of ${toolName} inside ${open.v}`, at: open.s };
|
|
23973
|
+
const args = readArgs(lx, openIdx);
|
|
23974
|
+
const k = args.findIndex((a) => a.s === toks[nameIdx].s);
|
|
23975
|
+
if (k < 0)
|
|
23976
|
+
return {
|
|
23977
|
+
kind: "unread",
|
|
23978
|
+
form: `registration of ${toolName}: name argument not at top level`,
|
|
23979
|
+
at: open.s
|
|
23980
|
+
};
|
|
23981
|
+
for (const a of args.slice(k + 1)) {
|
|
23982
|
+
if (a.k === "fn") return { kind: "none" };
|
|
23983
|
+
if (isStringish(a, ctx)) continue;
|
|
23984
|
+
let node = a;
|
|
23985
|
+
if (node.k === "id") {
|
|
23986
|
+
const d = ctx.b.decls.get(node.name);
|
|
23987
|
+
if (d && d.length === 1 && d[0].k === "obj") node = d[0];
|
|
23988
|
+
else if (d && d.length === 1 && d[0].k === "fn") return { kind: "none" };
|
|
23989
|
+
}
|
|
23990
|
+
if (node.k === "obj") {
|
|
23991
|
+
const cfg = fromConfig(node, ctx);
|
|
23992
|
+
if (cfg) return cfg;
|
|
23993
|
+
return schemaValue(node);
|
|
23994
|
+
}
|
|
23995
|
+
return { kind: "zod", node: a };
|
|
23996
|
+
}
|
|
23997
|
+
return { kind: "none" };
|
|
23998
|
+
}
|
|
23999
|
+
function readArgs(lx, openIdx) {
|
|
24000
|
+
const p = new Parser(lx, openIdx);
|
|
24001
|
+
const end = p.skipGroup(openIdx);
|
|
24002
|
+
const out = [];
|
|
24003
|
+
p.i = openIdx + 1;
|
|
24004
|
+
while (p.i < end - 1) {
|
|
24005
|
+
if (p.isP(",")) {
|
|
24006
|
+
p.i++;
|
|
24007
|
+
continue;
|
|
24008
|
+
}
|
|
24009
|
+
const before = p.i;
|
|
24010
|
+
out.push(p.parseExpr());
|
|
24011
|
+
if (p.i === before) p.i++;
|
|
24012
|
+
while (p.i < end - 1 && !p.isP(",")) p.i++;
|
|
24013
|
+
}
|
|
24014
|
+
return out;
|
|
24015
|
+
}
|
|
24016
|
+
function exemption(offsets) {
|
|
24017
|
+
for (const off of offsets) {
|
|
24018
|
+
const at = locate(off);
|
|
24019
|
+
if (!at) continue;
|
|
24020
|
+
const lx = lex(at.file);
|
|
24021
|
+
for (const ln of [at.line, at.line - 1]) {
|
|
24022
|
+
const c = lx.comments.get(ln);
|
|
24023
|
+
const m = c?.match(MARKER_RE);
|
|
24024
|
+
if (m && m[1].trim().length >= MIN_REASON) return m[1].trim();
|
|
24025
|
+
}
|
|
24026
|
+
}
|
|
24027
|
+
return null;
|
|
24028
|
+
}
|
|
24029
|
+
function verdictOf(j, scope, anchorFallback) {
|
|
24030
|
+
const ex = j.exempt.length > 0 ? ` Exempted (${j.exempt.length}): ${j.exempt.map((e) => `${e.path} (${e.anchor}) \u2014 "${e.reason}"`).join("; ")}.` : "";
|
|
24031
|
+
let decided;
|
|
24032
|
+
if (j.violations.length > 0) {
|
|
24033
|
+
decided = {
|
|
24034
|
+
id: ID,
|
|
24035
|
+
anchor: j.violations[0].anchor,
|
|
24036
|
+
state: "non-conforming",
|
|
24037
|
+
verdict: `${j.violations.length} of ${j.argumentCount} tool input site(s) declare a union mixing an array and a non-array value, which clients send in different shapes (${RULE}): ${j.violations.map((v) => `${v.path} (${v.anchor}${v.origin ? `, union at ${v.origin}` : ""})`).join(", ")}.${ex}`
|
|
24038
|
+
};
|
|
24039
|
+
} else {
|
|
24040
|
+
decided = {
|
|
24041
|
+
id: ID,
|
|
24042
|
+
anchor: anchorFallback,
|
|
24043
|
+
state: "present",
|
|
24044
|
+
verdict: `${j.toolCount} tool(s) read (${scope}), ${j.argumentCount} input site(s): no input argument mixes an array and a non-array value (${RULE}).${ex}`
|
|
24045
|
+
};
|
|
24046
|
+
}
|
|
24047
|
+
return settle(ID, decided, j.unread);
|
|
24048
|
+
}
|
|
24049
|
+
function judgeSites(sites, served, j) {
|
|
24050
|
+
for (const s of sites) {
|
|
24051
|
+
if (s.kind === "unread") {
|
|
24052
|
+
j.unread.push({
|
|
24053
|
+
anchor: s.anchor,
|
|
24054
|
+
reason: `${s.path}: ${s.form ?? "unread form"} (${RULE})`
|
|
24055
|
+
});
|
|
24056
|
+
continue;
|
|
24057
|
+
}
|
|
24058
|
+
const reason = served ? null : exemption(s.offsets);
|
|
24059
|
+
if (reason) j.exempt.push({ ...s, reason });
|
|
24060
|
+
else j.violations.push(s);
|
|
24061
|
+
}
|
|
24062
|
+
}
|
|
24063
|
+
function countArgs(s) {
|
|
24064
|
+
if (s.k === "object") return s.props.length;
|
|
24065
|
+
if (s.k === "all") return s.parts.reduce((n, p) => n + countArgs(p), 0);
|
|
24066
|
+
return 1;
|
|
24067
|
+
}
|
|
24068
|
+
function dedupe(sites) {
|
|
24069
|
+
const seen = /* @__PURE__ */ new Set();
|
|
24070
|
+
return sites.filter((s) => {
|
|
24071
|
+
const k = `${s.kind}|${s.path}|${s.form ?? ""}`;
|
|
24072
|
+
if (seen.has(k)) return false;
|
|
24073
|
+
seen.add(k);
|
|
24074
|
+
return true;
|
|
24075
|
+
});
|
|
24076
|
+
}
|
|
24077
|
+
function runStatic(tree) {
|
|
24078
|
+
const controls = s43Controls();
|
|
24079
|
+
if (!controls.sees || !controls.spares) {
|
|
24080
|
+
throw new Error(
|
|
24081
|
+
`S43 positive control FAILED: sees=${controls.sees} spares=${controls.spares} \u2014 reader broken, verdict untrustworthy`
|
|
24082
|
+
);
|
|
24083
|
+
}
|
|
24084
|
+
const tools = findRegisteredTools(tree).filter(
|
|
24085
|
+
(t) => isProductSource(t.anchor.slice(0, t.anchor.lastIndexOf(":")))
|
|
24086
|
+
);
|
|
24087
|
+
const unresolvedTools = findUnresolvedToolSites(tree).filter(
|
|
24088
|
+
(a) => isProductSource(a.slice(0, a.lastIndexOf(":")))
|
|
24089
|
+
);
|
|
24090
|
+
if (tools.length === 0) {
|
|
24091
|
+
const surface = toolSurfaceAnchor(tree);
|
|
24092
|
+
if (surface || unresolvedTools.length > 0) {
|
|
24093
|
+
const reason = noToolsLocatedReason(tree, `no input schema could be read (${RULE})`);
|
|
24094
|
+
return couldNotJudge(
|
|
24095
|
+
ID,
|
|
24096
|
+
surface ?? unresolvedTools[0],
|
|
24097
|
+
unresolvedTools.length > 0 ? `${reason}; unresolved registration site(s): ${unresolvedTools.join(", ")}` : reason
|
|
24098
|
+
);
|
|
24099
|
+
}
|
|
24100
|
+
return {
|
|
24101
|
+
id: ID,
|
|
24102
|
+
anchor: tree.root,
|
|
24103
|
+
state: "absent",
|
|
24104
|
+
verdict: `no MCP tool registered in product source \u2014 ${RULE} n/a`
|
|
24105
|
+
};
|
|
24106
|
+
}
|
|
24107
|
+
const byRel = new Map(tree.files.map((f) => [f.rel, f]));
|
|
24108
|
+
const j = {
|
|
24109
|
+
violations: [],
|
|
24110
|
+
exempt: [],
|
|
24111
|
+
unread: [],
|
|
24112
|
+
argumentCount: 0,
|
|
24113
|
+
toolCount: tools.length
|
|
24114
|
+
};
|
|
24115
|
+
for (const a of unresolvedTools)
|
|
24116
|
+
j.unread.push({
|
|
24117
|
+
anchor: a,
|
|
24118
|
+
reason: `a tool registered here has a name the scan cannot resolve, so its input schema is unread (${RULE})`
|
|
24119
|
+
});
|
|
24120
|
+
for (const tool of tools) {
|
|
24121
|
+
const cut = tool.anchor.lastIndexOf(":");
|
|
24122
|
+
const file = byRel.get(tool.anchor.slice(0, cut));
|
|
24123
|
+
const line = Number(tool.anchor.slice(cut + 1));
|
|
24124
|
+
if (!file) {
|
|
24125
|
+
j.unread.push({
|
|
24126
|
+
anchor: tool.anchor,
|
|
24127
|
+
reason: `${tool.name}: registration file not in the scanned tree (${RULE})`
|
|
24128
|
+
});
|
|
24129
|
+
continue;
|
|
24130
|
+
}
|
|
24131
|
+
const loc = (off) => {
|
|
24132
|
+
const at = off === void 0 ? null : locate(off);
|
|
24133
|
+
return at ? { line: at.line, anchor: `${at.file.rel}:${at.line}` } : { anchor: tool.anchor };
|
|
24134
|
+
};
|
|
24135
|
+
const located = locateSchema(file, tool.name, line);
|
|
24136
|
+
if (located.kind === "none") continue;
|
|
24137
|
+
if (located.kind === "unread") {
|
|
24138
|
+
j.unread.push({
|
|
24139
|
+
anchor: loc(located.at).anchor,
|
|
24140
|
+
reason: `${tool.name}: ${located.form} (${RULE})`
|
|
24141
|
+
});
|
|
24142
|
+
continue;
|
|
24143
|
+
}
|
|
24144
|
+
const ctx = moduleCtx(file, tree);
|
|
24145
|
+
const finalSchema = located.kind === "json" ? jsonSchemaOf(located.node, ctx) : evalZod(located.node, ctx);
|
|
24146
|
+
j.argumentCount += countArgs(finalSchema);
|
|
24147
|
+
const sites = [];
|
|
24148
|
+
walk2(finalSchema, tool.name, void 0, sites, loc);
|
|
24149
|
+
judgeSites(dedupe(sites), false, j);
|
|
24150
|
+
}
|
|
24151
|
+
return verdictOf(j, "static, from source", tools[0].anchor);
|
|
24152
|
+
}
|
|
24153
|
+
function jsonSchemaOf(n, ctx) {
|
|
24154
|
+
const v = literalValue(n, ctx);
|
|
24155
|
+
return jsonToS(v, { root: v }, /* @__PURE__ */ new Set());
|
|
24156
|
+
}
|
|
24157
|
+
function runServedHalf(runtime) {
|
|
24158
|
+
const anchor = `${runtime.root} (served)`;
|
|
24159
|
+
if (runtime.launchError)
|
|
24160
|
+
return couldNotJudge(
|
|
24161
|
+
ID,
|
|
24162
|
+
anchor,
|
|
24163
|
+
`the server could not be started/introspected, so no served inputSchema was read: ${runtime.launchError} (${RULE})`
|
|
24164
|
+
);
|
|
24165
|
+
const tools = runtime.tools;
|
|
24166
|
+
if (tools.length === 0)
|
|
24167
|
+
return {
|
|
24168
|
+
id: ID,
|
|
24169
|
+
anchor,
|
|
24170
|
+
state: "absent",
|
|
24171
|
+
verdict: `the running server serves no tool \u2014 ${RULE} n/a`
|
|
24172
|
+
};
|
|
24173
|
+
const j = {
|
|
24174
|
+
violations: [],
|
|
24175
|
+
exempt: [],
|
|
24176
|
+
unread: [],
|
|
24177
|
+
argumentCount: 0,
|
|
24178
|
+
toolCount: tools.length
|
|
24179
|
+
};
|
|
24180
|
+
for (const t of tools) {
|
|
24181
|
+
if (t.inputSchema === void 0) {
|
|
24182
|
+
j.unread.push({
|
|
24183
|
+
anchor: `${anchor} ${t.name}`,
|
|
24184
|
+
reason: `${t.name}: the introspection recorded no inputSchema for this served tool (tools/list inputSchema unread) (${RULE})`
|
|
24185
|
+
});
|
|
24186
|
+
continue;
|
|
24187
|
+
}
|
|
24188
|
+
const schema = jsonToS(t.inputSchema, { root: t.inputSchema }, /* @__PURE__ */ new Set());
|
|
24189
|
+
j.argumentCount += countArgs(schema);
|
|
24190
|
+
const sites = [];
|
|
24191
|
+
walk2(schema, t.name, void 0, sites, () => ({ anchor: `${anchor} tools/list ${t.name}` }));
|
|
24192
|
+
judgeSites(dedupe(sites), true, j);
|
|
24193
|
+
}
|
|
24194
|
+
return verdictOf(j, "served tools/list inputSchema", anchor);
|
|
24195
|
+
}
|
|
24196
|
+
function controlFile(text) {
|
|
24197
|
+
return {
|
|
24198
|
+
path: "<s43-control>.ts",
|
|
24199
|
+
rel: "<s43-control>",
|
|
24200
|
+
lines: text.split("\n").map((raw, i) => ({ n: i + 1, raw, comment: false }))
|
|
24201
|
+
};
|
|
24202
|
+
}
|
|
24203
|
+
function controlSites(text) {
|
|
24204
|
+
const file = controlFile(text);
|
|
24205
|
+
const located = locateSchema(file, "c", 3);
|
|
24206
|
+
if (located.kind !== "zod") return [];
|
|
24207
|
+
const ctx = moduleCtx(file, null);
|
|
24208
|
+
const sites = [];
|
|
24209
|
+
walk2(evalZod(located.node, ctx), "c", void 0, sites, () => ({ anchor: "<s43-control>" }));
|
|
24210
|
+
return sites;
|
|
24211
|
+
}
|
|
24212
|
+
function s43Controls() {
|
|
24213
|
+
const head = 'import { z } from "zod";\nexport function r(server: any) {\n server.registerTool("c", { description: "d", inputSchema: ';
|
|
24214
|
+
const tail = " }, async () => ({ content: [] }));\n}\n";
|
|
24215
|
+
const red = controlSites(`${head}{ ids: z.union([z.array(z.string()), z.string()]) }${tail}`);
|
|
24216
|
+
const green = controlSites(
|
|
24217
|
+
`${head}{ ids: z.union([z.string(), z.number()]), o: z.array(z.string()).nullable() }${tail}`
|
|
24218
|
+
);
|
|
24219
|
+
return {
|
|
24220
|
+
sees: red.length === 1 && red[0].kind === "violation" && red[0].path === "c.ids",
|
|
24221
|
+
spares: green.length === 0
|
|
24222
|
+
};
|
|
24223
|
+
}
|
|
24224
|
+
var s43UnionInput = {
|
|
24225
|
+
id: ID,
|
|
24226
|
+
rule: RULE,
|
|
24227
|
+
pin: STANDARD_PIN,
|
|
24228
|
+
run: runStatic,
|
|
24229
|
+
runServed: (runtime) => runServedHalf(runtime)
|
|
24230
|
+
};
|
|
24231
|
+
|
|
22512
24232
|
// src/detectors/index.ts
|
|
22513
24233
|
var registered = [
|
|
22514
24234
|
d2,
|
|
@@ -22614,6 +24334,7 @@ var registered = [
|
|
|
22614
24334
|
s39UpstreamError,
|
|
22615
24335
|
s40UpstreamRowsNarrowed,
|
|
22616
24336
|
s41LakeReader,
|
|
24337
|
+
s43UnionInput,
|
|
22617
24338
|
e5ExtensionIsolation,
|
|
22618
24339
|
a3SandboxRespected,
|
|
22619
24340
|
a4WcagGate,
|
|
@@ -22647,6 +24368,7 @@ var READS_CODE = /* @__PURE__ */ new Set([
|
|
|
22647
24368
|
"S-39",
|
|
22648
24369
|
"S-40",
|
|
22649
24370
|
"S-41",
|
|
24371
|
+
"S-43",
|
|
22650
24372
|
"E-5",
|
|
22651
24373
|
"A-3"
|
|
22652
24374
|
]);
|
|
@@ -23017,7 +24739,7 @@ const onMessage = (msg) => {
|
|
|
23017
24739
|
const props = schemaOf(t).properties;
|
|
23018
24740
|
return Boolean(props && typeof props === "object" && Object.prototype.hasOwnProperty.call(props, "cursor"));
|
|
23019
24741
|
};
|
|
23020
|
-
tools = served.map((t) => ({ name: String(t && t.name), description: t && typeof t.description === "string" ? t.description : undefined, cursorArgument: takesCursor(t) }));
|
|
24742
|
+
tools = served.map((t) => ({ name: String(t && t.name), description: t && typeof t.description === "string" ? t.description : undefined, cursorArgument: takesCursor(t), inputSchema: t && t.inputSchema && typeof t.inputSchema === "object" && !Array.isArray(t.inputSchema) ? t.inputSchema : undefined }));
|
|
23021
24743
|
const methods = ["tools/list"];
|
|
23022
24744
|
if (capabilities.resources) methods.push("resources/list", "resources/templates/list");
|
|
23023
24745
|
if (capabilities.prompts) methods.push("prompts/list");
|
|
@@ -23083,17 +24805,17 @@ const onMessage = (msg) => {
|
|
|
23083
24805
|
transport = plan.kind === "http" ? makeHttpTransport() : makeStdioTransport();
|
|
23084
24806
|
send({ jsonrpc: "2.0", id: 1, method: "initialize", params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "mcp-doctor", version: "0" } } });
|
|
23085
24807
|
`;
|
|
23086
|
-
var
|
|
24808
|
+
var isObj2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
23087
24809
|
var outcomeOf = (v) => v === "answered" || v === "refused" ? v : "no-answer";
|
|
23088
24810
|
function readServed(raw) {
|
|
23089
|
-
if (!
|
|
24811
|
+
if (!isObj2(raw)) return void 0;
|
|
23090
24812
|
const readList = (l) => {
|
|
23091
|
-
const r =
|
|
24813
|
+
const r = isObj2(l) ? l : {};
|
|
23092
24814
|
const method = typeof r.method === "string" ? r.method : "<unnamed list>";
|
|
23093
|
-
const fu =
|
|
24815
|
+
const fu = isObj2(r.followUp) ? r.followUp : void 0;
|
|
23094
24816
|
return {
|
|
23095
24817
|
method,
|
|
23096
|
-
outcome:
|
|
24818
|
+
outcome: isObj2(l) ? outcomeOf(r.outcome) : "no-answer",
|
|
23097
24819
|
...typeof r.detail === "string" ? { detail: r.detail } : {},
|
|
23098
24820
|
...Array.isArray(r.resultKeys) ? { resultKeys: r.resultKeys.map(String) } : {},
|
|
23099
24821
|
...r.resultType !== void 0 ? { resultType: r.resultType } : {},
|
|
@@ -23112,26 +24834,26 @@ function readServed(raw) {
|
|
|
23112
24834
|
};
|
|
23113
24835
|
const lists = (Array.isArray(raw.lists) ? raw.lists : []).map(readList);
|
|
23114
24836
|
const vp = raw.versionProbe;
|
|
23115
|
-
const versionProbe =
|
|
24837
|
+
const versionProbe = isObj2(vp) && vp.kind === "statuses" && typeof vp.supportedVersion === "string" && typeof vp.supported === "number" && typeof vp.unsupported === "number" ? {
|
|
23116
24838
|
kind: "statuses",
|
|
23117
24839
|
supportedVersion: vp.supportedVersion,
|
|
23118
24840
|
supported: vp.supported,
|
|
23119
24841
|
unsupported: vp.unsupported
|
|
23120
24842
|
} : {
|
|
23121
24843
|
kind: "not-run",
|
|
23122
|
-
reason:
|
|
24844
|
+
reason: isObj2(vp) && vp.kind === "not-run" && typeof vp.reason === "string" ? vp.reason : "unreadable version-probe record"
|
|
23123
24845
|
};
|
|
23124
24846
|
const as = raw.authServer;
|
|
23125
|
-
const authServer =
|
|
24847
|
+
const authServer = isObj2(as) && as.kind === "document" && typeof as.url === "string" && typeof as.status === "number" && isObj2(as.document) ? { kind: "document", url: as.url, status: as.status, document: as.document } : isObj2(as) && as.kind === "unavailable" && typeof as.url === "string" ? {
|
|
23126
24848
|
kind: "unavailable",
|
|
23127
24849
|
url: as.url,
|
|
23128
24850
|
reason: typeof as.reason === "string" ? as.reason : "no reason given"
|
|
23129
24851
|
} : {
|
|
23130
24852
|
kind: "not-run",
|
|
23131
|
-
reason:
|
|
24853
|
+
reason: isObj2(as) && as.kind === "not-run" && typeof as.reason === "string" ? as.reason : "unreadable authorization-server record"
|
|
23132
24854
|
};
|
|
23133
24855
|
return {
|
|
23134
|
-
capabilities:
|
|
24856
|
+
capabilities: isObj2(raw.capabilities) ? raw.capabilities : {},
|
|
23135
24857
|
...typeof raw.protocolVersion === "string" ? { protocolVersion: raw.protocolVersion } : {},
|
|
23136
24858
|
lists,
|
|
23137
24859
|
calls: (Array.isArray(raw.calls) ? raw.calls : []).map(readList),
|
|
@@ -23322,7 +25044,8 @@ function introspect(plan, root, evalSource, expectedCommit, evalsNote, secrets)
|
|
|
23322
25044
|
const count = evals.counts.get(name);
|
|
23323
25045
|
const base = t.description ? { name, description: t.description } : { name };
|
|
23324
25046
|
const withCursor = t.cursorArgument === true ? { ...base, cursorArgument: true } : base;
|
|
23325
|
-
|
|
25047
|
+
const withSchema = t.inputSchema ? { ...withCursor, inputSchema: t.inputSchema } : withCursor;
|
|
25048
|
+
return count === void 0 ? withSchema : { ...withSchema, evalCaseCount: count };
|
|
23326
25049
|
});
|
|
23327
25050
|
return {
|
|
23328
25051
|
root,
|