@vantageos/mcp-doctor 0.20.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +24 -111
- package/dist/doctor.d.ts +80 -0
- package/dist/doctor.js +2624 -333
- package/package.json +1 -1
package/dist/doctor.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
isJudgeable,
|
|
4
|
+
parseFile,
|
|
4
5
|
scanR4FilterPaths
|
|
5
6
|
} from "./chunk-OLW7SIJF.js";
|
|
6
7
|
|
|
7
8
|
// src/doctor.ts
|
|
8
|
-
import { readFileSync as
|
|
9
|
-
import { dirname as dirname19, join as
|
|
9
|
+
import { readFileSync as readFileSync28, realpathSync, statSync as statSync27 } from "fs";
|
|
10
|
+
import { dirname as dirname19, join as join37, resolve as resolve4 } from "path";
|
|
10
11
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
11
12
|
|
|
12
13
|
// src/scan.ts
|
|
@@ -798,6 +799,7 @@ var STANDARD_PIN = "1c66e11c43276df302d0d0689839172e598d7bcd";
|
|
|
798
799
|
var MANUFACT_RULES_PIN = "7e5513eff22c0e2174c100d26e0aa40f642a562f";
|
|
799
800
|
var C40_RULES_PIN = "941156e5734007188d1e3c54adadf3f1a3f84761";
|
|
800
801
|
var C19_RULES_PIN = "1596b8c552d8b836f4d6044569fb2e15c3bfe6cb";
|
|
802
|
+
var S51_RULES_PIN = "3b4982f7da3d34f0dc3bb42f8d3f3c5f9480943a";
|
|
801
803
|
|
|
802
804
|
// src/detectors/dLocalIdentity.ts
|
|
803
805
|
var CLOUD_IDENTITY_PACKAGE = "@vantageos/cloud-identity";
|
|
@@ -1022,8 +1024,8 @@ function isLocalContent(e, ctx, scopes, depth) {
|
|
|
1022
1024
|
const ch = x.match(/^(?:[\w$]+\s*\.\s*)?createHash\s*\(/);
|
|
1023
1025
|
if (ch) {
|
|
1024
1026
|
const c = callArgs(x, ch[0].length);
|
|
1025
|
-
const
|
|
1026
|
-
const d = c &&
|
|
1027
|
+
const up2 = c ? x.slice(c.end).match(/^\s*\.\s*update\s*\(/) : null;
|
|
1028
|
+
const d = c && up2 ? callArgs(x, c.end + up2[0].length) : null;
|
|
1027
1029
|
return d !== null && isLocalContent(d.args[0], ctx, scopes, depth + 1);
|
|
1028
1030
|
}
|
|
1029
1031
|
const sd = x.match(/^(?:[\w$]+\s*\.\s*)*subtle\s*\.\s*digest\s*\(/);
|
|
@@ -1384,7 +1386,7 @@ function localIdentityPositiveControls() {
|
|
|
1384
1386
|
}
|
|
1385
1387
|
function cloudIdentityBindings(file) {
|
|
1386
1388
|
const text = file.lines.map((l) => l.raw).join("\n");
|
|
1387
|
-
const
|
|
1389
|
+
const names2 = /* @__PURE__ */ new Set();
|
|
1388
1390
|
const namespaces = /* @__PURE__ */ new Set();
|
|
1389
1391
|
const pkg = `@vantageos\\/cloud-identity(?:\\/[^"']*)?`;
|
|
1390
1392
|
const named = new RegExp(`import\\s+(type\\s+)?\\{([^}]*)\\}\\s*from\\s*["']${pkg}["']`, "g");
|
|
@@ -1394,12 +1396,12 @@ function cloudIdentityBindings(file) {
|
|
|
1394
1396
|
const p = part.trim();
|
|
1395
1397
|
if (!p || p.startsWith("type ")) continue;
|
|
1396
1398
|
const as = p.match(/^[\w$]+\s+as\s+([\w$]+)$/);
|
|
1397
|
-
|
|
1399
|
+
names2.add(as ? as[1] : p);
|
|
1398
1400
|
}
|
|
1399
1401
|
}
|
|
1400
1402
|
const ns = new RegExp(`import\\s+\\*\\s+as\\s+([\\w$]+)\\s+from\\s*["']${pkg}["']`, "g");
|
|
1401
1403
|
for (const m of text.matchAll(ns)) namespaces.add(m[1]);
|
|
1402
|
-
return { names, namespaces };
|
|
1404
|
+
return { names: names2, namespaces };
|
|
1403
1405
|
}
|
|
1404
1406
|
function isDelegated(raw, start, callee, b) {
|
|
1405
1407
|
const before = raw.slice(0, start);
|
|
@@ -2102,11 +2104,12 @@ function isCodeAtCached(file, n, col) {
|
|
|
2102
2104
|
function wrapperDescriptionArg(tree, anchor) {
|
|
2103
2105
|
return scanWrappers(tree).descriptions.get(anchor);
|
|
2104
2106
|
}
|
|
2105
|
-
function findRegisteredTools(tree) {
|
|
2107
|
+
function findRegisteredTools(tree, inFile) {
|
|
2106
2108
|
const bindings = resolveNameBindings(tree);
|
|
2107
2109
|
const out = [];
|
|
2108
2110
|
const seen = /* @__PURE__ */ new Set();
|
|
2109
2111
|
const push = (name, anchor) => {
|
|
2112
|
+
if (inFile && !inFile(anchor.slice(0, anchor.lastIndexOf(":")))) return;
|
|
2110
2113
|
if (!seen.has(name)) {
|
|
2111
2114
|
seen.add(name);
|
|
2112
2115
|
out.push({ name, anchor });
|
|
@@ -2179,6 +2182,9 @@ function objectHasKey(lines2, at, indent) {
|
|
|
2179
2182
|
}
|
|
2180
2183
|
var TOOL_SURFACE_RE = /\bListToolsRequestSchema\b|["'`]tools\/list["'`]|\binputSchema\s*:|\bToolDefinition\b/;
|
|
2181
2184
|
function toolSurfaceAnchor(tree) {
|
|
2185
|
+
return toolMarkerAnchor(tree) ?? mcpDependencyAnchor(tree);
|
|
2186
|
+
}
|
|
2187
|
+
function toolMarkerAnchor(tree) {
|
|
2182
2188
|
for (const file of tree.files) {
|
|
2183
2189
|
for (const line of file.lines) {
|
|
2184
2190
|
if (line.comment) continue;
|
|
@@ -2187,8 +2193,45 @@ function toolSurfaceAnchor(tree) {
|
|
|
2187
2193
|
}
|
|
2188
2194
|
return null;
|
|
2189
2195
|
}
|
|
2196
|
+
var MCP_MODULE_RE = /mcp|modelcontextprotocol/i;
|
|
2197
|
+
var READER_COVERED_MODULES = ["@modelcontextprotocol/sdk"];
|
|
2198
|
+
var isUncoveredMcpModule = (spec) => MCP_MODULE_RE.test(spec) && !READER_COVERED_MODULES.some((m) => spec === m || spec.startsWith(`${m}/`));
|
|
2199
|
+
var MODULE_SPEC_RE = /\bfrom\s*["'`]([^"'`]+)["'`]|\brequire\s*\(\s*["'`]([^"'`]+)["'`]|\bimport\s*\(\s*["'`]([^"'`]+)["'`]|^\s*import\s*["'`]([^"'`]+)["'`]/;
|
|
2200
|
+
var DEPENDENCY_FIELDS = [
|
|
2201
|
+
"dependencies",
|
|
2202
|
+
"devDependencies",
|
|
2203
|
+
"peerDependencies",
|
|
2204
|
+
"optionalDependencies"
|
|
2205
|
+
];
|
|
2206
|
+
function mcpDependencyAnchor(tree) {
|
|
2207
|
+
const pj = tree.packageJson;
|
|
2208
|
+
if (pj?.unreadable)
|
|
2209
|
+
return `${pj.path} (unreadable: ${pj.unreadable}, so its MCP dependencies are unknown)`;
|
|
2210
|
+
if (pj) {
|
|
2211
|
+
for (const field of DEPENDENCY_FIELDS) {
|
|
2212
|
+
const deps = pj.json[field];
|
|
2213
|
+
if (typeof deps !== "object" || deps === null || Array.isArray(deps)) continue;
|
|
2214
|
+
const hit = Object.keys(deps).find(isUncoveredMcpModule);
|
|
2215
|
+
if (hit) return `${pj.path} ${field}.${hit}`;
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
for (const file of tree.files) {
|
|
2219
|
+
for (const line of file.lines) {
|
|
2220
|
+
if (line.comment) continue;
|
|
2221
|
+
const m = MODULE_SPEC_RE.exec(line.raw);
|
|
2222
|
+
const spec = m ? m[1] ?? m[2] ?? m[3] ?? m[4] : void 0;
|
|
2223
|
+
if (spec && !spec.startsWith(".") && isUncoveredMcpModule(spec))
|
|
2224
|
+
return `${file.rel}:${line.n}`;
|
|
2225
|
+
}
|
|
2226
|
+
}
|
|
2227
|
+
return null;
|
|
2228
|
+
}
|
|
2190
2229
|
function noToolsLocatedReason(tree, what) {
|
|
2191
|
-
|
|
2230
|
+
const searched = `searched ${tree.files.length} .ts/.tsx file(s) under ${tree.root} (all directories except node_modules/dist/build/tests/fixtures) for registerTool/.tool( calls and declarative { name, inputSchema } descriptors`;
|
|
2231
|
+
const dep = toolMarkerAnchor(tree) ? null : mcpDependencyAnchor(tree);
|
|
2232
|
+
if (dep)
|
|
2233
|
+
return `the tree builds on an MCP module (${dep}) but registers its tools through an API the reader does not recognise: ${searched}, and for the ListToolsRequestSchema / "tools/list" / inputSchema: / ToolDefinition markers \u2014 ${what}`;
|
|
2234
|
+
return `the tree serves MCP tools (tool-surface marker found) but no registered tool could be located: ${searched} \u2014 ${what}`;
|
|
2192
2235
|
}
|
|
2193
2236
|
var REGISTRATION_CALL_RE = /\b(?:s\.tool|\.tool|registerTool)\s*\(/;
|
|
2194
2237
|
function findUnresolvedToolSites(tree) {
|
|
@@ -2238,10 +2281,10 @@ function findUnresolvedToolSites(tree) {
|
|
|
2238
2281
|
function findListReadBuilders(tree) {
|
|
2239
2282
|
const bindings = resolveNameBindings(tree);
|
|
2240
2283
|
const extents = [];
|
|
2241
|
-
const endOf = (
|
|
2284
|
+
const endOf = (startLine2, startCol, text) => {
|
|
2242
2285
|
const lines2 = text.split("\n");
|
|
2243
2286
|
const last = lines2.length - 1;
|
|
2244
|
-
return [
|
|
2287
|
+
return [startLine2 + last, last === 0 ? startCol + text.length - 1 : lines2[last].length - 1];
|
|
2245
2288
|
};
|
|
2246
2289
|
for (const site of codeSites(tree, /(?:\.tool|\bregisterTool)\s*\(/g)) {
|
|
2247
2290
|
const open = site.col + site.match[0].lastIndexOf("(");
|
|
@@ -2449,15 +2492,15 @@ function callOpenerLine(file, siteLine) {
|
|
|
2449
2492
|
return siteLine;
|
|
2450
2493
|
}
|
|
2451
2494
|
function ownCallEnd(file, siteLine) {
|
|
2452
|
-
const
|
|
2495
|
+
const startLine2 = callOpenerLine(file, siteLine);
|
|
2453
2496
|
let depth = 0;
|
|
2454
2497
|
for (const line of file.lines) {
|
|
2455
|
-
if (line.n <
|
|
2498
|
+
if (line.n < startLine2) continue;
|
|
2456
2499
|
if (!line.comment) {
|
|
2457
2500
|
depth += (line.raw.match(/\(/g) ?? []).length - (line.raw.match(/\)/g) ?? []).length;
|
|
2458
2501
|
}
|
|
2459
|
-
if (line.n >=
|
|
2460
|
-
if (line.n ===
|
|
2502
|
+
if (line.n >= startLine2 && depth <= 0 && line.n > startLine2) return line.n;
|
|
2503
|
+
if (line.n === startLine2 && depth <= 0) {
|
|
2461
2504
|
return line.n;
|
|
2462
2505
|
}
|
|
2463
2506
|
}
|
|
@@ -2712,14 +2755,14 @@ function governingWorkflows(tree) {
|
|
|
2712
2755
|
if (existsSync3(wf)) {
|
|
2713
2756
|
const out = [];
|
|
2714
2757
|
const base = baseOf(tree);
|
|
2715
|
-
let
|
|
2758
|
+
let names2;
|
|
2716
2759
|
try {
|
|
2717
|
-
|
|
2760
|
+
names2 = readdirSync3(wf).sort();
|
|
2718
2761
|
} catch (err) {
|
|
2719
2762
|
recordSkip(tree, wf, base, `could not be listed (${fsErrorCode(err)}) \u2014 not read`);
|
|
2720
2763
|
return out;
|
|
2721
2764
|
}
|
|
2722
|
-
for (const name of
|
|
2765
|
+
for (const name of names2) {
|
|
2723
2766
|
if (!/\.ya?ml$/.test(name)) continue;
|
|
2724
2767
|
const full = join3(wf, name);
|
|
2725
2768
|
try {
|
|
@@ -3032,13 +3075,13 @@ var a4WcagGate = {
|
|
|
3032
3075
|
const workflowRun = governingWorkflows(tree).find(
|
|
3033
3076
|
(w) => /\baxe\b|axe-core/i.test(stripYamlComments(w.text))
|
|
3034
3077
|
);
|
|
3035
|
-
const
|
|
3036
|
-
const testRun =
|
|
3078
|
+
const testFiles3 = diskText(tree, (name) => /\.(?:test|spec)\.[jt]sx?$/.test(name));
|
|
3079
|
+
const testRun = testFiles3.find(
|
|
3037
3080
|
(f) => /\baxe\b|axe-core|jest-axe|vitest-axe/i.test(stripJsComments(f.text))
|
|
3038
3081
|
);
|
|
3039
3082
|
const refusedInputs = [
|
|
3040
3083
|
...refusedAsUnreadable(pkgs.refused, "its axe dependency and scripts are unread"),
|
|
3041
|
-
...refusedAsUnreadable(
|
|
3084
|
+
...refusedAsUnreadable(testFiles3.refused, "a test file that may run axe is unread"),
|
|
3042
3085
|
...refusedAsUnreadable(htmlShells.refused, "an HTML shell of the App is unread")
|
|
3043
3086
|
];
|
|
3044
3087
|
const run13 = scriptRun ?? (workflowRun ? workflowRun.rel : null) ?? (testRun ? testRun.rel : null);
|
|
@@ -4113,12 +4156,12 @@ function wrapperProof(s, server, mine) {
|
|
|
4113
4156
|
const pClose = matchClose(m, pOpen);
|
|
4114
4157
|
if (pClose < 0) return "the parameter list is unbalanced";
|
|
4115
4158
|
const params = splitList(m, pOpen + 1, pClose);
|
|
4116
|
-
const
|
|
4159
|
+
const names2 = [];
|
|
4117
4160
|
for (const p of params) {
|
|
4118
4161
|
const id = /^(\.\.\.)?\s*([A-Za-z_$][\w$]*)/.exec(p);
|
|
4119
4162
|
if (!id) return "a destructured parameter";
|
|
4120
4163
|
if (/=>/.test(p)) return "a function type in the parameter list";
|
|
4121
|
-
|
|
4164
|
+
names2.push(`${id[1] ?? ""}${id[2]}`);
|
|
4122
4165
|
}
|
|
4123
4166
|
const tail = m.slice(pClose + 1);
|
|
4124
4167
|
const arrow = /^\s*(?::[^=>{]*)?=>\s*/.exec(tail);
|
|
@@ -4170,9 +4213,9 @@ function wrapperProof(s, server, mine) {
|
|
|
4170
4213
|
const argsClose = matchClose(m, argsOpen);
|
|
4171
4214
|
if (argsClose < 0) return "the forwarding call is unbalanced";
|
|
4172
4215
|
const args = splitList(m, argsOpen + 1, argsClose);
|
|
4173
|
-
if (args.length !==
|
|
4174
|
-
return `the wrapper does not forward exactly its own parameters (${
|
|
4175
|
-
return untouchedParams(s, params,
|
|
4216
|
+
if (args.length !== names2.length || args.some((a, i) => a !== names2[i]))
|
|
4217
|
+
return `the wrapper does not forward exactly its own parameters (${names2.join(", ")}) to \`${alias}\``;
|
|
4218
|
+
return untouchedParams(s, params, names2, bStart, bEnd, argsOpen, argsClose);
|
|
4176
4219
|
}
|
|
4177
4220
|
function methodArgumentRead(shape, o) {
|
|
4178
4221
|
const before = shape.slice(Math.max(0, o - 80), o);
|
|
@@ -4207,11 +4250,11 @@ function decoratorProof(s, server, mine) {
|
|
|
4207
4250
|
const pOpen = rhsAt + head[0].length - 1;
|
|
4208
4251
|
const pClose = matchClose(m, pOpen);
|
|
4209
4252
|
if (pClose < 0) return "the parameter list is unbalanced";
|
|
4210
|
-
const
|
|
4211
|
-
if (
|
|
4253
|
+
const names2 = splitList(m, pOpen + 1, pClose).map((p) => /^\s*([A-Za-z_$][\w$]*)/.exec(p)?.[1]);
|
|
4254
|
+
if (names2.length < 2 || names2.some((n) => n === void 0))
|
|
4212
4255
|
return "the parameters are not plain names";
|
|
4213
|
-
const first =
|
|
4214
|
-
const handler =
|
|
4256
|
+
const first = names2[0];
|
|
4257
|
+
const handler = names2[names2.length - 1];
|
|
4215
4258
|
const tail = m.slice(pClose + 1);
|
|
4216
4259
|
const arrow = /^\s*(?::[^=>{]*)?=>\s*\{/.exec(tail);
|
|
4217
4260
|
const fnBody = arrow ? void 0 : /^\s*(?::[^{]*)?\{/.exec(tail);
|
|
@@ -4254,7 +4297,7 @@ function enclosingOpens(m, at, lo) {
|
|
|
4254
4297
|
}
|
|
4255
4298
|
return out;
|
|
4256
4299
|
}
|
|
4257
|
-
function untouchedParams(s, params,
|
|
4300
|
+
function untouchedParams(s, params, names2, bStart, bEnd, fwdOpen, fwdClose) {
|
|
4258
4301
|
const m = s.shape;
|
|
4259
4302
|
const stmt = (i) => {
|
|
4260
4303
|
let a = i;
|
|
@@ -4266,8 +4309,8 @@ function untouchedParams(s, params, names, bStart, bEnd, fwdOpen, fwdClose) {
|
|
|
4266
4309
|
const argsUse = /(?<![\w$.])arguments(?![\w$])/g.exec(m.slice(bStart, bEnd));
|
|
4267
4310
|
if (argsUse)
|
|
4268
4311
|
return `the wrapper reads \`arguments\`, which aliases its parameters: ${stmt(bStart + argsUse.index)}`;
|
|
4269
|
-
for (let k = 0; k <
|
|
4270
|
-
const id =
|
|
4312
|
+
for (let k = 0; k < names2.length; k++) {
|
|
4313
|
+
const id = names2[k].replace(/^\.\.\./, "");
|
|
4271
4314
|
const decl = params[k].replace(/^\.\.\.\s*/, "");
|
|
4272
4315
|
const typed = /^[A-Za-z_$][\w$]*\s*\??\s*:\s*([^=]*?)\s*(?:=(?![=>]).*)?$/s.exec(decl);
|
|
4273
4316
|
const primitive = typed !== void 0 && typed !== null && PRIMITIVE_TYPE.test(typed[1]);
|
|
@@ -5084,28 +5127,28 @@ var requesting = /* @__PURE__ */ new WeakMap();
|
|
|
5084
5127
|
function requestingFunctions(tree) {
|
|
5085
5128
|
const hit = requesting.get(tree);
|
|
5086
5129
|
if (hit) return hit;
|
|
5087
|
-
const
|
|
5130
|
+
const names2 = /* @__PURE__ */ new Map();
|
|
5088
5131
|
const add = (n, s) => {
|
|
5089
|
-
const set =
|
|
5132
|
+
const set = names2.get(n) ?? /* @__PURE__ */ new Set();
|
|
5090
5133
|
const had = set.has(s);
|
|
5091
5134
|
set.add(s);
|
|
5092
|
-
|
|
5135
|
+
names2.set(n, set);
|
|
5093
5136
|
return !had;
|
|
5094
5137
|
};
|
|
5095
5138
|
for (const c of upstreamSurface(tree).calls)
|
|
5096
5139
|
for (const f of enclosingFns(c.src, c.start)) if (f.name) add(f.name, c.src);
|
|
5097
5140
|
for (let round = 0; round < 6; round++) {
|
|
5098
5141
|
let grew = false;
|
|
5099
|
-
for (const n of [...
|
|
5142
|
+
for (const n of [...names2.keys()]) {
|
|
5100
5143
|
for (const c of callsMatching(tree, new RegExp(String.raw`^(?:[\w$]+\.)*${esc2(n)}$`))) {
|
|
5101
|
-
if (!callReaches(c.src, c.callee, n,
|
|
5144
|
+
if (!callReaches(c.src, c.callee, n, names2.get(n))) continue;
|
|
5102
5145
|
for (const f of enclosingFns(c.src, c.start)) if (f.name && add(f.name, c.src)) grew = true;
|
|
5103
5146
|
}
|
|
5104
5147
|
}
|
|
5105
5148
|
if (!grew) break;
|
|
5106
5149
|
}
|
|
5107
|
-
requesting.set(tree,
|
|
5108
|
-
return
|
|
5150
|
+
requesting.set(tree, names2);
|
|
5151
|
+
return names2;
|
|
5109
5152
|
}
|
|
5110
5153
|
function callReaches(s, callee, name, defs) {
|
|
5111
5154
|
if (callee.includes(".")) return true;
|
|
@@ -5821,7 +5864,7 @@ function symbolConst(file, name) {
|
|
|
5821
5864
|
);
|
|
5822
5865
|
return uncommentedLines(file).some((row) => re.test(row));
|
|
5823
5866
|
}
|
|
5824
|
-
function computedKeys(file, lineNo,
|
|
5867
|
+
function computedKeys(file, lineNo, names2, out) {
|
|
5825
5868
|
const raw = file.lines[lineNo - 1].raw;
|
|
5826
5869
|
for (let col = raw.indexOf("["); col >= 0; col = raw.indexOf("[", col + 1)) {
|
|
5827
5870
|
if (!isCodeAt(file, lineNo, col)) continue;
|
|
@@ -5836,14 +5879,14 @@ function computedKeys(file, lineNo, names, out) {
|
|
|
5836
5879
|
const lit = expr.match(/^(["'`])((?:\\.|(?!\1)[^\\])*)\1$/);
|
|
5837
5880
|
const anchor = `${file.rel}:${lineNo}`;
|
|
5838
5881
|
if (lit && !(lit[1] === "`" && lit[2].includes("${"))) {
|
|
5839
|
-
if (
|
|
5882
|
+
if (names2.includes(lit[2])) keyInBrace(file, lineNo, col, lit[2], "computed-key", out);
|
|
5840
5883
|
continue;
|
|
5841
5884
|
}
|
|
5842
5885
|
if (/^[A-Za-z_$][\w$]*$/.test(expr) && symbolConst(file, expr)) continue;
|
|
5843
5886
|
if (/^[A-Za-z_$][\w$]*$/.test(expr)) {
|
|
5844
5887
|
const bound = constString(file, expr);
|
|
5845
5888
|
if (bound.kind === "value") {
|
|
5846
|
-
if (bound.value !== null &&
|
|
5889
|
+
if (bound.value !== null && names2.includes(bound.value)) {
|
|
5847
5890
|
keyInBrace(file, lineNo, col, bound.value, "computed-key", out);
|
|
5848
5891
|
}
|
|
5849
5892
|
continue;
|
|
@@ -5864,9 +5907,9 @@ function computedKeys(file, lineNo, names, out) {
|
|
|
5864
5907
|
}
|
|
5865
5908
|
}
|
|
5866
5909
|
}
|
|
5867
|
-
function fieldWrites(tree,
|
|
5910
|
+
function fieldWrites(tree, names2) {
|
|
5868
5911
|
const out = { writes: [], unread: [], computed: [] };
|
|
5869
|
-
const alt =
|
|
5912
|
+
const alt = names2.map((n) => n.replace(/[$]/g, "\\$&")).join("|");
|
|
5870
5913
|
const identRe = new RegExp(`(?<![\\w$])(${alt})(?![\\w$])`, "g");
|
|
5871
5914
|
const quotedRe = new RegExp(`(["'])(${alt})\\1`, "g");
|
|
5872
5915
|
for (const file of tree.files) {
|
|
@@ -5902,7 +5945,7 @@ function fieldWrites(tree, names) {
|
|
|
5902
5945
|
keyInBrace(file, line.n, col, name, "shorthand", out);
|
|
5903
5946
|
}
|
|
5904
5947
|
}
|
|
5905
|
-
computedKeys(file, line.n,
|
|
5948
|
+
computedKeys(file, line.n, names2, out);
|
|
5906
5949
|
for (const m of line.raw.matchAll(quotedRe)) {
|
|
5907
5950
|
const col = m.index ?? 0;
|
|
5908
5951
|
if (!isCodeAt(file, line.n, col)) continue;
|
|
@@ -6615,16 +6658,16 @@ function hostToolProblems(tree) {
|
|
|
6615
6658
|
const unresolvedSites = findUnresolvedToolSites(tree);
|
|
6616
6659
|
const named = [];
|
|
6617
6660
|
for (const c of caps) {
|
|
6618
|
-
for (const
|
|
6619
|
-
if (c.key !==
|
|
6661
|
+
for (const ts6 of TOOL_SETTINGS) {
|
|
6662
|
+
if (c.key !== ts6.cap) continue;
|
|
6620
6663
|
const m = c.body.match(
|
|
6621
|
-
new RegExp(`["'\`]?${
|
|
6664
|
+
new RegExp(`["'\`]?${ts6.setting}["'\`]?\\s*:\\s*["'\`]([^"'\`]+)["'\`]`)
|
|
6622
6665
|
);
|
|
6623
6666
|
if (m)
|
|
6624
6667
|
named.push({
|
|
6625
6668
|
name: m[1],
|
|
6626
|
-
kind:
|
|
6627
|
-
from: `${
|
|
6669
|
+
kind: ts6.kind,
|
|
6670
|
+
from: `${ts6.cap}.${ts6.setting}`,
|
|
6628
6671
|
anchor: c.anchor
|
|
6629
6672
|
});
|
|
6630
6673
|
}
|
|
@@ -7644,13 +7687,13 @@ var MECHANISM_BASE_SET = /* @__PURE__ */ new Set([
|
|
|
7644
7687
|
]);
|
|
7645
7688
|
var isDataLayerFile = (rel) => /(^|\/)convex\//.test(rel);
|
|
7646
7689
|
function judgeIndexedFromSource(tree, id, indexed) {
|
|
7647
|
-
const
|
|
7690
|
+
const names2 = indexed.map((t) => `"${t.name}" (${t.searchMechanism})`).join(", ");
|
|
7648
7691
|
const dataLayer = tree.files.filter((f) => isJudgeable(f) && isDataLayerFile(f.rel));
|
|
7649
7692
|
if (dataLayer.length === 0) {
|
|
7650
7693
|
return couldNotJudge(
|
|
7651
7694
|
id,
|
|
7652
7695
|
indexed[0].anchor,
|
|
7653
|
-
`${indexed.length} list/search tool(s) claim an indexed mechanism (${
|
|
7696
|
+
`${indexed.length} list/search tool(s) claim an indexed mechanism (${names2}) and no data-layer source is in the tree (convex/ files read: 0): no implementation confirms the declaration, and C-10 reads a data layer through backend R-4 (Convex only) (C-10)`
|
|
7654
7697
|
);
|
|
7655
7698
|
}
|
|
7656
7699
|
const scan = scanR4FilterPaths(tree.files);
|
|
@@ -7660,7 +7703,7 @@ function judgeIndexedFromSource(tree, id, indexed) {
|
|
|
7660
7703
|
id,
|
|
7661
7704
|
anchor: `${scan.violate[0].rel}:${scan.violate[0].n}`,
|
|
7662
7705
|
state: "non-conforming",
|
|
7663
|
-
verdict: `${indexed.length} list/search tool(s) claim an indexed mechanism (${
|
|
7706
|
+
verdict: `${indexed.length} list/search tool(s) claim an indexed mechanism (${names2}) while ${scan.violate.length} filter path(s) of the data layer scan (read through backend R-4): ${shown.join(" | ")}${scan.violate.length > 3 ? ` | and ${scan.violate.length - 3} more` : ""} -> bound the filtered field in the index range, or declare what the path does (C-10)`
|
|
7664
7707
|
};
|
|
7665
7708
|
}
|
|
7666
7709
|
if (scan.cnj.length > 0) {
|
|
@@ -7668,14 +7711,14 @@ function judgeIndexedFromSource(tree, id, indexed) {
|
|
|
7668
7711
|
return couldNotJudge(
|
|
7669
7712
|
id,
|
|
7670
7713
|
`${first.rel}:${first.n}`,
|
|
7671
|
-
`${scan.cnj.length} filter path(s) of the data layer could not be read through backend R-4 (first: ${first.note}): whether they answer the indexed claim of ${
|
|
7714
|
+
`${scan.cnj.length} filter path(s) of the data layer could not be read through backend R-4 (first: ${first.note}): whether they answer the indexed claim of ${names2} is undecided (C-10)`
|
|
7672
7715
|
);
|
|
7673
7716
|
}
|
|
7674
7717
|
if (scan.reads === 0) {
|
|
7675
7718
|
return couldNotJudge(
|
|
7676
7719
|
id,
|
|
7677
7720
|
indexed[0].anchor,
|
|
7678
|
-
`${indexed.length} list/search tool(s) claim an indexed mechanism (${
|
|
7721
|
+
`${indexed.length} list/search tool(s) claim an indexed mechanism (${names2}) and backend R-4 found no list read in a public query door among ${dataLayer.length} convex file(s): no implementation confirms the declaration (C-10)`
|
|
7679
7722
|
);
|
|
7680
7723
|
}
|
|
7681
7724
|
return void 0;
|
|
@@ -8207,7 +8250,7 @@ var Parser = class _Parser {
|
|
|
8207
8250
|
return sub.parseExpr();
|
|
8208
8251
|
}
|
|
8209
8252
|
paramNames(from, to) {
|
|
8210
|
-
const
|
|
8253
|
+
const names2 = [];
|
|
8211
8254
|
let depth = 0;
|
|
8212
8255
|
let expectName = true;
|
|
8213
8256
|
for (let j = from; j < to; j++) {
|
|
@@ -8219,11 +8262,11 @@ var Parser = class _Parser {
|
|
|
8219
8262
|
continue;
|
|
8220
8263
|
}
|
|
8221
8264
|
if (depth === 0 && expectName && t.t === "id") {
|
|
8222
|
-
|
|
8265
|
+
names2.push(t.v);
|
|
8223
8266
|
expectName = false;
|
|
8224
8267
|
}
|
|
8225
8268
|
}
|
|
8226
|
-
return
|
|
8269
|
+
return names2;
|
|
8227
8270
|
}
|
|
8228
8271
|
parsePostfix() {
|
|
8229
8272
|
let node = this.parsePrimary();
|
|
@@ -8668,9 +8711,9 @@ function moduleCtx(file, tree, from) {
|
|
|
8668
8711
|
resolving: from ? from.resolving : /* @__PURE__ */ new Set()
|
|
8669
8712
|
};
|
|
8670
8713
|
}
|
|
8671
|
-
function flatten(
|
|
8714
|
+
function flatten(branches2) {
|
|
8672
8715
|
const out = [];
|
|
8673
|
-
for (const b of
|
|
8716
|
+
for (const b of branches2) {
|
|
8674
8717
|
if (b.k === "union") out.push(...flatten(b.branches));
|
|
8675
8718
|
else out.push(b);
|
|
8676
8719
|
}
|
|
@@ -9133,12 +9176,12 @@ function walk2(s, path, useAt, out, loc) {
|
|
|
9133
9176
|
const offsetsFor = (...offs) => offs.filter((o) => o !== void 0);
|
|
9134
9177
|
switch (s.k) {
|
|
9135
9178
|
case "union": {
|
|
9136
|
-
const
|
|
9137
|
-
const arrays =
|
|
9138
|
-
const others =
|
|
9179
|
+
const branches2 = flatten(s.branches);
|
|
9180
|
+
const arrays = branches2.filter((b) => b.k === "array").length;
|
|
9181
|
+
const others = branches2.filter(
|
|
9139
9182
|
(b) => b.k !== "array" && b.k !== "null" && b.k !== "unread"
|
|
9140
9183
|
).length;
|
|
9141
|
-
const unreadB =
|
|
9184
|
+
const unreadB = branches2.filter((b) => b.k === "unread");
|
|
9142
9185
|
if (arrays > 0 && others > 0) {
|
|
9143
9186
|
const use = loc(useAt ?? s.at);
|
|
9144
9187
|
const origin = loc(s.at ?? useAt);
|
|
@@ -9158,7 +9201,7 @@ function walk2(s, path, useAt, out, loc) {
|
|
|
9158
9201
|
anchor: loc(unreadB[0].at ?? s.at ?? useAt).anchor
|
|
9159
9202
|
});
|
|
9160
9203
|
}
|
|
9161
|
-
for (const b of
|
|
9204
|
+
for (const b of branches2) if (b.k !== "unread") walk2(b, path, useAt, out, loc);
|
|
9162
9205
|
return;
|
|
9163
9206
|
}
|
|
9164
9207
|
case "array":
|
|
@@ -9435,9 +9478,7 @@ function runStatic(tree) {
|
|
|
9435
9478
|
`S43 positive control FAILED: sees=${controls.sees} spares=${controls.spares} \u2014 reader broken, verdict untrustworthy`
|
|
9436
9479
|
);
|
|
9437
9480
|
}
|
|
9438
|
-
const tools = findRegisteredTools(tree)
|
|
9439
|
-
(t) => isProductSource(t.anchor.slice(0, t.anchor.lastIndexOf(":")))
|
|
9440
|
-
);
|
|
9481
|
+
const tools = findRegisteredTools(tree, isProductSource);
|
|
9441
9482
|
const unresolvedTools = findUnresolvedToolSites(tree).filter(
|
|
9442
9483
|
(a) => isProductSource(a.slice(0, a.lastIndexOf(":")))
|
|
9443
9484
|
);
|
|
@@ -10094,14 +10135,14 @@ function judgeDeclaration(byAnnotation, schema) {
|
|
|
10094
10135
|
return { missing, unread: unread2 };
|
|
10095
10136
|
}
|
|
10096
10137
|
if (!byAnnotation.cursor && !schema.cursor) missing.push("cursor");
|
|
10097
|
-
const
|
|
10138
|
+
const num2 = (declared, n, label2, finite) => {
|
|
10098
10139
|
if (declared) return;
|
|
10099
10140
|
if (n.kind === "literal" && (!finite || Number.isFinite(n.value))) return;
|
|
10100
10141
|
if (n.kind === "unread") unread2.push(`${label2} unread (${n.form})`);
|
|
10101
10142
|
else missing.push(label2);
|
|
10102
10143
|
};
|
|
10103
|
-
|
|
10104
|
-
|
|
10144
|
+
num2(byAnnotation.def, schema.limitDefault, "default", false);
|
|
10145
|
+
num2(byAnnotation.max, schema.limitMax, "finite max", true);
|
|
10105
10146
|
return { missing, unread: unread2 };
|
|
10106
10147
|
}
|
|
10107
10148
|
|
|
@@ -11354,8 +11395,8 @@ function importedModule(file, fn) {
|
|
|
11354
11395
|
const text = file.lines.map((l) => l.raw).join("\n");
|
|
11355
11396
|
const re = /import\s*\{([^}]*)\}\s*from\s*["'](\.{1,2}\/[^"']+)["']/g;
|
|
11356
11397
|
for (const m of text.matchAll(re)) {
|
|
11357
|
-
const
|
|
11358
|
-
const local =
|
|
11398
|
+
const names2 = m[1].split(",").map((s) => s.trim().replace(/^type\s+/, ""));
|
|
11399
|
+
const local = names2.map(
|
|
11359
11400
|
(n) => n.split(/\s+as\s+/).pop()?.trim()
|
|
11360
11401
|
);
|
|
11361
11402
|
if (!local.includes(fn)) continue;
|
|
@@ -13155,15 +13196,15 @@ function filesUnder(dir, unread2, rel) {
|
|
|
13155
13196
|
const out = /* @__PURE__ */ new Map();
|
|
13156
13197
|
let incomplete = false;
|
|
13157
13198
|
const walk3 = (d, prefix) => {
|
|
13158
|
-
let
|
|
13199
|
+
let names2;
|
|
13159
13200
|
try {
|
|
13160
|
-
|
|
13201
|
+
names2 = readdirSync8(d);
|
|
13161
13202
|
} catch (e) {
|
|
13162
13203
|
unread2.push({ anchor: rel, reason: `${prefix || "."} not listed (${e.message})` });
|
|
13163
13204
|
incomplete = true;
|
|
13164
13205
|
return;
|
|
13165
13206
|
}
|
|
13166
|
-
for (const n of
|
|
13207
|
+
for (const n of names2.sort()) {
|
|
13167
13208
|
const full = join12(d, n);
|
|
13168
13209
|
const r = prefix ? `${prefix}/${n}` : n;
|
|
13169
13210
|
try {
|
|
@@ -13208,12 +13249,12 @@ function packageSkillProblems(tree, skillFiles, unread2) {
|
|
|
13208
13249
|
if (packages.length === 0 || skillFiles.length === 0) return [];
|
|
13209
13250
|
const skillsRoot = (pkg) => pkg ? `${pkg}/skills` : "skills";
|
|
13210
13251
|
const inPackage = (rel) => packages.some((p) => rel.startsWith(`${skillsRoot(p)}/`));
|
|
13211
|
-
const
|
|
13252
|
+
const names2 = [...new Set(skillFiles.map((s) => s.dir))].sort();
|
|
13212
13253
|
const out = [];
|
|
13213
13254
|
for (const pkg of packages) {
|
|
13214
13255
|
const at = pkg || ".";
|
|
13215
13256
|
const missing = [];
|
|
13216
|
-
for (const name of
|
|
13257
|
+
for (const name of names2) {
|
|
13217
13258
|
const rel = `${skillsRoot(pkg)}/${name}/SKILL.md`;
|
|
13218
13259
|
const copy = skillFiles.find((s) => s.rel === rel);
|
|
13219
13260
|
if (!copy) {
|
|
@@ -14035,14 +14076,14 @@ function testFiles(tree, unread2) {
|
|
|
14035
14076
|
const base = baseOf(tree);
|
|
14036
14077
|
const out = [];
|
|
14037
14078
|
const walk3 = (dir, rel) => {
|
|
14038
|
-
let
|
|
14079
|
+
let names2;
|
|
14039
14080
|
try {
|
|
14040
|
-
|
|
14081
|
+
names2 = readdirSync10(dir);
|
|
14041
14082
|
} catch (err) {
|
|
14042
14083
|
unread2.push(`${rel}/ (not listed: ${err.message})`);
|
|
14043
14084
|
return;
|
|
14044
14085
|
}
|
|
14045
|
-
for (const name of
|
|
14086
|
+
for (const name of names2) {
|
|
14046
14087
|
if (name === "node_modules") continue;
|
|
14047
14088
|
const full = join14(dir, name);
|
|
14048
14089
|
let st;
|
|
@@ -14308,15 +14349,15 @@ function run3(tree) {
|
|
|
14308
14349
|
if (registered2.length === 0 && listed.length > 0)
|
|
14309
14350
|
v.unread.push("no tool registration located in the tree: the kit's tools are not compared");
|
|
14310
14351
|
else {
|
|
14311
|
-
const
|
|
14312
|
-
const missing = registered2.filter((n) => !
|
|
14313
|
-
const extra =
|
|
14352
|
+
const names2 = listed.map((t) => t.name);
|
|
14353
|
+
const missing = registered2.filter((n) => !names2.includes(n));
|
|
14354
|
+
const extra = names2.filter((n) => !registered2.includes(n));
|
|
14314
14355
|
if (missing.length > 0)
|
|
14315
14356
|
v.red.push(`${KIT} omits the registered tool(s) ${missing.join(", ")}`);
|
|
14316
14357
|
if (extra.length > 0)
|
|
14317
14358
|
v.red.push(`${KIT} lists ${extra.join(", ")}, which the tree registers nowhere`);
|
|
14318
14359
|
if (missing.length + extra.length === 0)
|
|
14319
|
-
v.ok.push(`${
|
|
14360
|
+
v.ok.push(`${names2.length} tool(s) listed, one per registration`);
|
|
14320
14361
|
}
|
|
14321
14362
|
const deferred = [];
|
|
14322
14363
|
for (const k of listed) {
|
|
@@ -14374,9 +14415,9 @@ function runServed2(runtime) {
|
|
|
14374
14415
|
if (!listed) v.red.push(`${KIT} has no tools[]`);
|
|
14375
14416
|
else {
|
|
14376
14417
|
const served = runtime.tools;
|
|
14377
|
-
const
|
|
14378
|
-
const missing = served.filter((t) => !
|
|
14379
|
-
const extra =
|
|
14418
|
+
const names2 = listed.map((t) => t.name);
|
|
14419
|
+
const missing = served.filter((t) => !names2.includes(t.name)).map((t) => t.name);
|
|
14420
|
+
const extra = names2.filter((n) => !served.some((t) => t.name === n));
|
|
14380
14421
|
if (missing.length > 0) v.red.push(`${KIT} omits the served tool(s) ${missing.join(", ")}`);
|
|
14381
14422
|
if (extra.length > 0)
|
|
14382
14423
|
v.red.push(`${KIT} lists ${extra.join(", ")}, which the server does not serve`);
|
|
@@ -14462,9 +14503,9 @@ function runStatic2(tree) {
|
|
|
14462
14503
|
state: "absent",
|
|
14463
14504
|
verdict: `"private": true: not published to npm \u2014 ${RULE5} n/a`
|
|
14464
14505
|
};
|
|
14465
|
-
let
|
|
14506
|
+
let names2;
|
|
14466
14507
|
try {
|
|
14467
|
-
|
|
14508
|
+
names2 = readdirSync11(tree.root).filter((n) => README_RE.test(n));
|
|
14468
14509
|
} catch (err) {
|
|
14469
14510
|
return couldNotJudge(
|
|
14470
14511
|
ID5,
|
|
@@ -14472,7 +14513,7 @@ function runStatic2(tree) {
|
|
|
14472
14513
|
`the package root could not be listed (${fsErrorCode(err)}) (${RULE5})`
|
|
14473
14514
|
);
|
|
14474
14515
|
}
|
|
14475
|
-
if (
|
|
14516
|
+
if (names2.length === 0)
|
|
14476
14517
|
return {
|
|
14477
14518
|
id: ID5,
|
|
14478
14519
|
anchor: tree.root,
|
|
@@ -14480,7 +14521,7 @@ function runStatic2(tree) {
|
|
|
14480
14521
|
verdict: `no README (no readme* file) at the package root: nothing to measure (its presence is C-1 / C-31's subject) \u2014 ${RULE5} n/a`
|
|
14481
14522
|
};
|
|
14482
14523
|
const sized = [];
|
|
14483
|
-
for (const name of
|
|
14524
|
+
for (const name of names2.sort()) {
|
|
14484
14525
|
const path = join16(tree.root, name);
|
|
14485
14526
|
try {
|
|
14486
14527
|
const st = lstatSync(path);
|
|
@@ -14861,9 +14902,9 @@ function nested(node, path) {
|
|
|
14861
14902
|
if (isObj3(node.properties)) out.push(...fieldsOf(node, path));
|
|
14862
14903
|
if (isObj3(node.items)) out.push(...nested(node.items, `${path}[]`));
|
|
14863
14904
|
for (const k of ["anyOf", "oneOf", "allOf"]) {
|
|
14864
|
-
const
|
|
14865
|
-
if (Array.isArray(
|
|
14866
|
-
for (const b of
|
|
14905
|
+
const branches2 = node[k];
|
|
14906
|
+
if (Array.isArray(branches2)) {
|
|
14907
|
+
for (const b of branches2) if (isObj3(b)) out.push(...nested(b, path));
|
|
14867
14908
|
}
|
|
14868
14909
|
}
|
|
14869
14910
|
return out;
|
|
@@ -14928,15 +14969,192 @@ function sourced(d, served) {
|
|
|
14928
14969
|
if (/["'`][^"'`\s]{1,64}["'`]/.test(d)) return true;
|
|
14929
14970
|
return /\b(name|ID)\b/.test(d);
|
|
14930
14971
|
}
|
|
14931
|
-
|
|
14972
|
+
var IDENT3 = "[A-Za-z_$][A-Za-z0-9_$]*";
|
|
14973
|
+
var OPEN2 = { "{": "}", "[": "]", "(": ")" };
|
|
14974
|
+
function closeOf2(s, i) {
|
|
14975
|
+
const stack = [];
|
|
14976
|
+
for (let j = i; j < s.length; j++) {
|
|
14977
|
+
const c = s[j];
|
|
14978
|
+
if (OPEN2[c]) stack.push(OPEN2[c]);
|
|
14979
|
+
else if (c === "}" || c === "]" || c === ")") {
|
|
14980
|
+
if (stack.pop() !== c) return -1;
|
|
14981
|
+
if (stack.length === 0) return j;
|
|
14982
|
+
}
|
|
14983
|
+
}
|
|
14984
|
+
return -1;
|
|
14985
|
+
}
|
|
14986
|
+
function splitTop2(s) {
|
|
14932
14987
|
const out = [];
|
|
14933
|
-
|
|
14934
|
-
|
|
14935
|
-
|
|
14936
|
-
|
|
14988
|
+
let depth = 0;
|
|
14989
|
+
let cur = "";
|
|
14990
|
+
for (const c of s) {
|
|
14991
|
+
if (OPEN2[c]) depth++;
|
|
14992
|
+
else if (c === "}" || c === "]" || c === ")") depth--;
|
|
14993
|
+
if (c === "," && depth === 0) {
|
|
14994
|
+
out.push(cur);
|
|
14995
|
+
cur = "";
|
|
14996
|
+
} else cur += c;
|
|
14997
|
+
}
|
|
14998
|
+
out.push(cur);
|
|
14999
|
+
return out.map((x) => x.trim()).filter((x) => x.length > 0);
|
|
15000
|
+
}
|
|
15001
|
+
function clauseEnd(d, from) {
|
|
15002
|
+
for (let j = from; j < d.length; j++) {
|
|
15003
|
+
const c = d[j];
|
|
15004
|
+
if (OPEN2[c]) {
|
|
15005
|
+
const k = closeOf2(d, j);
|
|
15006
|
+
if (k === -1) return -1;
|
|
15007
|
+
j = k;
|
|
15008
|
+
continue;
|
|
14937
15009
|
}
|
|
15010
|
+
if (c === ";") return j;
|
|
15011
|
+
if ((c === "." || c === ":") && (j + 1 === d.length || /\s/.test(d[j + 1]))) return j;
|
|
14938
15012
|
}
|
|
14939
|
-
return
|
|
15013
|
+
return d.length;
|
|
15014
|
+
}
|
|
15015
|
+
function literalNames(inner) {
|
|
15016
|
+
const names2 = [];
|
|
15017
|
+
const unread2 = [];
|
|
15018
|
+
const member = new RegExp(`^(${IDENT3})\\??((?:\\s+or\\s+${IDENT3}\\??)*)\\s*([:[{].*)?$`, "s");
|
|
15019
|
+
for (const m of splitTop2(inner)) {
|
|
15020
|
+
const r = member.exec(m);
|
|
15021
|
+
if (!r) {
|
|
15022
|
+
unread2.push(`member "${m}" is not a field name`);
|
|
15023
|
+
continue;
|
|
15024
|
+
}
|
|
15025
|
+
names2.push(r[1]);
|
|
15026
|
+
for (const alt of (r[2] ?? "").matchAll(new RegExp(`or\\s+(${IDENT3})`, "g")))
|
|
15027
|
+
names2.push(alt[1]);
|
|
15028
|
+
}
|
|
15029
|
+
return { names: names2, unread: unread2 };
|
|
15030
|
+
}
|
|
15031
|
+
var plusNames = (s) => [...s.matchAll(new RegExp(`\\bplus\\s+(${IDENT3})`, "g"))].map((m) => m[1]);
|
|
15032
|
+
function returnsClauses(d) {
|
|
15033
|
+
const out = [];
|
|
15034
|
+
for (const m of d.matchAll(/\bReturns\b/g)) {
|
|
15035
|
+
const at = m.index;
|
|
15036
|
+
const before = d.slice(0, at);
|
|
15037
|
+
if (!(before.trim() === "" || /[.;:]\s+$/.test(before))) {
|
|
15038
|
+
out.push({
|
|
15039
|
+
form: "prose",
|
|
15040
|
+
text: d.slice(at, at + 60),
|
|
15041
|
+
names: [],
|
|
15042
|
+
literalRead: false,
|
|
15043
|
+
unread: [
|
|
15044
|
+
`"Returns" at "${d.slice(Math.max(0, at - 20), at + 20)}" does not open a sentence`
|
|
15045
|
+
]
|
|
15046
|
+
});
|
|
15047
|
+
continue;
|
|
15048
|
+
}
|
|
15049
|
+
const start = at + "Returns".length;
|
|
15050
|
+
const end = clauseEnd(d, start);
|
|
15051
|
+
const body = d.slice(start, end === -1 ? d.length : end);
|
|
15052
|
+
const text = `Returns${body}`;
|
|
15053
|
+
if (end === -1) {
|
|
15054
|
+
out.push({
|
|
15055
|
+
form: "prose",
|
|
15056
|
+
text,
|
|
15057
|
+
names: [],
|
|
15058
|
+
literalRead: false,
|
|
15059
|
+
unread: [`"${text}": unbalanced bracket`]
|
|
15060
|
+
});
|
|
15061
|
+
continue;
|
|
15062
|
+
}
|
|
15063
|
+
const names2 = [];
|
|
15064
|
+
const unread2 = [];
|
|
15065
|
+
if (/^\s*\{/.test(body)) {
|
|
15066
|
+
let first = true;
|
|
15067
|
+
for (let j = 0; j < body.length; j++) {
|
|
15068
|
+
const c = body[j];
|
|
15069
|
+
if (!OPEN2[c]) continue;
|
|
15070
|
+
const k = closeOf2(body, j);
|
|
15071
|
+
if (c === "{") {
|
|
15072
|
+
if (!first && !/\bor\s*$/.test(body.slice(0, j)))
|
|
15073
|
+
unread2.push(`"${body.slice(j, k + 1)}": a second literal not introduced by "or"`);
|
|
15074
|
+
else {
|
|
15075
|
+
const r = literalNames(body.slice(j + 1, k));
|
|
15076
|
+
names2.push(...r.names);
|
|
15077
|
+
unread2.push(...r.unread.map((u) => `"${text}": ${u}`));
|
|
15078
|
+
}
|
|
15079
|
+
first = false;
|
|
15080
|
+
}
|
|
15081
|
+
j = k;
|
|
15082
|
+
}
|
|
15083
|
+
names2.push(...plusNames(body.replace(/\{[\s\S]*\}/, "")));
|
|
15084
|
+
out.push({
|
|
15085
|
+
form: "object-literal",
|
|
15086
|
+
text,
|
|
15087
|
+
names: [...new Set(names2)],
|
|
15088
|
+
// A member it could not read may be any property: the "left out" direction is then not judged.
|
|
15089
|
+
literalRead: unread2.length === 0,
|
|
15090
|
+
unread: unread2
|
|
15091
|
+
});
|
|
15092
|
+
continue;
|
|
15093
|
+
}
|
|
15094
|
+
let literal = false;
|
|
15095
|
+
let list = false;
|
|
15096
|
+
for (let j = 0; j < body.length; j++) {
|
|
15097
|
+
const c = body[j];
|
|
15098
|
+
if (!OPEN2[c]) continue;
|
|
15099
|
+
const k = closeOf2(body, j);
|
|
15100
|
+
const group = body.slice(j, k + 1);
|
|
15101
|
+
if (c === "{") {
|
|
15102
|
+
literal = true;
|
|
15103
|
+
unread2.push(
|
|
15104
|
+
`"${text}": an object literal inside prose (${group}) cannot be placed at the top level`
|
|
15105
|
+
);
|
|
15106
|
+
} else if (c === "(") {
|
|
15107
|
+
const members3 = splitTop2(group.slice(1, -1));
|
|
15108
|
+
const named = new RegExp(`^(${IDENT3})\\??(?:\\s*\\{[\\s\\S]*\\})?$`);
|
|
15109
|
+
const isName = members3.map((x) => named.exec(x)?.[1]);
|
|
15110
|
+
if (isName.every((x) => x !== void 0)) {
|
|
15111
|
+
list = true;
|
|
15112
|
+
names2.push(...isName);
|
|
15113
|
+
} else if (isName.some((x) => x !== void 0))
|
|
15114
|
+
unread2.push(
|
|
15115
|
+
`"${text}": the group ${group} mixes field names and prose (${members3.filter((_, i) => isName[i] === void 0).join(", ")})`
|
|
15116
|
+
);
|
|
15117
|
+
}
|
|
15118
|
+
j = k;
|
|
15119
|
+
}
|
|
15120
|
+
names2.push(...plusNames(body));
|
|
15121
|
+
out.push({
|
|
15122
|
+
form: literal ? "literal-in-prose" : list ? "field-list" : "prose",
|
|
15123
|
+
text,
|
|
15124
|
+
names: [...new Set(names2)],
|
|
15125
|
+
literalRead: false,
|
|
15126
|
+
unread: unread2
|
|
15127
|
+
});
|
|
15128
|
+
}
|
|
15129
|
+
return out;
|
|
15130
|
+
}
|
|
15131
|
+
function returnsAlignment(d, top, fields) {
|
|
15132
|
+
const clauses = returnsClauses(d);
|
|
15133
|
+
if (top === null) {
|
|
15134
|
+
const given = clauses.flatMap((c) => c.names);
|
|
15135
|
+
return {
|
|
15136
|
+
bad: [],
|
|
15137
|
+
notes: [],
|
|
15138
|
+
cnj: [
|
|
15139
|
+
...given.length > 0 ? [
|
|
15140
|
+
`outputSchema has no top-level properties object: the Returns clause names (${given.join(", ")}) and cannot be aligned`
|
|
15141
|
+
] : [],
|
|
15142
|
+
...clauses.flatMap((c) => c.unread)
|
|
15143
|
+
]
|
|
15144
|
+
};
|
|
15145
|
+
}
|
|
15146
|
+
const named = new Set(clauses.flatMap((c) => c.names));
|
|
15147
|
+
const bad = [...named].filter((k) => !top.includes(k)).map((k) => {
|
|
15148
|
+
const deeper = fields.find((f) => f.key === k)?.path;
|
|
15149
|
+
return deeper ? `${k}: named as returned, not in outputSchema at the top level (it is ${deeper})` : `${k}: named as returned, not in outputSchema`;
|
|
15150
|
+
});
|
|
15151
|
+
const left = new Set(
|
|
15152
|
+
clauses.filter((c) => c.literalRead).flatMap((c) => top.filter((p) => !c.names.includes(p)))
|
|
15153
|
+
);
|
|
15154
|
+
const notes = [...left].map(
|
|
15155
|
+
(p) => `${p} is a top-level property of the outputSchema that the Returns { \u2026 } literal does not name`
|
|
15156
|
+
);
|
|
15157
|
+
return { bad, notes, cnj: clauses.flatMap((c) => c.unread) };
|
|
14940
15158
|
}
|
|
14941
15159
|
var HINTS = ["readOnlyHint", "destructiveHint", "idempotentHint", "openWorldHint"];
|
|
14942
15160
|
function scoreTools(tools) {
|
|
@@ -15000,13 +15218,18 @@ function scoreTools(tools) {
|
|
|
15000
15218
|
);
|
|
15001
15219
|
else {
|
|
15002
15220
|
const fields = fieldsOf(output);
|
|
15003
|
-
const
|
|
15004
|
-
|
|
15005
|
-
|
|
15221
|
+
const top = isObj3(output.properties) ? Object.keys(output.properties) : null;
|
|
15222
|
+
const aligned = returnsAlignment(t.description ?? "", top, fields);
|
|
15223
|
+
const verdict3 = v(
|
|
15224
|
+
"output-described-aligned",
|
|
15225
|
+
[
|
|
15006
15226
|
...fields.filter((f) => !f.node || !desc(f.node).trim()).map((f) => `${f.path}: no description`),
|
|
15007
|
-
...
|
|
15008
|
-
]
|
|
15227
|
+
...aligned.bad
|
|
15228
|
+
],
|
|
15229
|
+
aligned.cnj
|
|
15009
15230
|
);
|
|
15231
|
+
if (aligned.notes.length > 0) verdict3.notes = aligned.notes;
|
|
15232
|
+
out.push(verdict3);
|
|
15010
15233
|
}
|
|
15011
15234
|
}
|
|
15012
15235
|
return out;
|
|
@@ -15054,6 +15277,10 @@ function runServed4(runtime) {
|
|
|
15054
15277
|
const head = `${runtime.tools.length} served tool(s) x ${CRITERIA.length} criteria \u2014 ${tally.join(" | ")}`;
|
|
15055
15278
|
const reds = lines2("non-conforming");
|
|
15056
15279
|
const unread2 = lines2("could-not-judge");
|
|
15280
|
+
const noted = verdicts.filter((x) => (x.notes ?? []).length > 0).map((x) => `${x.tool} ${x.criterion}: note: ${(x.notes ?? []).join("; ")}`);
|
|
15281
|
+
const noteBlock = noted.length > 0 ? `
|
|
15282
|
+
notes (not defects):
|
|
15283
|
+
${noted.join("\n")}` : "";
|
|
15057
15284
|
if (reds.length > 0)
|
|
15058
15285
|
return {
|
|
15059
15286
|
id: ID8,
|
|
@@ -15062,12 +15289,12 @@ function runServed4(runtime) {
|
|
|
15062
15289
|
verdict: `${RULE8}: ${head}
|
|
15063
15290
|
${reds.join("\n")}${unread2.length > 0 ? `
|
|
15064
15291
|
could not judge:
|
|
15065
|
-
${unread2.join("\n")}` : ""}`
|
|
15292
|
+
${unread2.join("\n")}` : ""}${noteBlock}`
|
|
15066
15293
|
};
|
|
15067
15294
|
if (unread2.length > 0)
|
|
15068
15295
|
return couldNotJudge(ID8, anchor, `${head}
|
|
15069
|
-
${unread2.join("\n")} (${RULE8})`);
|
|
15070
|
-
return { id: ID8, anchor, state: "present", verdict: `${head} (${RULE8})` };
|
|
15296
|
+
${unread2.join("\n")}${noteBlock} (${RULE8})`);
|
|
15297
|
+
return { id: ID8, anchor, state: "present", verdict: `${head}${noteBlock} (${RULE8})` };
|
|
15071
15298
|
}
|
|
15072
15299
|
var c40ToolDocumentation = {
|
|
15073
15300
|
id: ID8,
|
|
@@ -16824,7 +17051,7 @@ function classifySurface(file, startIdx, anchor, pkgIdents) {
|
|
|
16824
17051
|
return { kind: "unreadable-source", anchor };
|
|
16825
17052
|
}
|
|
16826
17053
|
function packageJsonVersionConsts(tree) {
|
|
16827
|
-
const
|
|
17054
|
+
const names2 = /* @__PURE__ */ new Set();
|
|
16828
17055
|
const decl = /\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\b/;
|
|
16829
17056
|
for (const file of tree.files) {
|
|
16830
17057
|
const code = file.lines.filter((l) => !l.comment);
|
|
@@ -16840,10 +17067,10 @@ function packageJsonVersionConsts(tree) {
|
|
|
16840
17067
|
depth += (raw.match(/[({[]/g) ?? []).length - (raw.match(/[)}\]]/g) ?? []).length;
|
|
16841
17068
|
if (depth <= 0 && /;\s*$/.test(raw)) break;
|
|
16842
17069
|
}
|
|
16843
|
-
if (/package\.json/.test(stmt) && /\.version\b/.test(stmt))
|
|
17070
|
+
if (/package\.json/.test(stmt) && /\.version\b/.test(stmt)) names2.add(m[1]);
|
|
16844
17071
|
}
|
|
16845
17072
|
}
|
|
16846
|
-
return
|
|
17073
|
+
return names2;
|
|
16847
17074
|
}
|
|
16848
17075
|
function sdkServerVersionSurface(tree) {
|
|
16849
17076
|
const derived = packageJsonVersionConsts(tree);
|
|
@@ -19107,9 +19334,9 @@ function resolvesToLiteral(tree, path) {
|
|
|
19107
19334
|
};
|
|
19108
19335
|
if (/[()]/.test(path)) return false;
|
|
19109
19336
|
if (!path.includes(".")) return plainLiteral(path);
|
|
19110
|
-
const
|
|
19111
|
-
const def = new RegExp(`(?:^|[\\s{,])${esc4(
|
|
19112
|
-
const shorthand = new RegExp(`[{,]\\s*${esc4(
|
|
19337
|
+
const prop2 = path.split(".").pop() ?? "";
|
|
19338
|
+
const def = new RegExp(`(?:^|[\\s{,])${esc4(prop2)}\\s*:\\s*([^,}\\n]+)`);
|
|
19339
|
+
const shorthand = new RegExp(`[{,]\\s*${esc4(prop2)}\\s*[,}]`);
|
|
19113
19340
|
const defs = lines2.map((l) => l.match(def)).filter((m) => m !== null);
|
|
19114
19341
|
if (defs.length === 0 || lines2.some((l) => shorthand.test(l))) return false;
|
|
19115
19342
|
return defs.every((m) => {
|
|
@@ -19178,8 +19405,8 @@ function boundToSystemState(tree, path) {
|
|
|
19178
19405
|
if (lines2.some((l) => param.test(l))) return null;
|
|
19179
19406
|
return exprSystemKind(found[0][1]);
|
|
19180
19407
|
}
|
|
19181
|
-
const
|
|
19182
|
-
const def = new RegExp(`(?:^|[\\s{,])${esc4(
|
|
19408
|
+
const prop2 = path.split(".").pop() ?? "";
|
|
19409
|
+
const def = new RegExp(`(?:^|[\\s{,])${esc4(prop2)}\\s*:\\s*([^,}\\n]+)`);
|
|
19183
19410
|
const defs = lines2.map((l) => l.match(def)).filter((m) => m !== null);
|
|
19184
19411
|
if (defs.length === 0) return null;
|
|
19185
19412
|
const kinds = defs.map((m) => exprSystemKind(m[1]));
|
|
@@ -19513,11 +19740,11 @@ function prmRouteViaConstant(tree) {
|
|
|
19513
19740
|
const decl = /\bconst\s+([A-Za-z_$][\w$]*)\s*(?::[^=\n]+)?=\s*(\[[^\]]*\]|"[^"\n]*"|'[^'\n]*'|`[^`]*`)/g;
|
|
19514
19741
|
for (const m of text.matchAll(decl)) if (m[2].includes(PRM_PATH_LITERAL)) holders.add(m[1]);
|
|
19515
19742
|
if (holders.size === 0) continue;
|
|
19516
|
-
const
|
|
19743
|
+
const names2 = new Set(holders);
|
|
19517
19744
|
const loop = /\bfor\s*\(\s*(?:const|let)\s+([A-Za-z_$][\w$]*)\s+of\s+([A-Za-z_$][\w$]*)\s*\)/g;
|
|
19518
|
-
for (const m of text.matchAll(loop)) if (holders.has(m[2]))
|
|
19745
|
+
for (const m of text.matchAll(loop)) if (holders.has(m[2])) names2.add(m[1]);
|
|
19519
19746
|
const route = /\b(?:app|router|server)\.(?:get|route|all)\s*\(\s*([A-Za-z_$][\w$]*)\s*,/g;
|
|
19520
|
-
for (const m of text.matchAll(route)) if (
|
|
19747
|
+
for (const m of text.matchAll(route)) if (names2.has(m[1])) return true;
|
|
19521
19748
|
}
|
|
19522
19749
|
return false;
|
|
19523
19750
|
}
|
|
@@ -19528,8 +19755,17 @@ function challengeForwarded(tree) {
|
|
|
19528
19755
|
const code = file.lines.filter((l) => !l.comment);
|
|
19529
19756
|
const text = code.map((l) => l.raw).join("\n");
|
|
19530
19757
|
if (!FORWARD_STATUS_RE.test(text)) continue;
|
|
19531
|
-
const
|
|
19532
|
-
|
|
19758
|
+
const ct = codeText(file);
|
|
19759
|
+
for (const l of code) {
|
|
19760
|
+
if (!FORWARD_HEADER_LINE_RE.test(l.raw)) continue;
|
|
19761
|
+
const start = ct.lineStart[l.n - 1] ?? 0;
|
|
19762
|
+
if (on401Path(ct, start, start + l.raw.length)) return `${file.rel}:${l.n}`;
|
|
19763
|
+
const owner = /([\w$]+)\.headers\b/.exec(l.raw)?.[1];
|
|
19764
|
+
if (owner === void 0) continue;
|
|
19765
|
+
const near = code.filter((x) => x.n >= l.n - PATH_LINES_BEFORE && x.n <= l.n + PATH_LINES_AFTER).map((x) => x.raw).join("\n");
|
|
19766
|
+
if (new RegExp(`\\b${owner.replace(/\$/g, "\\$")}\\.status\\b`).test(near))
|
|
19767
|
+
return `${file.rel}:${l.n}`;
|
|
19768
|
+
}
|
|
19533
19769
|
}
|
|
19534
19770
|
return null;
|
|
19535
19771
|
}
|
|
@@ -20268,12 +20504,12 @@ function gateExemptions(tree, g, installer) {
|
|
|
20268
20504
|
const end = exprEnd(s.shape, eq + 1);
|
|
20269
20505
|
const code = s.code.slice(eq + 1, end);
|
|
20270
20506
|
const shape = s.shape.slice(eq + 1, end);
|
|
20271
|
-
const
|
|
20507
|
+
const names2 = [];
|
|
20272
20508
|
const unread2 = [];
|
|
20273
20509
|
const param = /^\s*(?:\(\s*)*(?:async\s*)?(?:function\s*[\w$]*\s*)?\(\s*([A-Za-z_$][\w$]*)/.exec(
|
|
20274
20510
|
shape
|
|
20275
20511
|
)?.[1];
|
|
20276
|
-
if (!param) return { names, unread: unread2 };
|
|
20512
|
+
if (!param) return { names: names2, unread: unread2 };
|
|
20277
20513
|
const literal = (text, home) => {
|
|
20278
20514
|
const lit = stringLiteral(text);
|
|
20279
20515
|
if (lit !== null) return lit;
|
|
@@ -20364,7 +20600,7 @@ function gateExemptions(tree, g, installer) {
|
|
|
20364
20600
|
anchor: c.anchor,
|
|
20365
20601
|
reason: `the exempt set passed to ${installer.name} (${c.anchor}) is not a \`new Set([...])\` of strings`
|
|
20366
20602
|
});
|
|
20367
|
-
else for (const n of got2)
|
|
20603
|
+
else for (const n of got2) names2.push({ name: n, anchor: c.anchor });
|
|
20368
20604
|
}
|
|
20369
20605
|
continue;
|
|
20370
20606
|
}
|
|
@@ -20375,7 +20611,7 @@ function gateExemptions(tree, g, installer) {
|
|
|
20375
20611
|
anchor: at,
|
|
20376
20612
|
reason: `the exempt set \`${id}\` (${at}) cannot be followed to a \`new Set([...])\` of strings`
|
|
20377
20613
|
});
|
|
20378
|
-
else for (const n of got)
|
|
20614
|
+
else for (const n of got) names2.push({ name: n, anchor: at });
|
|
20379
20615
|
} else if (e3) {
|
|
20380
20616
|
for (const el of topLevelParts(e3[1])) {
|
|
20381
20617
|
const v = literal(el, s);
|
|
@@ -20384,10 +20620,10 @@ function gateExemptions(tree, g, installer) {
|
|
|
20384
20620
|
anchor: at,
|
|
20385
20621
|
reason: `exempt list element \`${el.slice(0, 40)}\` (${at}) is not a string`
|
|
20386
20622
|
});
|
|
20387
|
-
else
|
|
20623
|
+
else names2.push({ name: v, anchor: at });
|
|
20388
20624
|
}
|
|
20389
20625
|
} else if (e2 && literal(e2[1], s) !== null) {
|
|
20390
|
-
|
|
20626
|
+
names2.push({ name: literal(e2[1], s), anchor: at });
|
|
20391
20627
|
} else {
|
|
20392
20628
|
unread2.push({
|
|
20393
20629
|
anchor: at,
|
|
@@ -20396,7 +20632,7 @@ function gateExemptions(tree, g, installer) {
|
|
|
20396
20632
|
}
|
|
20397
20633
|
}
|
|
20398
20634
|
}
|
|
20399
|
-
return { names, unread: unread2 };
|
|
20635
|
+
return { names: names2, unread: unread2 };
|
|
20400
20636
|
}
|
|
20401
20637
|
function decisionCalls(tree) {
|
|
20402
20638
|
const out = [];
|
|
@@ -20568,8 +20804,8 @@ function judgeStatic(tree, id) {
|
|
|
20568
20804
|
`\`${e.name}\` (${e.anchor}) is exempt from the gate (${gate.anchor}): only the identity tool (C-33) may skip the role decision`
|
|
20569
20805
|
);
|
|
20570
20806
|
}
|
|
20571
|
-
const
|
|
20572
|
-
const callRe =
|
|
20807
|
+
const names2 = installers.map((i) => i.fn?.name).filter((n) => !!n);
|
|
20808
|
+
const callRe = names2.length > 0 ? new RegExp(String.raw`(?<![\w$.])(?:${names2.map(esc2).join("|")})\s*\(`) : null;
|
|
20573
20809
|
for (const reg of regs) {
|
|
20574
20810
|
if (reg.form === "tools/call dispatcher") continue;
|
|
20575
20811
|
const s = reg.call.src;
|
|
@@ -20593,7 +20829,7 @@ function judgeStatic(tree, id) {
|
|
|
20593
20829
|
if (installAt === void 0) {
|
|
20594
20830
|
unreadable2.push({
|
|
20595
20831
|
anchor: reg.call.anchor,
|
|
20596
|
-
reason: `tool \`${name}\` (${reg.call.anchor}) is registered in a function that does not install the gate (${
|
|
20832
|
+
reason: `tool \`${name}\` (${reg.call.anchor}) is registered in a function that does not install the gate (${names2.join(", ") || gates[0].anchor}): whether its calls pass the gate is not decidable statically`
|
|
20597
20833
|
});
|
|
20598
20834
|
} else if (installAt > reg.call.start) {
|
|
20599
20835
|
problems.push(
|
|
@@ -21441,16 +21677,16 @@ function readInstalledAs(tree) {
|
|
|
21441
21677
|
}
|
|
21442
21678
|
const files = [];
|
|
21443
21679
|
const walk3 = (d) => {
|
|
21444
|
-
let
|
|
21680
|
+
let names2;
|
|
21445
21681
|
try {
|
|
21446
|
-
|
|
21682
|
+
names2 = readdirSync15(d).sort();
|
|
21447
21683
|
} catch (e) {
|
|
21448
21684
|
out.unread.push(
|
|
21449
21685
|
`${d.slice(nm.length + 1)} (directory not listed: ${e.message})`
|
|
21450
21686
|
);
|
|
21451
21687
|
return;
|
|
21452
21688
|
}
|
|
21453
|
-
for (const n of
|
|
21689
|
+
for (const n of names2) {
|
|
21454
21690
|
if (files.length >= MAX_FILES_PER_PACKAGE) return;
|
|
21455
21691
|
if (n === "node_modules") continue;
|
|
21456
21692
|
const full = join31(d, n);
|
|
@@ -21898,73 +22134,291 @@ var s5AuthzElements = {
|
|
|
21898
22134
|
);
|
|
21899
22135
|
},
|
|
21900
22136
|
/**
|
|
21901
|
-
* SERVED half (
|
|
21902
|
-
*
|
|
21903
|
-
* is an array listing "none". (l): `authorization_response_iss_parameter_supported` is the boolean true.
|
|
21904
|
-
* The other elements, and `iss` on every authorization response, are not readable from a metadata
|
|
21905
|
-
* document: the result says so and stays could-not-judge unless an element is contradicted.
|
|
22137
|
+
* SERVED half (--url, or a launched server): every element the wire can answer is READ; every other is NAMED with
|
|
22138
|
+
* the reason it is not read. See `judgeServed` for the decision per element.
|
|
21906
22139
|
*/
|
|
21907
22140
|
runServed(runtime) {
|
|
21908
|
-
|
|
21909
|
-
|
|
21910
|
-
|
|
21911
|
-
|
|
21912
|
-
|
|
21913
|
-
|
|
21914
|
-
|
|
21915
|
-
|
|
21916
|
-
|
|
21917
|
-
|
|
22141
|
+
return judgeServed(this.id, runtime);
|
|
22142
|
+
}
|
|
22143
|
+
};
|
|
22144
|
+
var JWT_BEARER = "urn:ietf:params:oauth:grant-type:jwt-bearer";
|
|
22145
|
+
function unreadGet(g) {
|
|
22146
|
+
if (g.status === void 0) return g.detail ?? "no answer";
|
|
22147
|
+
if (g.status >= 200 && g.status < 300)
|
|
22148
|
+
return g.json ? void 0 : `HTTP ${g.status} with no JSON object`;
|
|
22149
|
+
return `HTTP ${g.status}`;
|
|
22150
|
+
}
|
|
22151
|
+
var isNotServed = (g) => g.status !== void 0 && g.status >= 400 && g.status < 500;
|
|
22152
|
+
function noPrmAt(g) {
|
|
22153
|
+
if (isNotServed(g)) return `HTTP ${g.status}`;
|
|
22154
|
+
if (unreadGet(g) !== void 0) return void 0;
|
|
22155
|
+
const doc = g.json;
|
|
22156
|
+
return "resource" in doc || "authorization_servers" in doc ? void 0 : `HTTP ${g.status}, a JSON object with neither resource nor authorization_servers`;
|
|
22157
|
+
}
|
|
22158
|
+
function prmElements(docs) {
|
|
22159
|
+
if (!docs)
|
|
22160
|
+
return [
|
|
22161
|
+
{
|
|
22162
|
+
id: "f",
|
|
22163
|
+
status: "unread",
|
|
22164
|
+
text: "(f) the PRM copies were not recorded by this run (a runtime record that predates the read)"
|
|
22165
|
+
}
|
|
22166
|
+
];
|
|
22167
|
+
if (docs.kind === "not-run")
|
|
22168
|
+
return [{ id: "f", status: "unread", text: `(f) the PRM was not read: ${docs.reason}` }];
|
|
22169
|
+
const copies = [docs.prm.suffixed, docs.prm.bare].filter((g) => g !== void 0);
|
|
22170
|
+
if (copies.every((g) => noPrmAt(g) !== void 0))
|
|
22171
|
+
return [
|
|
22172
|
+
{
|
|
22173
|
+
id: "f",
|
|
22174
|
+
status: "unread",
|
|
22175
|
+
text: `(f) no PRM is served (${copies.map((g) => `${noPrmAt(g)} at ${g.url}`).join(", ")}): whether S-5 applies to this server, ${S5_CONDITION}, is a statement of its source tree, not of the wire`
|
|
22176
|
+
}
|
|
22177
|
+
];
|
|
22178
|
+
const out = [];
|
|
22179
|
+
for (const g of copies) {
|
|
22180
|
+
const none = noPrmAt(g);
|
|
22181
|
+
if (none !== void 0) {
|
|
22182
|
+
out.push({ id: "f", status: "red", text: `(f) the PRM is not served at ${g.url} (${none})` });
|
|
22183
|
+
continue;
|
|
21918
22184
|
}
|
|
21919
|
-
const
|
|
21920
|
-
|
|
21921
|
-
|
|
21922
|
-
|
|
21923
|
-
const unreadable2 = [];
|
|
21924
|
-
const cimd = doc.client_id_metadata_document_supported;
|
|
21925
|
-
if (cimd === true) oks.push("client_id_metadata_document_supported true");
|
|
21926
|
-
else
|
|
21927
|
-
reds.push(
|
|
21928
|
-
`(g) the served AS metadata ${cimd === void 0 ? "does not announce" : `announces ${JSON.stringify(cimd)} for`} client_id_metadata_document_supported: true`
|
|
21929
|
-
);
|
|
21930
|
-
const methods = doc.token_endpoint_auth_methods_supported;
|
|
21931
|
-
if (Array.isArray(methods)) {
|
|
21932
|
-
if (methods.includes("none"))
|
|
21933
|
-
oks.push(`"none" in token_endpoint_auth_methods_supported ${JSON.stringify(methods)}`);
|
|
21934
|
-
else
|
|
21935
|
-
reds.push(
|
|
21936
|
-
`(g) the served AS metadata lists ${JSON.stringify(methods)} in token_endpoint_auth_methods_supported, without "none"`
|
|
21937
|
-
);
|
|
21938
|
-
} else if (methods === void 0) {
|
|
21939
|
-
reds.push(
|
|
21940
|
-
'(g) the served AS metadata has no token_endpoint_auth_methods_supported (so no "none")'
|
|
21941
|
-
);
|
|
21942
|
-
} else {
|
|
21943
|
-
unreadable2.push(
|
|
21944
|
-
`token_endpoint_auth_methods_supported is served as ${JSON.stringify(methods)}, not an array`
|
|
21945
|
-
);
|
|
22185
|
+
const why = unreadGet(g);
|
|
22186
|
+
if (why) {
|
|
22187
|
+
out.push({ id: "f", status: "unread", text: `(f) the PRM at ${g.url} was not read: ${why}` });
|
|
22188
|
+
continue;
|
|
21946
22189
|
}
|
|
21947
|
-
const
|
|
21948
|
-
if (
|
|
22190
|
+
const resource = g.json.resource;
|
|
22191
|
+
if (typeof resource !== "string")
|
|
22192
|
+
out.push({
|
|
22193
|
+
id: "f",
|
|
22194
|
+
status: "red",
|
|
22195
|
+
text: `(f) the PRM served at ${g.url} has no string resource (${JSON.stringify(resource) ?? "absent"})`
|
|
22196
|
+
});
|
|
22197
|
+
else if (resource !== docs.mcpUrl)
|
|
22198
|
+
out.push({
|
|
22199
|
+
id: "f",
|
|
22200
|
+
status: "red",
|
|
22201
|
+
text: `(f) the PRM served at ${g.url} names resource ${JSON.stringify(resource)}, not the MCP URL ${docs.mcpUrl} (path included)`
|
|
22202
|
+
});
|
|
22203
|
+
}
|
|
22204
|
+
if (out.length === 0)
|
|
22205
|
+
out.push({
|
|
22206
|
+
id: "f",
|
|
22207
|
+
status: "ok",
|
|
22208
|
+
text: `(f) the PRM resource equals the MCP URL ${docs.mcpUrl} at ${copies.map((g) => g.url).join(" and at ")}`
|
|
22209
|
+
});
|
|
22210
|
+
return out;
|
|
22211
|
+
}
|
|
22212
|
+
function asElements(as) {
|
|
22213
|
+
if (as.kind !== "document") {
|
|
22214
|
+
const why = `the authorization-server metadata was not read: ${as.kind === "not-run" ? as.reason : `${as.url}: ${as.reason}`}`;
|
|
22215
|
+
return ["g", "j", "l"].map((id) => ({ id, status: "unread", text: `(${id}) ${why}` }));
|
|
22216
|
+
}
|
|
22217
|
+
const doc = as.document;
|
|
22218
|
+
const out = [];
|
|
22219
|
+
const g = [];
|
|
22220
|
+
const cimd = doc.client_id_metadata_document_supported;
|
|
22221
|
+
if (cimd === true) g.push("client_id_metadata_document_supported true");
|
|
22222
|
+
else
|
|
22223
|
+
out.push({
|
|
22224
|
+
id: "g",
|
|
22225
|
+
status: "red",
|
|
22226
|
+
text: `(g) the served AS metadata ${cimd === void 0 ? "does not announce" : `announces ${JSON.stringify(cimd)} for`} client_id_metadata_document_supported: true`
|
|
22227
|
+
});
|
|
22228
|
+
const methods = doc.token_endpoint_auth_methods_supported;
|
|
22229
|
+
if (Array.isArray(methods)) {
|
|
22230
|
+
if (methods.includes("none"))
|
|
22231
|
+
g.push(`"none" in token_endpoint_auth_methods_supported ${JSON.stringify(methods)}`);
|
|
21949
22232
|
else
|
|
21950
|
-
|
|
21951
|
-
|
|
21952
|
-
|
|
21953
|
-
|
|
21954
|
-
|
|
21955
|
-
|
|
21956
|
-
|
|
21957
|
-
|
|
21958
|
-
|
|
21959
|
-
|
|
21960
|
-
}
|
|
21961
|
-
|
|
21962
|
-
|
|
21963
|
-
|
|
21964
|
-
|
|
21965
|
-
|
|
22233
|
+
out.push({
|
|
22234
|
+
id: "g",
|
|
22235
|
+
status: "red",
|
|
22236
|
+
text: `(g) the served AS metadata lists ${JSON.stringify(methods)} in token_endpoint_auth_methods_supported, without "none"`
|
|
22237
|
+
});
|
|
22238
|
+
} else if (methods === void 0) {
|
|
22239
|
+
out.push({
|
|
22240
|
+
id: "g",
|
|
22241
|
+
status: "red",
|
|
22242
|
+
text: '(g) the served AS metadata has no token_endpoint_auth_methods_supported (so no "none")'
|
|
22243
|
+
});
|
|
22244
|
+
} else {
|
|
22245
|
+
out.push({
|
|
22246
|
+
id: "g",
|
|
22247
|
+
status: "unread",
|
|
22248
|
+
text: `(g) token_endpoint_auth_methods_supported is served as ${JSON.stringify(methods)}, not an array`
|
|
22249
|
+
});
|
|
21966
22250
|
}
|
|
22251
|
+
if (g.length === 2)
|
|
22252
|
+
out.push({ id: "g", status: "ok", text: `(g) served at ${as.url}: ${g.join(", ")}` });
|
|
22253
|
+
const grants = doc.grant_types_supported;
|
|
22254
|
+
if (Array.isArray(grants) && grants.includes(JWT_BEARER))
|
|
22255
|
+
out.push({
|
|
22256
|
+
id: "j",
|
|
22257
|
+
status: "unread",
|
|
22258
|
+
text: `(j) the jwt-bearer grant is announced at ${as.url}: whether it keeps trusted issuers PER TENANT is served by no metadata (a human verdict)`
|
|
22259
|
+
});
|
|
22260
|
+
else if (grants === void 0 || Array.isArray(grants))
|
|
22261
|
+
out.push({
|
|
22262
|
+
id: "j",
|
|
22263
|
+
status: "unestablished",
|
|
22264
|
+
text: "(j) no jwt-bearer grant announced in the served AS metadata, owed only to a server offered to Team/Enterprise clients, which no source states"
|
|
22265
|
+
});
|
|
22266
|
+
else
|
|
22267
|
+
out.push({
|
|
22268
|
+
id: "j",
|
|
22269
|
+
status: "unread",
|
|
22270
|
+
text: `(j) grant_types_supported is served as ${JSON.stringify(grants)}, not an array`
|
|
22271
|
+
});
|
|
22272
|
+
const iss = doc.authorization_response_iss_parameter_supported;
|
|
22273
|
+
if (iss === true)
|
|
22274
|
+
out.push({
|
|
22275
|
+
id: "l",
|
|
22276
|
+
status: "ok",
|
|
22277
|
+
text: `(l) authorization_response_iss_parameter_supported true at ${as.url}`
|
|
22278
|
+
});
|
|
22279
|
+
else
|
|
22280
|
+
out.push({
|
|
22281
|
+
id: "l",
|
|
22282
|
+
status: "red",
|
|
22283
|
+
text: `(l) the served AS metadata ${iss === void 0 ? "does not announce" : `announces ${JSON.stringify(iss)} for`} authorization_response_iss_parameter_supported: true (RFC 9207)`
|
|
22284
|
+
});
|
|
22285
|
+
return out;
|
|
22286
|
+
}
|
|
22287
|
+
function oidcElements(docs) {
|
|
22288
|
+
if (!docs || docs.kind === "not-run")
|
|
22289
|
+
return [
|
|
22290
|
+
{
|
|
22291
|
+
id: "k",
|
|
22292
|
+
status: "unread",
|
|
22293
|
+
text: `(k) the OIDC discovery was not read: ${docs ? docs.reason : "a runtime record that predates the read"}`
|
|
22294
|
+
}
|
|
22295
|
+
];
|
|
22296
|
+
const o = docs.oidc;
|
|
22297
|
+
if ("skipped" in o)
|
|
22298
|
+
return [
|
|
22299
|
+
{ id: "k", status: "unread", text: `(k) the OIDC discovery was not read: ${o.skipped}` }
|
|
22300
|
+
];
|
|
22301
|
+
if (isNotServed(o))
|
|
22302
|
+
return [
|
|
22303
|
+
{
|
|
22304
|
+
id: "k",
|
|
22305
|
+
status: "unestablished",
|
|
22306
|
+
text: `(k) no OIDC discovery published at ${o.url} (HTTP ${o.status}), owed only to a server aimed at a host that binds enterprise accounts, which no source states`
|
|
22307
|
+
}
|
|
22308
|
+
];
|
|
22309
|
+
const why = unreadGet(o);
|
|
22310
|
+
if (why)
|
|
22311
|
+
return [
|
|
22312
|
+
{
|
|
22313
|
+
id: "k",
|
|
22314
|
+
status: "unread",
|
|
22315
|
+
text: `(k) the OIDC discovery at ${o.url} was not read: ${why}`
|
|
22316
|
+
}
|
|
22317
|
+
];
|
|
22318
|
+
const doc = o.json;
|
|
22319
|
+
const out = [];
|
|
22320
|
+
const scopes = doc.scopes_supported;
|
|
22321
|
+
if (Array.isArray(scopes)) {
|
|
22322
|
+
const missing = ["openid", "email"].filter((x) => !scopes.includes(x));
|
|
22323
|
+
if (missing.length > 0)
|
|
22324
|
+
out.push({
|
|
22325
|
+
id: "k",
|
|
22326
|
+
status: "red",
|
|
22327
|
+
text: `(k) OIDC discovery served at ${o.url} lacks ${missing.map((x) => JSON.stringify(x)).join(" and ")} in scopes_supported`
|
|
22328
|
+
});
|
|
22329
|
+
} else {
|
|
22330
|
+
out.push({
|
|
22331
|
+
id: "k",
|
|
22332
|
+
status: "unread",
|
|
22333
|
+
text: `(k) OIDC discovery served at ${o.url} states no scopes_supported array, so openid and email are unread`
|
|
22334
|
+
});
|
|
22335
|
+
}
|
|
22336
|
+
const userinfo = doc.userinfo_endpoint;
|
|
22337
|
+
if (typeof userinfo !== "string")
|
|
22338
|
+
out.push({
|
|
22339
|
+
id: "k",
|
|
22340
|
+
status: "red",
|
|
22341
|
+
text: `(k) OIDC discovery served at ${o.url} lacks a userinfo_endpoint`
|
|
22342
|
+
});
|
|
22343
|
+
if (out.length > 0) return out;
|
|
22344
|
+
const claims = doc.claims_supported;
|
|
22345
|
+
if (Array.isArray(claims) && claims.includes("email") && claims.includes("email_verified"))
|
|
22346
|
+
return [
|
|
22347
|
+
{
|
|
22348
|
+
id: "k",
|
|
22349
|
+
status: "ok",
|
|
22350
|
+
text: `(k) OIDC discovery served at ${o.url} with openid and email, userinfo_endpoint ${userinfo}, claims email and email_verified`
|
|
22351
|
+
}
|
|
22352
|
+
];
|
|
22353
|
+
return [
|
|
22354
|
+
{
|
|
22355
|
+
id: "k",
|
|
22356
|
+
status: "unread",
|
|
22357
|
+
text: `(k) OIDC discovery served at ${o.url} with openid and email and userinfo_endpoint ${userinfo}, but claims_supported does not list email and email_verified (an inexhaustive list): what UserInfo returns needs an authenticated GET`
|
|
22358
|
+
}
|
|
22359
|
+
];
|
|
22360
|
+
}
|
|
22361
|
+
var H_UNREAD = {
|
|
22362
|
+
id: "h",
|
|
22363
|
+
status: "unread",
|
|
22364
|
+
text: "(h) needs an authorization-request probe: only a request the AS answers proves it accepts https://claude.ai/api/mcp/auth_callback and a loopback redirect on any port, and no known client document lists the claude.ai callback"
|
|
22365
|
+
};
|
|
22366
|
+
var I_UNREAD = {
|
|
22367
|
+
id: "i",
|
|
22368
|
+
status: "unread",
|
|
22369
|
+
text: "(i) whether /authorize authenticates a person is a human verdict plus a sign-in probe with a test client on a development deployment, stated by no metadata"
|
|
21967
22370
|
};
|
|
22371
|
+
var ISS_UNREAD = {
|
|
22372
|
+
id: "l",
|
|
22373
|
+
status: "unread",
|
|
22374
|
+
text: "(l) `iss` on every authorization response, error responses included, needs an authorization-request probe"
|
|
22375
|
+
};
|
|
22376
|
+
function judgeServed(id, runtime) {
|
|
22377
|
+
let facts;
|
|
22378
|
+
let note = "";
|
|
22379
|
+
if (!runtime.served && runtime.publicAuth) {
|
|
22380
|
+
facts = runtime.publicAuth;
|
|
22381
|
+
note = ` [the MCP handshake failed: ${runtime.launchError ?? "no reason given"}; the public authorization reads were made]`;
|
|
22382
|
+
} else {
|
|
22383
|
+
const got = servedOrCouldNotJudge(id, "S-5", runtime);
|
|
22384
|
+
if ("cnj" in got) return got.cnj;
|
|
22385
|
+
facts = got.served;
|
|
22386
|
+
}
|
|
22387
|
+
const anchor = `${runtime.root} (served authorization-server metadata)`;
|
|
22388
|
+
const els = [
|
|
22389
|
+
...prmElements(facts.authDocs),
|
|
22390
|
+
...asElements(facts.authServer),
|
|
22391
|
+
H_UNREAD,
|
|
22392
|
+
I_UNREAD,
|
|
22393
|
+
...oidcElements(facts.authDocs),
|
|
22394
|
+
ISS_UNREAD
|
|
22395
|
+
].sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
22396
|
+
const of = (st) => els.filter((e) => e.status === st).map((e) => e.text);
|
|
22397
|
+
const [reds, oks, uns, unread2] = [of("red"), of("ok"), of("unestablished"), of("unread")];
|
|
22398
|
+
if (reds.length > 0)
|
|
22399
|
+
return {
|
|
22400
|
+
id,
|
|
22401
|
+
anchor,
|
|
22402
|
+
state: "non-conforming",
|
|
22403
|
+
verdict: `${reds.join("; ")} (S-5 (f)..(l), read on the wire)${unread2.length > 0 ? `; also not read on the wire: ${unread2.join("; ")}` : ""}${note}`
|
|
22404
|
+
};
|
|
22405
|
+
const parts = [
|
|
22406
|
+
oks.length > 0 ? `established: ${oks.join("; ")}` : "",
|
|
22407
|
+
uns.length > 0 ? `unestablished condition: ${uns.join("; ")}` : ""
|
|
22408
|
+
].filter(Boolean);
|
|
22409
|
+
if (unread2.length === 0)
|
|
22410
|
+
return {
|
|
22411
|
+
id,
|
|
22412
|
+
anchor,
|
|
22413
|
+
state: "present",
|
|
22414
|
+
verdict: `${parts.join(". ")} (S-5 (f)..(l), read on the wire)${note}`
|
|
22415
|
+
};
|
|
22416
|
+
return couldNotJudge(
|
|
22417
|
+
id,
|
|
22418
|
+
anchor,
|
|
22419
|
+
`no element (f)..(l) is contradicted on the wire. ${parts.length > 0 ? `${parts.join(". ")}. ` : ""}not read on the wire: ${unread2.join("; ")} (S-5 (f)..(l))${note}`
|
|
22420
|
+
);
|
|
22421
|
+
}
|
|
21968
22422
|
|
|
21969
22423
|
// src/detectors/s8-token-passthrough.ts
|
|
21970
22424
|
var INCOMING_RE = new RegExp(
|
|
@@ -22273,8 +22727,8 @@ var s10SsrfGuard = {
|
|
|
22273
22727
|
/\b(?:const|let|var)\s*\{([^}]*)\}\s*=\s*(?:args|input|params|payload|delivery|subscription|opts|options|data|(?:req|request)\.(?:body|query|params))\b/g
|
|
22274
22728
|
)) {
|
|
22275
22729
|
for (const part of m[1].split(",")) {
|
|
22276
|
-
const [
|
|
22277
|
-
if (URL_PROP_NAMES.has(
|
|
22730
|
+
const [prop2, rename] = part.split(":").map((s) => s.trim());
|
|
22731
|
+
if (URL_PROP_NAMES.has(prop2)) aliases.add(rename || prop2);
|
|
22278
22732
|
}
|
|
22279
22733
|
}
|
|
22280
22734
|
const templateOnly = first.match(/^`\$\{([^}]+)\}`$/)?.[1] ?? first;
|
|
@@ -22615,9 +23069,9 @@ var isDeclaration = (c) => {
|
|
|
22615
23069
|
return a !== void 0 && /^\s*[A-Za-z_$][\w$]*\??\s*:\s*\S/.test(c.src.shape.slice(a[0], a[1]));
|
|
22616
23070
|
};
|
|
22617
23071
|
function typedFetchNames(s) {
|
|
22618
|
-
const
|
|
22619
|
-
for (const h of s.shape.matchAll(TYPED_FETCH))
|
|
22620
|
-
return
|
|
23072
|
+
const names2 = /* @__PURE__ */ new Set();
|
|
23073
|
+
for (const h of s.shape.matchAll(TYPED_FETCH)) names2.add(h[1]);
|
|
23074
|
+
return names2;
|
|
22621
23075
|
}
|
|
22622
23076
|
function outboundSites(tree) {
|
|
22623
23077
|
const sites = /* @__PURE__ */ new Map();
|
|
@@ -24621,12 +25075,12 @@ function lineAt2(text, offset) {
|
|
|
24621
25075
|
for (let i = 0; i < offset && i < text.length; i++) if (text.charCodeAt(i) === 10) n++;
|
|
24622
25076
|
return n;
|
|
24623
25077
|
}
|
|
24624
|
-
var
|
|
25078
|
+
var OPEN3 = { "(": ")", "[": "]", "{": "}" };
|
|
24625
25079
|
function matchClose2(m, open) {
|
|
24626
25080
|
const stack = [];
|
|
24627
25081
|
for (let i = open; i < m.length; i++) {
|
|
24628
25082
|
const ch = m[i];
|
|
24629
|
-
if (
|
|
25083
|
+
if (OPEN3[ch] !== void 0) stack.push(OPEN3[ch]);
|
|
24630
25084
|
else if (ch === ")" || ch === "]" || ch === "}") {
|
|
24631
25085
|
if (stack.pop() !== ch) return -1;
|
|
24632
25086
|
if (stack.length === 0) return i;
|
|
@@ -24634,13 +25088,13 @@ function matchClose2(m, open) {
|
|
|
24634
25088
|
}
|
|
24635
25089
|
return -1;
|
|
24636
25090
|
}
|
|
24637
|
-
function
|
|
25091
|
+
function splitTop3(m, from, to) {
|
|
24638
25092
|
const parts = [];
|
|
24639
25093
|
let depth = 0;
|
|
24640
25094
|
let start = from;
|
|
24641
25095
|
for (let i = from; i < to; i++) {
|
|
24642
25096
|
const ch = m[i];
|
|
24643
|
-
if (
|
|
25097
|
+
if (OPEN3[ch] !== void 0) depth++;
|
|
24644
25098
|
else if (ch === ")" || ch === "]" || ch === "}") depth--;
|
|
24645
25099
|
else if (ch === "," && depth === 0) {
|
|
24646
25100
|
parts.push([start, i]);
|
|
@@ -24651,14 +25105,14 @@ function splitTop2(m, from, to) {
|
|
|
24651
25105
|
return parts;
|
|
24652
25106
|
}
|
|
24653
25107
|
function listTs(dir, unread2, out = []) {
|
|
24654
|
-
let
|
|
25108
|
+
let names2;
|
|
24655
25109
|
try {
|
|
24656
|
-
|
|
25110
|
+
names2 = readdirSync16(dir);
|
|
24657
25111
|
} catch (err) {
|
|
24658
25112
|
unread2.push(`${dir} could not be listed (${fsErrorCode(err)})`);
|
|
24659
25113
|
return out;
|
|
24660
25114
|
}
|
|
24661
|
-
for (const n of
|
|
25115
|
+
for (const n of names2) {
|
|
24662
25116
|
if (n === "node_modules" || n === "_generated" || n === "__tests__") continue;
|
|
24663
25117
|
const p = join32(dir, n);
|
|
24664
25118
|
let st;
|
|
@@ -24683,7 +25137,7 @@ function discoverBackend(root) {
|
|
|
24683
25137
|
} catch {
|
|
24684
25138
|
return void 0;
|
|
24685
25139
|
}
|
|
24686
|
-
for (let
|
|
25140
|
+
for (let up2 = 0; up2 < 5; up2++) {
|
|
24687
25141
|
const cand = join32(dir, "convex");
|
|
24688
25142
|
if (existsSync22(join32(cand, "schema.ts"))) return cand;
|
|
24689
25143
|
const parent = dirname16(dir);
|
|
@@ -24770,7 +25224,7 @@ function definitionOf(name, files) {
|
|
|
24770
25224
|
let depth = 0;
|
|
24771
25225
|
for (let i = hit.index + hit[0].length; i < f.m.length; i++) {
|
|
24772
25226
|
const ch = f.m[i];
|
|
24773
|
-
if (
|
|
25227
|
+
if (OPEN3[ch] !== void 0) {
|
|
24774
25228
|
depth++;
|
|
24775
25229
|
} else if (ch === ")" || ch === "]" || ch === "}") {
|
|
24776
25230
|
depth--;
|
|
@@ -24803,7 +25257,7 @@ function readHelper(name, files, seen = /* @__PURE__ */ new Set(), depth = 0) {
|
|
|
24803
25257
|
}
|
|
24804
25258
|
return { forwards, optional };
|
|
24805
25259
|
}
|
|
24806
|
-
var
|
|
25260
|
+
var IDENT4 = /^\s*([A-Za-z_$][\w$]*)\s*(?:as\s+[\w$.<>[\]]+\s*)?$/;
|
|
24807
25261
|
function esc6(name) {
|
|
24808
25262
|
return name.replace(/\$/g, "\\$");
|
|
24809
25263
|
}
|
|
@@ -24835,7 +25289,7 @@ function enclosingCall(m, offset) {
|
|
|
24835
25289
|
return void 0;
|
|
24836
25290
|
const close2 = matchClose2(m, i);
|
|
24837
25291
|
if (close2 < 0) return void 0;
|
|
24838
|
-
const index =
|
|
25292
|
+
const index = splitTop3(m, i + 1, close2).findIndex(([a, b]) => offset >= a && offset < b);
|
|
24839
25293
|
return index < 0 ? void 0 : { callee: callee[1], index };
|
|
24840
25294
|
}
|
|
24841
25295
|
}
|
|
@@ -24852,7 +25306,7 @@ function paramOf(callee, index, files) {
|
|
|
24852
25306
|
const open = hit.index + hit[0].length - 1;
|
|
24853
25307
|
const close2 = matchClose2(fr.m, open);
|
|
24854
25308
|
if (close2 < 0) return { file: fr, text: void 0 };
|
|
24855
|
-
const part =
|
|
25309
|
+
const part = splitTop3(fr.m, open + 1, close2)[index];
|
|
24856
25310
|
return part ? { file: fr, text: fr.m.slice(part[0], part[1]).trim(), span: part } : { file: fr, text: void 0 };
|
|
24857
25311
|
}
|
|
24858
25312
|
return void 0;
|
|
@@ -24883,11 +25337,11 @@ function handOff(at, o, len2, files, propertyOf, expression = false) {
|
|
|
24883
25337
|
let argAt = o;
|
|
24884
25338
|
let key = propertyOf;
|
|
24885
25339
|
if (!(/[(,]\s*$/.test(pre) && (expression || /^\s*[,)]/.test(after)))) {
|
|
24886
|
-
const
|
|
25340
|
+
const prop2 = /[{,]\s*([A-Za-z_$][\w$]*)\s*:\s*$/.exec(pre);
|
|
24887
25341
|
const short = !expression && /[{,]\s*$/.test(pre) && /^\s*[,}]/.test(after);
|
|
24888
|
-
if (!
|
|
25342
|
+
if (!prop2 && !short) return void 0;
|
|
24889
25343
|
if (key !== void 0) return "is nested two objects deep, which this scan does not follow";
|
|
24890
|
-
key =
|
|
25344
|
+
key = prop2 ? prop2[1] : at.m.slice(o, o + len2);
|
|
24891
25345
|
let depth = 0;
|
|
24892
25346
|
let brace = -1;
|
|
24893
25347
|
for (let i = o - 1; i >= 0; i--) {
|
|
@@ -24920,8 +25374,8 @@ function readFetchers(files, scan, onCall) {
|
|
|
24920
25374
|
const open = hit.index + hit[0].length - 1;
|
|
24921
25375
|
const close2 = matchClose2(fr.m, open);
|
|
24922
25376
|
if (close2 < 0) continue;
|
|
24923
|
-
const parts =
|
|
24924
|
-
const first = parts[0] ?
|
|
25377
|
+
const parts = splitTop3(fr.m, open + 1, close2);
|
|
25378
|
+
const first = parts[0] ? IDENT4.exec(fr.m.slice(parts[0][0], parts[0][1])) : null;
|
|
24925
25379
|
if (!first) continue;
|
|
24926
25380
|
const fn = enclosingFn(fr.m, hit.index, first[1]);
|
|
24927
25381
|
if (!fn) continue;
|
|
@@ -24999,7 +25453,7 @@ function readFetchers(files, scan, onCall) {
|
|
|
24999
25453
|
cnj(at, o, "has a call here that could not be read");
|
|
25000
25454
|
continue;
|
|
25001
25455
|
}
|
|
25002
|
-
const cp =
|
|
25456
|
+
const cp = splitTop3(at.m, po + 1, pc);
|
|
25003
25457
|
const raw = cp[0] ? at.text.slice(cp[0][0], cp[0][1]) : "";
|
|
25004
25458
|
const lit = /^\s*(?:\/\/[^\n]*\n\s*)*["'`]([\w/]+:[\w]+)["'`]/.exec(raw);
|
|
25005
25459
|
const ref = /^\s*(?:api|internal)\.([\w]+)\.([\w]+)/.exec(raw);
|
|
@@ -25221,7 +25675,7 @@ function scanS28(tree) {
|
|
|
25221
25675
|
scan.calls++;
|
|
25222
25676
|
const line = lineAt2(text, hit.index);
|
|
25223
25677
|
const tool = toolNameBefore(text, hit.index);
|
|
25224
|
-
const parts =
|
|
25678
|
+
const parts = splitTop3(m, open + 1, close2);
|
|
25225
25679
|
let door;
|
|
25226
25680
|
if (parts[0]) {
|
|
25227
25681
|
const rawFirst = text.slice(parts[0][0], parts[0][1]);
|
|
@@ -25669,7 +26123,7 @@ function matchClose3(m, open) {
|
|
|
25669
26123
|
}
|
|
25670
26124
|
return -1;
|
|
25671
26125
|
}
|
|
25672
|
-
function
|
|
26126
|
+
function splitTop4(m, from, to) {
|
|
25673
26127
|
const out = [];
|
|
25674
26128
|
let depth = 0;
|
|
25675
26129
|
let start = from;
|
|
@@ -25760,7 +26214,7 @@ function inlineNarrowing(m, start, close2, end) {
|
|
|
25760
26214
|
const open = p + chain[0].length - 1;
|
|
25761
26215
|
const cbClose = matchClose3(m, open);
|
|
25762
26216
|
if (cbClose < 0) return { unreadable: `a .${chain[1]}( whose closing paren is not found` };
|
|
25763
|
-
const argSpans =
|
|
26217
|
+
const argSpans = splitTop4(m, open + 1, cbClose);
|
|
25764
26218
|
const cbSpan = argSpans[0];
|
|
25765
26219
|
const cb = cbSpan ? m.slice(cbSpan[0], cbSpan[1]) : "";
|
|
25766
26220
|
if (chain[1] === "filter") {
|
|
@@ -25780,10 +26234,10 @@ function inlineNarrowing(m, start, close2, end) {
|
|
|
25780
26234
|
const found = narrowingsOver(m, [param], bodyFrom, bodyTo);
|
|
25781
26235
|
return found.length > 0 ? { narrowing: found[0] } : null;
|
|
25782
26236
|
}
|
|
25783
|
-
function rebound(m,
|
|
26237
|
+
function rebound(m, names2, from, to) {
|
|
25784
26238
|
const out = [];
|
|
25785
26239
|
const region = m.slice(from, to);
|
|
25786
|
-
for (const name of
|
|
26240
|
+
for (const name of names2) {
|
|
25787
26241
|
for (const hit of region.matchAll(
|
|
25788
26242
|
new RegExp(
|
|
25789
26243
|
`\\b(?:const|let|var)\\s+([A-Za-z_$][\\w$]*)\\s*(?::[^=]+)?=\\s*${esc7(name)}\\s*(?:;|$)`,
|
|
@@ -25795,10 +26249,10 @@ function rebound(m, names, from, to) {
|
|
|
25795
26249
|
}
|
|
25796
26250
|
return out;
|
|
25797
26251
|
}
|
|
25798
|
-
function narrowingsOver(m,
|
|
26252
|
+
function narrowingsOver(m, names2, from, to) {
|
|
25799
26253
|
const out = [];
|
|
25800
26254
|
const region = m.slice(from, to);
|
|
25801
|
-
for (const name of
|
|
26255
|
+
for (const name of names2) {
|
|
25802
26256
|
const n = esc7(name);
|
|
25803
26257
|
for (const hit of region.matchAll(/\bscopeFilter(List|Get)\s*\(/g)) {
|
|
25804
26258
|
const open = from + (hit.index ?? 0) + hit[0].length - 1;
|
|
@@ -25853,7 +26307,7 @@ function scanS35(tree) {
|
|
|
25853
26307
|
if (close2 < 0) continue;
|
|
25854
26308
|
res.calls++;
|
|
25855
26309
|
const anchor = `${file.rel}:${lineAt3(m, start)}`;
|
|
25856
|
-
const parts =
|
|
26310
|
+
const parts = splitTop4(m, open + 1, close2);
|
|
25857
26311
|
const first = parts[0] ? raw.slice(parts[0][0], parts[0][1]) : "";
|
|
25858
26312
|
const cast = String.raw`(?:\s+as\s+[\w$.<>[\] ]+)?\s*$`;
|
|
25859
26313
|
const lit = new RegExp(String.raw`^\s*["'\x60]([\w/]+:[\w]+)["'\x60]${cast}`).exec(first);
|
|
@@ -25877,12 +26331,12 @@ function scanS35(tree) {
|
|
|
25877
26331
|
}
|
|
25878
26332
|
const argText2 = parts.slice(1).map(([a, b]) => m.slice(a, b)).join(",");
|
|
25879
26333
|
const carried = CARRY_WORD.test(argText2);
|
|
25880
|
-
const
|
|
26334
|
+
const names2 = boundNames(m, start);
|
|
25881
26335
|
const end = blockEnd(m, start);
|
|
25882
26336
|
const inline = inlineNarrowing(m, start, close2, end);
|
|
25883
26337
|
const narrowings = [
|
|
25884
26338
|
...inline && "narrowing" in inline ? [inline.narrowing] : [],
|
|
25885
|
-
...narrowingsOver(m, [...
|
|
26339
|
+
...narrowingsOver(m, [...names2, ...rebound(m, names2, close2 + 1, end)], close2 + 1, end)
|
|
25886
26340
|
].sort((a, b) => a.offset - b.offset);
|
|
25887
26341
|
if (narrowings.length === 0 && inline && "unreadable" in inline && !carried) {
|
|
25888
26342
|
res.cnj.push({
|
|
@@ -25894,7 +26348,7 @@ function scanS35(tree) {
|
|
|
25894
26348
|
if (narrowings.length === 0 || carried) {
|
|
25895
26349
|
res.ok.push({
|
|
25896
26350
|
anchor,
|
|
25897
|
-
note:
|
|
26351
|
+
note: names2.length === 0 && !inline ? `${anchor} ${door}: result not bound, nothing narrows it` : `${anchor} ${door}`
|
|
25898
26352
|
});
|
|
25899
26353
|
continue;
|
|
25900
26354
|
}
|
|
@@ -26666,14 +27120,14 @@ function scanS37(tree) {
|
|
|
26666
27120
|
}
|
|
26667
27121
|
for (const k of outputSinks(s)) {
|
|
26668
27122
|
const body = s.shape.slice(k.at, k.end);
|
|
26669
|
-
const
|
|
27123
|
+
const names2 = [...bound].filter(
|
|
26670
27124
|
(n) => new RegExp(String.raw`(?<![\w$.])${n}(?![\w$])`).test(body)
|
|
26671
27125
|
);
|
|
26672
27126
|
const direct = reads.find((r) => r.at >= k.at && r.at <= k.end);
|
|
26673
27127
|
const secret = [...secretKeys].find(
|
|
26674
27128
|
(n) => new RegExp(String.raw`\.${n}(?![\w$])`).test(body)
|
|
26675
27129
|
);
|
|
26676
|
-
const what =
|
|
27130
|
+
const what = names2[0] ?? (direct ? `${direct.name ?? "an environment value"}` : secret);
|
|
26677
27131
|
if (what !== void 0) {
|
|
26678
27132
|
const anchor = anchorAt(s, k.at);
|
|
26679
27133
|
res.red.push({
|
|
@@ -26952,8 +27406,8 @@ function scanS38(tree) {
|
|
|
26952
27406
|
if (requesting2.length === 0) continue;
|
|
26953
27407
|
const f = requesting2[0];
|
|
26954
27408
|
const anchor = anchorAt(s, f.at);
|
|
26955
|
-
const
|
|
26956
|
-
const kind = group.length === 1 ? "calls itself" : `is in a recursion cycle (${
|
|
27409
|
+
const names2 = group.map((g) => `\`${g.name}\``).join(" -> ");
|
|
27410
|
+
const kind = group.length === 1 ? "calls itself" : `is in a recursion cycle (${names2})`;
|
|
26957
27411
|
const text = group.map((g) => s.shape.slice(g.at, g.to)).join("\n");
|
|
26958
27412
|
if (/\b(?:sleep|delay|setTimeout)\s*\(|retry-?after|attempt/i.test(text) || /\b429\b|\b503\b/.test(text)) {
|
|
26959
27413
|
res.cnj.push({
|
|
@@ -28319,7 +28773,7 @@ function scanS42(tree) {
|
|
|
28319
28773
|
if (close2 < 0) continue;
|
|
28320
28774
|
const at = `${f.rel}:${lineAt2(text, hit.index)}`;
|
|
28321
28775
|
const tool = toolNameBefore(text, hit.index).name ?? "(unnamed tool)";
|
|
28322
|
-
const parts =
|
|
28776
|
+
const parts = splitTop3(m, open + 1, close2);
|
|
28323
28777
|
const first = parts[0] ? text.slice(parts[0][0], parts[0][1]) : "";
|
|
28324
28778
|
const lit = /^\s*["'`]([\w/]+:[\w]+)["'`]/.exec(first);
|
|
28325
28779
|
const ref = /^\s*(?:api|internal)\.([\w]+)\.([\w]+)/.exec(first);
|
|
@@ -28503,7 +28957,7 @@ function runStatic4(tree) {
|
|
|
28503
28957
|
`S44 positive control FAILED: sees=${controls.sees} spares=${controls.spares} \u2014 reader broken, verdict untrustworthy`
|
|
28504
28958
|
);
|
|
28505
28959
|
const inProduct = (a) => isProductSource(a.slice(0, a.lastIndexOf(":")));
|
|
28506
|
-
const tools = findRegisteredTools(tree
|
|
28960
|
+
const tools = findRegisteredTools(tree, isProductSource);
|
|
28507
28961
|
const unresolved = findUnresolvedToolSites(tree).filter(inProduct);
|
|
28508
28962
|
if (tools.length === 0) {
|
|
28509
28963
|
const surface = toolSurfaceAnchor(tree);
|
|
@@ -32378,7 +32832,7 @@ function judgeAttempt(a) {
|
|
|
32378
32832
|
return { kind: "unread", text: `${at} (neither accepted nor refused)` };
|
|
32379
32833
|
}
|
|
32380
32834
|
function runServed5(runtime) {
|
|
32381
|
-
const r =
|
|
32835
|
+
const r = judgeServed2(runtime);
|
|
32382
32836
|
if (!runtime.launchError || !runtime.publicAuth) return r;
|
|
32383
32837
|
const note = ` [the MCP handshake failed: ${runtime.launchError}; the public authorization reads were made]`;
|
|
32384
32838
|
return {
|
|
@@ -32387,7 +32841,7 @@ function runServed5(runtime) {
|
|
|
32387
32841
|
...r.reason !== void 0 ? { reason: `${r.reason}${note}` } : {}
|
|
32388
32842
|
};
|
|
32389
32843
|
}
|
|
32390
|
-
function
|
|
32844
|
+
function judgeServed2(runtime) {
|
|
32391
32845
|
let facts;
|
|
32392
32846
|
if (!runtime.served && runtime.publicAuth) facts = runtime.publicAuth;
|
|
32393
32847
|
else {
|
|
@@ -33128,6 +33582,1659 @@ var s50ServedDiscovery = {
|
|
|
33128
33582
|
runServed: runServed7
|
|
33129
33583
|
};
|
|
33130
33584
|
|
|
33585
|
+
// src/detectors/s51-served-output.ts
|
|
33586
|
+
import * as ts2 from "typescript";
|
|
33587
|
+
|
|
33588
|
+
// src/detectors/jsonSchemaCheck.ts
|
|
33589
|
+
var ANNOTATIONS = /* @__PURE__ */ new Set([
|
|
33590
|
+
"$schema",
|
|
33591
|
+
"$id",
|
|
33592
|
+
"$comment",
|
|
33593
|
+
"$defs",
|
|
33594
|
+
"definitions",
|
|
33595
|
+
"$vocabulary",
|
|
33596
|
+
"$anchor",
|
|
33597
|
+
"title",
|
|
33598
|
+
"description",
|
|
33599
|
+
"default",
|
|
33600
|
+
"deprecated",
|
|
33601
|
+
"readOnly",
|
|
33602
|
+
"writeOnly",
|
|
33603
|
+
"examples",
|
|
33604
|
+
"format",
|
|
33605
|
+
"contentEncoding",
|
|
33606
|
+
"contentMediaType",
|
|
33607
|
+
"contentSchema"
|
|
33608
|
+
]);
|
|
33609
|
+
var ASSERTED = /* @__PURE__ */ new Set([
|
|
33610
|
+
"$ref",
|
|
33611
|
+
"allOf",
|
|
33612
|
+
"anyOf",
|
|
33613
|
+
"oneOf",
|
|
33614
|
+
"not",
|
|
33615
|
+
"if",
|
|
33616
|
+
"then",
|
|
33617
|
+
"else",
|
|
33618
|
+
"properties",
|
|
33619
|
+
"patternProperties",
|
|
33620
|
+
"additionalProperties",
|
|
33621
|
+
"propertyNames",
|
|
33622
|
+
"dependentSchemas",
|
|
33623
|
+
"prefixItems",
|
|
33624
|
+
"items",
|
|
33625
|
+
"contains",
|
|
33626
|
+
"type",
|
|
33627
|
+
"enum",
|
|
33628
|
+
"const",
|
|
33629
|
+
"multipleOf",
|
|
33630
|
+
"maximum",
|
|
33631
|
+
"exclusiveMaximum",
|
|
33632
|
+
"minimum",
|
|
33633
|
+
"exclusiveMinimum",
|
|
33634
|
+
"maxLength",
|
|
33635
|
+
"minLength",
|
|
33636
|
+
"pattern",
|
|
33637
|
+
"maxItems",
|
|
33638
|
+
"minItems",
|
|
33639
|
+
"uniqueItems",
|
|
33640
|
+
"maxContains",
|
|
33641
|
+
"minContains",
|
|
33642
|
+
"maxProperties",
|
|
33643
|
+
"minProperties",
|
|
33644
|
+
"required",
|
|
33645
|
+
"dependentRequired"
|
|
33646
|
+
]);
|
|
33647
|
+
var NOT_IMPLEMENTED = /* @__PURE__ */ new Set([
|
|
33648
|
+
"$dynamicRef",
|
|
33649
|
+
"$dynamicAnchor",
|
|
33650
|
+
"unevaluatedItems",
|
|
33651
|
+
"unevaluatedProperties"
|
|
33652
|
+
]);
|
|
33653
|
+
var SCHEMA_KEYWORD_CENSUS = /* @__PURE__ */ new Set([
|
|
33654
|
+
...ANNOTATIONS,
|
|
33655
|
+
...ASSERTED,
|
|
33656
|
+
...NOT_IMPLEMENTED
|
|
33657
|
+
]);
|
|
33658
|
+
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
33659
|
+
var has4 = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
|
|
33660
|
+
var nonNegInt = (v) => typeof v === "number" && Number.isInteger(v) && v >= 0;
|
|
33661
|
+
var num = (v) => typeof v === "number" && Number.isFinite(v);
|
|
33662
|
+
var strings = (v) => Array.isArray(v) && v.every((x) => typeof x === "string");
|
|
33663
|
+
var KEYWORD_SHAPE = {
|
|
33664
|
+
multipleOf: [(v) => num(v) && v > 0, "a number above 0"],
|
|
33665
|
+
maximum: [num, "a number"],
|
|
33666
|
+
exclusiveMaximum: [num, "a number"],
|
|
33667
|
+
minimum: [num, "a number"],
|
|
33668
|
+
exclusiveMinimum: [num, "a number"],
|
|
33669
|
+
maxLength: [nonNegInt, "a non-negative integer"],
|
|
33670
|
+
minLength: [nonNegInt, "a non-negative integer"],
|
|
33671
|
+
maxItems: [nonNegInt, "a non-negative integer"],
|
|
33672
|
+
minItems: [nonNegInt, "a non-negative integer"],
|
|
33673
|
+
maxContains: [nonNegInt, "a non-negative integer"],
|
|
33674
|
+
minContains: [nonNegInt, "a non-negative integer"],
|
|
33675
|
+
maxProperties: [nonNegInt, "a non-negative integer"],
|
|
33676
|
+
minProperties: [nonNegInt, "a non-negative integer"],
|
|
33677
|
+
pattern: [(v) => typeof v === "string", "a string"],
|
|
33678
|
+
uniqueItems: [(v) => typeof v === "boolean", "a boolean"],
|
|
33679
|
+
required: [strings, "an array of strings"],
|
|
33680
|
+
dependentRequired: [
|
|
33681
|
+
(v) => isObj4(v) && Object.values(v).every(strings),
|
|
33682
|
+
"an object of string arrays"
|
|
33683
|
+
],
|
|
33684
|
+
properties: [isObj4, "an object"],
|
|
33685
|
+
patternProperties: [isObj4, "an object"],
|
|
33686
|
+
dependentSchemas: [isObj4, "an object"]
|
|
33687
|
+
};
|
|
33688
|
+
function typeOf(v) {
|
|
33689
|
+
if (v === null) return "null";
|
|
33690
|
+
if (Array.isArray(v)) return "array";
|
|
33691
|
+
if (typeof v === "number") return Number.isInteger(v) ? "integer" : "number";
|
|
33692
|
+
return typeof v;
|
|
33693
|
+
}
|
|
33694
|
+
function matchesType(v, t) {
|
|
33695
|
+
const k = typeOf(v);
|
|
33696
|
+
if (t === "number") return k === "number" || k === "integer";
|
|
33697
|
+
return k === t;
|
|
33698
|
+
}
|
|
33699
|
+
function jsonEqual(a, b) {
|
|
33700
|
+
if (a === b) return true;
|
|
33701
|
+
if (typeof a === "number" && typeof b === "number") return a === b;
|
|
33702
|
+
if (Array.isArray(a) && Array.isArray(b))
|
|
33703
|
+
return a.length === b.length && a.every((x, i) => jsonEqual(x, b[i]));
|
|
33704
|
+
if (isObj4(a) && isObj4(b)) {
|
|
33705
|
+
const ka = Object.keys(a);
|
|
33706
|
+
const kb2 = Object.keys(b);
|
|
33707
|
+
return ka.length === kb2.length && ka.every((k) => has4(b, k) && jsonEqual(a[k], b[k]));
|
|
33708
|
+
}
|
|
33709
|
+
return false;
|
|
33710
|
+
}
|
|
33711
|
+
function resolvePointer(root, ref) {
|
|
33712
|
+
if (ref === "#") return { ok: true, v: root };
|
|
33713
|
+
if (!ref.startsWith("#/")) return { ok: false };
|
|
33714
|
+
let cur = root;
|
|
33715
|
+
for (const raw of ref.slice(2).split("/")) {
|
|
33716
|
+
const seg = decodeURIComponent(raw).replace(/~1/g, "/").replace(/~0/g, "~");
|
|
33717
|
+
if (Array.isArray(cur) && /^\d+$/.test(seg)) cur = cur[Number(seg)];
|
|
33718
|
+
else if (isObj4(cur) && has4(cur, seg)) cur = cur[seg];
|
|
33719
|
+
else return { ok: false };
|
|
33720
|
+
}
|
|
33721
|
+
return { ok: true, v: cur };
|
|
33722
|
+
}
|
|
33723
|
+
var VALID = { kind: "valid" };
|
|
33724
|
+
function regex(p) {
|
|
33725
|
+
if (typeof p !== "string") return null;
|
|
33726
|
+
try {
|
|
33727
|
+
return new RegExp(p, "u");
|
|
33728
|
+
} catch {
|
|
33729
|
+
return null;
|
|
33730
|
+
}
|
|
33731
|
+
}
|
|
33732
|
+
function checkSchema(schema, value, root = schema, path = "$", depth = 0) {
|
|
33733
|
+
if (depth > 64) return { kind: "unread", path, why: "schema recursion deeper than 64 levels" };
|
|
33734
|
+
if (schema === true) return VALID;
|
|
33735
|
+
if (schema === false) return { kind: "invalid", path, why: "the schema is `false`" };
|
|
33736
|
+
if (!isObj4(schema))
|
|
33737
|
+
return {
|
|
33738
|
+
kind: "unread",
|
|
33739
|
+
path,
|
|
33740
|
+
why: `a schema that is a ${typeOf(schema)}, not an object or a boolean`
|
|
33741
|
+
};
|
|
33742
|
+
for (const k of Object.keys(schema)) {
|
|
33743
|
+
if (NOT_IMPLEMENTED.has(k))
|
|
33744
|
+
return { kind: "unread", path, why: `keyword \`${k}\` is not implemented` };
|
|
33745
|
+
if (!ANNOTATIONS.has(k) && !ASSERTED.has(k))
|
|
33746
|
+
return { kind: "unread", path, why: `keyword \`${k}\` is outside the 2020-12 census` };
|
|
33747
|
+
}
|
|
33748
|
+
for (const [k, [ok, want]] of Object.entries(KEYWORD_SHAPE))
|
|
33749
|
+
if (has4(schema, k) && !ok(schema[k]))
|
|
33750
|
+
return {
|
|
33751
|
+
kind: "unread",
|
|
33752
|
+
path,
|
|
33753
|
+
why: `keyword \`${k}\` carries ${JSON.stringify(schema[k])}, not ${want}`
|
|
33754
|
+
};
|
|
33755
|
+
const sub = (s, v, p) => checkSchema(s, v, root, p, depth + 1);
|
|
33756
|
+
const fail = (why) => ({ kind: "invalid", path, why });
|
|
33757
|
+
const all = (results) => {
|
|
33758
|
+
const unread2 = results.find((r) => r.kind === "unread");
|
|
33759
|
+
if (unread2) return unread2;
|
|
33760
|
+
return results.find((r) => r.kind === "invalid") ?? VALID;
|
|
33761
|
+
};
|
|
33762
|
+
const out = [];
|
|
33763
|
+
if (schema.$ref !== void 0) {
|
|
33764
|
+
if (typeof schema.$ref !== "string")
|
|
33765
|
+
return { kind: "unread", path, why: "a `$ref` that is not a string" };
|
|
33766
|
+
const target = resolvePointer(root, schema.$ref);
|
|
33767
|
+
if (!target.ok)
|
|
33768
|
+
return {
|
|
33769
|
+
kind: "unread",
|
|
33770
|
+
path,
|
|
33771
|
+
why: `\`$ref\` ${schema.$ref} is not a resolvable local pointer`
|
|
33772
|
+
};
|
|
33773
|
+
out.push(sub(target.v, value, path));
|
|
33774
|
+
}
|
|
33775
|
+
if (schema.type !== void 0) {
|
|
33776
|
+
const types = Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
33777
|
+
if (types.some((t) => typeof t !== "string"))
|
|
33778
|
+
return { kind: "unread", path, why: "a `type` that is not a string or a list of strings" };
|
|
33779
|
+
if (!types.some((t) => matchesType(value, t)))
|
|
33780
|
+
out.push(fail(`a ${typeOf(value)} where the schema says ${types.join(" | ")}`));
|
|
33781
|
+
}
|
|
33782
|
+
if (schema.enum !== void 0) {
|
|
33783
|
+
if (!Array.isArray(schema.enum))
|
|
33784
|
+
return { kind: "unread", path, why: "an `enum` that is not an array" };
|
|
33785
|
+
if (!schema.enum.some((e) => jsonEqual(e, value))) out.push(fail("a value outside its `enum`"));
|
|
33786
|
+
}
|
|
33787
|
+
if (has4(schema, "const") && !jsonEqual(schema.const, value))
|
|
33788
|
+
out.push(fail("a value other than its `const`"));
|
|
33789
|
+
for (const key of ["allOf", "anyOf", "oneOf"]) {
|
|
33790
|
+
const list = schema[key];
|
|
33791
|
+
if (list === void 0) continue;
|
|
33792
|
+
if (!Array.isArray(list)) return { kind: "unread", path, why: `\`${key}\` is not an array` };
|
|
33793
|
+
const results = list.map((s, i) => sub(s, value, `${path}<${key}[${i}]>`));
|
|
33794
|
+
const unread2 = results.find((r) => r.kind === "unread");
|
|
33795
|
+
if (unread2) return unread2;
|
|
33796
|
+
const passed = results.filter((r) => r.kind === "valid").length;
|
|
33797
|
+
if (key === "allOf" && passed < list.length)
|
|
33798
|
+
out.push(results.find((r) => r.kind === "invalid"));
|
|
33799
|
+
if (key === "anyOf" && passed === 0) out.push(fail("no `anyOf` branch validates"));
|
|
33800
|
+
if (key === "oneOf" && passed !== 1)
|
|
33801
|
+
out.push(fail(`${passed} \`oneOf\` branches validate, exactly one must`));
|
|
33802
|
+
}
|
|
33803
|
+
if (schema.not !== void 0) {
|
|
33804
|
+
const r = sub(schema.not, value, `${path}<not>`);
|
|
33805
|
+
if (r.kind === "unread") return r;
|
|
33806
|
+
if (r.kind === "valid") out.push(fail("the value validates against `not`"));
|
|
33807
|
+
}
|
|
33808
|
+
if (schema.if !== void 0) {
|
|
33809
|
+
const r = sub(schema.if, value, `${path}<if>`);
|
|
33810
|
+
if (r.kind === "unread") return r;
|
|
33811
|
+
const branch = r.kind === "valid" ? schema.then : schema.else;
|
|
33812
|
+
if (branch !== void 0) out.push(sub(branch, value, path));
|
|
33813
|
+
}
|
|
33814
|
+
if (typeof value === "number") {
|
|
33815
|
+
const n = (k) => typeof schema[k] === "number" ? schema[k] : void 0;
|
|
33816
|
+
const mo = n("multipleOf");
|
|
33817
|
+
if (mo !== void 0 && mo > 0 && !Number.isInteger(value / mo))
|
|
33818
|
+
out.push(fail(`not a multiple of ${mo}`));
|
|
33819
|
+
if (n("maximum") !== void 0 && value > n("maximum"))
|
|
33820
|
+
out.push(fail("above `maximum`"));
|
|
33821
|
+
if (n("minimum") !== void 0 && value < n("minimum"))
|
|
33822
|
+
out.push(fail("below `minimum`"));
|
|
33823
|
+
if (n("exclusiveMaximum") !== void 0 && value >= n("exclusiveMaximum"))
|
|
33824
|
+
out.push(fail("not below `exclusiveMaximum`"));
|
|
33825
|
+
if (n("exclusiveMinimum") !== void 0 && value <= n("exclusiveMinimum"))
|
|
33826
|
+
out.push(fail("not above `exclusiveMinimum`"));
|
|
33827
|
+
}
|
|
33828
|
+
if (typeof value === "string") {
|
|
33829
|
+
const len2 = [...value].length;
|
|
33830
|
+
if (typeof schema.maxLength === "number" && len2 > schema.maxLength)
|
|
33831
|
+
out.push(fail("longer than `maxLength`"));
|
|
33832
|
+
if (typeof schema.minLength === "number" && len2 < schema.minLength)
|
|
33833
|
+
out.push(fail("shorter than `minLength`"));
|
|
33834
|
+
if (schema.pattern !== void 0) {
|
|
33835
|
+
const re = regex(schema.pattern);
|
|
33836
|
+
if (!re)
|
|
33837
|
+
return {
|
|
33838
|
+
kind: "unread",
|
|
33839
|
+
path,
|
|
33840
|
+
why: `\`pattern\` ${String(schema.pattern)} does not compile`
|
|
33841
|
+
};
|
|
33842
|
+
if (!re.test(value)) out.push(fail(`does not match \`pattern\` ${schema.pattern}`));
|
|
33843
|
+
}
|
|
33844
|
+
}
|
|
33845
|
+
if (Array.isArray(value)) {
|
|
33846
|
+
if (typeof schema.maxItems === "number" && value.length > schema.maxItems)
|
|
33847
|
+
out.push(fail("more items than `maxItems`"));
|
|
33848
|
+
if (typeof schema.minItems === "number" && value.length < schema.minItems)
|
|
33849
|
+
out.push(fail("fewer items than `minItems`"));
|
|
33850
|
+
if (schema.uniqueItems === true && value.some((x, i) => value.slice(i + 1).some((y) => jsonEqual(x, y))))
|
|
33851
|
+
out.push(fail("duplicate items under `uniqueItems`"));
|
|
33852
|
+
const prefix = schema.prefixItems;
|
|
33853
|
+
if (prefix !== void 0 && !Array.isArray(prefix))
|
|
33854
|
+
return { kind: "unread", path, why: "`prefixItems` is not an array" };
|
|
33855
|
+
const np = Array.isArray(prefix) ? prefix.length : 0;
|
|
33856
|
+
value.forEach((item, i) => {
|
|
33857
|
+
if (i < np) out.push(sub(prefix[i], item, `${path}[${i}]`));
|
|
33858
|
+
else if (schema.items !== void 0) out.push(sub(schema.items, item, `${path}[${i}]`));
|
|
33859
|
+
});
|
|
33860
|
+
if (schema.contains !== void 0) {
|
|
33861
|
+
const hits = value.map((x, i) => sub(schema.contains, x, `${path}[${i}]`));
|
|
33862
|
+
const unread2 = hits.find((r) => r.kind === "unread");
|
|
33863
|
+
if (unread2) return unread2;
|
|
33864
|
+
const count = hits.filter((r) => r.kind === "valid").length;
|
|
33865
|
+
const min = typeof schema.minContains === "number" ? schema.minContains : 1;
|
|
33866
|
+
if (count < min) out.push(fail(`${count} item(s) match \`contains\`, at least ${min} must`));
|
|
33867
|
+
if (typeof schema.maxContains === "number" && count > schema.maxContains)
|
|
33868
|
+
out.push(fail(`${count} item(s) match \`contains\`, at most ${schema.maxContains} may`));
|
|
33869
|
+
}
|
|
33870
|
+
}
|
|
33871
|
+
if (isObj4(value)) {
|
|
33872
|
+
const keys = Object.keys(value);
|
|
33873
|
+
if (typeof schema.maxProperties === "number" && keys.length > schema.maxProperties)
|
|
33874
|
+
out.push(fail("more properties than `maxProperties`"));
|
|
33875
|
+
if (typeof schema.minProperties === "number" && keys.length < schema.minProperties)
|
|
33876
|
+
out.push(fail("fewer properties than `minProperties`"));
|
|
33877
|
+
if (schema.required !== void 0) {
|
|
33878
|
+
if (!Array.isArray(schema.required))
|
|
33879
|
+
return { kind: "unread", path, why: "`required` is not an array" };
|
|
33880
|
+
const missing = schema.required.filter((r) => typeof r === "string" && !has4(value, r));
|
|
33881
|
+
if (missing.length > 0)
|
|
33882
|
+
out.push(fail(`required ${missing.map((m) => `\`${m}\``).join(", ")} missing`));
|
|
33883
|
+
}
|
|
33884
|
+
if (isObj4(schema.dependentRequired)) {
|
|
33885
|
+
for (const [k, deps] of Object.entries(schema.dependentRequired)) {
|
|
33886
|
+
if (!has4(value, k) || !Array.isArray(deps)) continue;
|
|
33887
|
+
const missing = deps.filter((d) => typeof d === "string" && !has4(value, d));
|
|
33888
|
+
if (missing.length > 0) out.push(fail(`\`${k}\` present without ${missing.join(", ")}`));
|
|
33889
|
+
}
|
|
33890
|
+
}
|
|
33891
|
+
if (isObj4(schema.dependentSchemas)) {
|
|
33892
|
+
for (const [k, s] of Object.entries(schema.dependentSchemas))
|
|
33893
|
+
if (has4(value, k)) out.push(sub(s, value, path));
|
|
33894
|
+
}
|
|
33895
|
+
const props = isObj4(schema.properties) ? schema.properties : {};
|
|
33896
|
+
const patterns = [];
|
|
33897
|
+
if (isObj4(schema.patternProperties)) {
|
|
33898
|
+
for (const [p, s] of Object.entries(schema.patternProperties)) {
|
|
33899
|
+
const re = regex(p);
|
|
33900
|
+
if (!re)
|
|
33901
|
+
return { kind: "unread", path, why: `\`patternProperties\` key ${p} does not compile` };
|
|
33902
|
+
patterns.push([re, s]);
|
|
33903
|
+
}
|
|
33904
|
+
}
|
|
33905
|
+
for (const k of keys) {
|
|
33906
|
+
const p = `${path}.${k}`;
|
|
33907
|
+
let evaluated = false;
|
|
33908
|
+
if (has4(props, k)) {
|
|
33909
|
+
out.push(sub(props[k], value[k], p));
|
|
33910
|
+
evaluated = true;
|
|
33911
|
+
}
|
|
33912
|
+
for (const [re, s] of patterns) {
|
|
33913
|
+
if (re.test(k)) {
|
|
33914
|
+
out.push(sub(s, value[k], p));
|
|
33915
|
+
evaluated = true;
|
|
33916
|
+
}
|
|
33917
|
+
}
|
|
33918
|
+
if (!evaluated && schema.additionalProperties !== void 0)
|
|
33919
|
+
out.push(sub(schema.additionalProperties, value[k], p));
|
|
33920
|
+
if (schema.propertyNames !== void 0)
|
|
33921
|
+
out.push(sub(schema.propertyNames, k, `${path}<key ${k}>`));
|
|
33922
|
+
}
|
|
33923
|
+
}
|
|
33924
|
+
return all(out);
|
|
33925
|
+
}
|
|
33926
|
+
function schemaCheckControls() {
|
|
33927
|
+
const s = { type: "object", properties: { n: { type: "integer" } }, required: ["n"] };
|
|
33928
|
+
return {
|
|
33929
|
+
sees: checkSchema(s, { n: "x" }).kind === "invalid" && checkSchema(s, {}).kind === "invalid",
|
|
33930
|
+
spares: checkSchema(s, { n: 1, extra: true }).kind === "valid",
|
|
33931
|
+
refuses: checkSchema({ unevaluatedProperties: false }, {}).kind === "unread"
|
|
33932
|
+
};
|
|
33933
|
+
}
|
|
33934
|
+
|
|
33935
|
+
// src/detectors/outputContract.ts
|
|
33936
|
+
import * as ts from "typescript";
|
|
33937
|
+
var lineOfPos = (sf, pos) => sf.getLineAndCharacterOfPosition(pos).line + 1;
|
|
33938
|
+
var startLine = (n) => lineOfPos(n.getSourceFile(), n.getStart(n.getSourceFile()));
|
|
33939
|
+
function isFunctionLikeExpr(e) {
|
|
33940
|
+
return ts.isArrowFunction(e) || ts.isFunctionExpression(e);
|
|
33941
|
+
}
|
|
33942
|
+
var unwrapExpr = (e) => {
|
|
33943
|
+
let x = e;
|
|
33944
|
+
while (ts.isParenthesizedExpression(x) || ts.isAsExpression(x) || ts.isSatisfiesExpression(x) || ts.isNonNullExpression(x) || ts.isAwaitExpression(x) || ts.isTypeAssertionExpression(x))
|
|
33945
|
+
x = x.expression;
|
|
33946
|
+
return x;
|
|
33947
|
+
};
|
|
33948
|
+
function sameFileFunction(sf, name) {
|
|
33949
|
+
let found;
|
|
33950
|
+
const visit = (n) => {
|
|
33951
|
+
if (found) return;
|
|
33952
|
+
if (ts.isFunctionDeclaration(n) && n.name?.text === name && n.body) found = n;
|
|
33953
|
+
else if (ts.isVariableDeclaration(n) && ts.isIdentifier(n.name) && n.name.text === name && n.initializer && isFunctionLikeExpr(unwrapExpr(n.initializer)))
|
|
33954
|
+
found = unwrapExpr(n.initializer);
|
|
33955
|
+
else ts.forEachChild(n, visit);
|
|
33956
|
+
};
|
|
33957
|
+
visit(sf);
|
|
33958
|
+
return found;
|
|
33959
|
+
}
|
|
33960
|
+
function completes(stmts) {
|
|
33961
|
+
if (stmts.length === 0) return true;
|
|
33962
|
+
return stmtCompletes(stmts[stmts.length - 1]);
|
|
33963
|
+
}
|
|
33964
|
+
function stmtCompletes(s) {
|
|
33965
|
+
if (ts.isReturnStatement(s) || ts.isThrowStatement(s)) return false;
|
|
33966
|
+
if (ts.isBlock(s)) return completes(s.statements);
|
|
33967
|
+
if (ts.isIfStatement(s))
|
|
33968
|
+
return !s.elseStatement || stmtCompletes(s.thenStatement) || stmtCompletes(s.elseStatement);
|
|
33969
|
+
if (ts.isTryStatement(s)) {
|
|
33970
|
+
if (s.finallyBlock && !completes(s.finallyBlock.statements)) return false;
|
|
33971
|
+
return completes(s.tryBlock.statements) || (s.catchClause ? completes(s.catchClause.block.statements) : false);
|
|
33972
|
+
}
|
|
33973
|
+
if (ts.isSwitchStatement(s)) {
|
|
33974
|
+
const clauses = s.caseBlock.clauses;
|
|
33975
|
+
if (!clauses.some((c) => ts.isDefaultClause(c))) return true;
|
|
33976
|
+
return clauses.some((c) => c.statements.length === 0 || completes(c.statements));
|
|
33977
|
+
}
|
|
33978
|
+
return true;
|
|
33979
|
+
}
|
|
33980
|
+
function collectReturns(body, sf, rel, out, inCatch = false) {
|
|
33981
|
+
const visit = (n, catching) => {
|
|
33982
|
+
if (n !== body && ts.isFunctionLike(n)) return;
|
|
33983
|
+
if (ts.isReturnStatement(n)) {
|
|
33984
|
+
out.push({
|
|
33985
|
+
anchor: `${rel}:${startLine(n)}`,
|
|
33986
|
+
...n.expression ? { expr: n.expression } : {},
|
|
33987
|
+
form: n.expression ? "return" : "bare-return",
|
|
33988
|
+
inCatch: catching
|
|
33989
|
+
});
|
|
33990
|
+
return;
|
|
33991
|
+
}
|
|
33992
|
+
if (ts.isCatchClause(n)) {
|
|
33993
|
+
visit(n.block, true);
|
|
33994
|
+
return;
|
|
33995
|
+
}
|
|
33996
|
+
ts.forEachChild(n, (c) => visit(c, catching));
|
|
33997
|
+
};
|
|
33998
|
+
visit(body, inCatch);
|
|
33999
|
+
void sf;
|
|
34000
|
+
}
|
|
34001
|
+
function functionReturns(fn, sf, rel) {
|
|
34002
|
+
const out = [];
|
|
34003
|
+
const body = fn.body;
|
|
34004
|
+
if (!body) return out;
|
|
34005
|
+
if (!ts.isBlock(body)) {
|
|
34006
|
+
out.push({
|
|
34007
|
+
anchor: `${rel}:${startLine(body)}`,
|
|
34008
|
+
expr: body,
|
|
34009
|
+
form: "concise",
|
|
34010
|
+
inCatch: false
|
|
34011
|
+
});
|
|
34012
|
+
return out;
|
|
34013
|
+
}
|
|
34014
|
+
collectReturns(body, sf, rel, out);
|
|
34015
|
+
if (completes(body.statements))
|
|
34016
|
+
out.push({
|
|
34017
|
+
anchor: `${rel}:${lineOfPos(sf, body.getEnd())}`,
|
|
34018
|
+
form: "fall-through",
|
|
34019
|
+
inCatch: false
|
|
34020
|
+
});
|
|
34021
|
+
return out;
|
|
34022
|
+
}
|
|
34023
|
+
function registrationCall(sf, line, name) {
|
|
34024
|
+
let best;
|
|
34025
|
+
const visit = (n) => {
|
|
34026
|
+
const a = startLine(n);
|
|
34027
|
+
const b = lineOfPos(sf, n.getEnd());
|
|
34028
|
+
if (a > line || b < line) return;
|
|
34029
|
+
if (ts.isCallExpression(n)) {
|
|
34030
|
+
const names2 = n.arguments.some((arg) => {
|
|
34031
|
+
const u = unwrapExpr(arg);
|
|
34032
|
+
if (ts.isStringLiteralLike(u)) return u.text === name;
|
|
34033
|
+
return (ts.isIdentifier(u) || ts.isPropertyAccessExpression(u)) && startLine(u) === line;
|
|
34034
|
+
});
|
|
34035
|
+
if (names2 && n.arguments.some((arg) => {
|
|
34036
|
+
const x = unwrapExpr(arg);
|
|
34037
|
+
return isFunctionLikeExpr(x) || ts.isIdentifier(x) || ts.isCallExpression(x);
|
|
34038
|
+
}))
|
|
34039
|
+
best = n;
|
|
34040
|
+
}
|
|
34041
|
+
ts.forEachChild(n, visit);
|
|
34042
|
+
};
|
|
34043
|
+
visit(sf);
|
|
34044
|
+
return best;
|
|
34045
|
+
}
|
|
34046
|
+
function caseClause(sf, name) {
|
|
34047
|
+
let found;
|
|
34048
|
+
const visit = (n) => {
|
|
34049
|
+
if (found) return;
|
|
34050
|
+
if (ts.isCaseClause(n) && ts.isStringLiteralLike(n.expression) && n.expression.text === name)
|
|
34051
|
+
found = n;
|
|
34052
|
+
else ts.forEachChild(n, visit);
|
|
34053
|
+
};
|
|
34054
|
+
visit(sf);
|
|
34055
|
+
return found;
|
|
34056
|
+
}
|
|
34057
|
+
var parsedCache = /* @__PURE__ */ new WeakMap();
|
|
34058
|
+
function sourceFileOf(f) {
|
|
34059
|
+
let sf = parsedCache.get(f);
|
|
34060
|
+
if (!sf) {
|
|
34061
|
+
sf = parseFile(f).sf;
|
|
34062
|
+
parsedCache.set(f, sf);
|
|
34063
|
+
}
|
|
34064
|
+
return sf;
|
|
34065
|
+
}
|
|
34066
|
+
function readHandler(tree, tool) {
|
|
34067
|
+
const cut = tool.anchor.lastIndexOf(":");
|
|
34068
|
+
const rel = tool.anchor.slice(0, cut);
|
|
34069
|
+
const line = Number(tool.anchor.slice(cut + 1));
|
|
34070
|
+
const file = tree.files.find((f) => f.rel === rel);
|
|
34071
|
+
if (!file)
|
|
34072
|
+
return {
|
|
34073
|
+
kind: "unread",
|
|
34074
|
+
anchor: tool.anchor,
|
|
34075
|
+
reason: `${tool.name}: its registration file is not in the scanned tree`
|
|
34076
|
+
};
|
|
34077
|
+
const sf = sourceFileOf(file);
|
|
34078
|
+
const call = registrationCall(sf, line, tool.name);
|
|
34079
|
+
if (call) {
|
|
34080
|
+
const last = [...call.arguments].reverse().find((a) => {
|
|
34081
|
+
const x = unwrapExpr(a);
|
|
34082
|
+
return isFunctionLikeExpr(x) || ts.isIdentifier(x) || ts.isCallExpression(x) && x.arguments.some((w) => isFunctionLikeExpr(unwrapExpr(w)));
|
|
34083
|
+
});
|
|
34084
|
+
let u = last ? unwrapExpr(last) : void 0;
|
|
34085
|
+
if (u && ts.isCallExpression(u))
|
|
34086
|
+
u = [...u.arguments].map(unwrapExpr).reverse().find(isFunctionLikeExpr);
|
|
34087
|
+
if (u && isFunctionLikeExpr(u))
|
|
34088
|
+
return {
|
|
34089
|
+
kind: "read",
|
|
34090
|
+
anchor: `${rel}:${startLine(u)}`,
|
|
34091
|
+
returns: functionReturns(u, sf, rel),
|
|
34092
|
+
sf,
|
|
34093
|
+
file
|
|
34094
|
+
};
|
|
34095
|
+
if (u && ts.isIdentifier(u)) {
|
|
34096
|
+
const fn = sameFileFunction(sf, u.text);
|
|
34097
|
+
if (fn)
|
|
34098
|
+
return {
|
|
34099
|
+
kind: "read",
|
|
34100
|
+
anchor: `${rel}:${startLine(fn)}`,
|
|
34101
|
+
returns: functionReturns(fn, sf, rel),
|
|
34102
|
+
sf,
|
|
34103
|
+
file
|
|
34104
|
+
};
|
|
34105
|
+
return {
|
|
34106
|
+
kind: "unread",
|
|
34107
|
+
anchor: `${rel}:${startLine(u)}`,
|
|
34108
|
+
reason: `${tool.name}: its handler \`${u.text}\` is not a function declared in ${rel}`
|
|
34109
|
+
};
|
|
34110
|
+
}
|
|
34111
|
+
}
|
|
34112
|
+
for (const f of tree.files.filter((x) => isProductSource(x.rel))) {
|
|
34113
|
+
const csf = sourceFileOf(f);
|
|
34114
|
+
const clause = caseClause(csf, tool.name);
|
|
34115
|
+
if (!clause) continue;
|
|
34116
|
+
const out = [];
|
|
34117
|
+
for (const st of clause.statements) collectReturns(st, csf, f.rel, out);
|
|
34118
|
+
if (completes(clause.statements))
|
|
34119
|
+
return {
|
|
34120
|
+
kind: "unread",
|
|
34121
|
+
anchor: `${f.rel}:${startLine(clause)}`,
|
|
34122
|
+
reason: `${tool.name}: its \`case\` clause falls through to the next one`
|
|
34123
|
+
};
|
|
34124
|
+
return {
|
|
34125
|
+
kind: "read",
|
|
34126
|
+
anchor: `${f.rel}:${startLine(clause)}`,
|
|
34127
|
+
returns: out,
|
|
34128
|
+
sf: csf,
|
|
34129
|
+
file: f
|
|
34130
|
+
};
|
|
34131
|
+
}
|
|
34132
|
+
return {
|
|
34133
|
+
kind: "unread",
|
|
34134
|
+
anchor: tool.anchor,
|
|
34135
|
+
reason: `${tool.name}: no handler found (not a function argument of its registration, a same-file function, or a \`case\` clause)`
|
|
34136
|
+
};
|
|
34137
|
+
}
|
|
34138
|
+
function productRegistrations(tree) {
|
|
34139
|
+
const inProduct = (a) => isProductSource(a.slice(0, a.lastIndexOf(":")));
|
|
34140
|
+
const all = findRegisteredTools(tree, isProductSource);
|
|
34141
|
+
const computed = all.filter((t) => t.name.includes("${"));
|
|
34142
|
+
return {
|
|
34143
|
+
tools: all.filter((t) => !t.name.includes("${")),
|
|
34144
|
+
unresolved: [
|
|
34145
|
+
...findUnresolvedToolSites(tree).filter(inProduct),
|
|
34146
|
+
...computed.map((t) => t.anchor)
|
|
34147
|
+
]
|
|
34148
|
+
};
|
|
34149
|
+
}
|
|
34150
|
+
function returnedValues(expr, sf, depth = 0) {
|
|
34151
|
+
if (expr === void 0) return [{ kind: "nullish", form: "undefined" }];
|
|
34152
|
+
const e = unwrapExpr(expr);
|
|
34153
|
+
if (e.kind === ts.SyntaxKind.NullKeyword) return [{ kind: "nullish", form: "null" }];
|
|
34154
|
+
if (ts.isIdentifier(e) && e.text === "undefined") return [{ kind: "nullish", form: "undefined" }];
|
|
34155
|
+
if (ts.isVoidExpression(e)) return [{ kind: "nullish", form: "void" }];
|
|
34156
|
+
if (ts.isObjectLiteralExpression(e)) return [{ kind: "object", node: e }];
|
|
34157
|
+
if (ts.isConditionalExpression(e))
|
|
34158
|
+
return [...returnedValues(e.whenTrue, sf, depth), ...returnedValues(e.whenFalse, sf, depth)];
|
|
34159
|
+
if (depth >= 4)
|
|
34160
|
+
return [{ kind: "unread", form: `\`${e.getText(sf).slice(0, 60)}\` (followed too deep)` }];
|
|
34161
|
+
if (ts.isIdentifier(e)) {
|
|
34162
|
+
const init = constInitOf(e);
|
|
34163
|
+
if (init) return returnedValues(init, sf, depth + 1).filter((v) => v.kind !== "nullish");
|
|
34164
|
+
return [{ kind: "unread", form: `identifier \`${e.text}\` not bound to a const in reach` }];
|
|
34165
|
+
}
|
|
34166
|
+
if (ts.isCallExpression(e) && ts.isIdentifier(e.expression)) {
|
|
34167
|
+
const fn = sameFileFunction(sf, e.expression.text);
|
|
34168
|
+
if (fn) {
|
|
34169
|
+
const out = [];
|
|
34170
|
+
for (const r of functionReturns(fn, sf, sf.fileName))
|
|
34171
|
+
out.push(...returnedValues(r.expr, sf, depth + 1));
|
|
34172
|
+
return out.filter((v) => v.kind !== "nullish");
|
|
34173
|
+
}
|
|
34174
|
+
return [
|
|
34175
|
+
{ kind: "unread", form: `a call to \`${e.expression.text}\`, not a function of this file` }
|
|
34176
|
+
];
|
|
34177
|
+
}
|
|
34178
|
+
return [{ kind: "unread", form: `\`${e.getText(sf).slice(0, 60)}\`` }];
|
|
34179
|
+
}
|
|
34180
|
+
function constInitOf(id) {
|
|
34181
|
+
for (let x = id.parent; x; x = x.parent) {
|
|
34182
|
+
if (!(ts.isBlock(x) || ts.isSourceFile(x))) continue;
|
|
34183
|
+
for (const st of x.statements) {
|
|
34184
|
+
if (!ts.isVariableStatement(st) || !(st.declarationList.flags & ts.NodeFlags.Const)) continue;
|
|
34185
|
+
for (const d of st.declarationList.declarations)
|
|
34186
|
+
if (ts.isIdentifier(d.name) && d.name.text === id.text && d.initializer && d.getStart() < id.getStart())
|
|
34187
|
+
return d.initializer;
|
|
34188
|
+
}
|
|
34189
|
+
}
|
|
34190
|
+
return void 0;
|
|
34191
|
+
}
|
|
34192
|
+
function prop(obj, name) {
|
|
34193
|
+
for (const p of obj.properties) {
|
|
34194
|
+
if (ts.isPropertyAssignment(p) && (ts.isIdentifier(p.name) || ts.isStringLiteralLike(p.name)) && p.name.text === name)
|
|
34195
|
+
return { kind: "value", value: p.initializer };
|
|
34196
|
+
if (ts.isShorthandPropertyAssignment(p) && p.name.text === name)
|
|
34197
|
+
return { kind: "shorthand", ident: p.name };
|
|
34198
|
+
}
|
|
34199
|
+
if (obj.properties.some((p) => ts.isSpreadAssignment(p))) return { kind: "spread" };
|
|
34200
|
+
return { kind: "absent" };
|
|
34201
|
+
}
|
|
34202
|
+
function isErrorObject(obj) {
|
|
34203
|
+
const p = prop(obj, "isError");
|
|
34204
|
+
return p.kind === "value" && p.value.kind === ts.SyntaxKind.TrueKeyword;
|
|
34205
|
+
}
|
|
34206
|
+
function servedToolCalls(id, rule, runtime) {
|
|
34207
|
+
const anchor = `${runtime.root} (served)`;
|
|
34208
|
+
if (runtime.launchError)
|
|
34209
|
+
return {
|
|
34210
|
+
cnj: couldNotJudge(
|
|
34211
|
+
id,
|
|
34212
|
+
anchor,
|
|
34213
|
+
`the server could not be started/introspected, so no served tool result was read: ${runtime.launchError} (${rule})`
|
|
34214
|
+
)
|
|
34215
|
+
};
|
|
34216
|
+
if (!runtime.served?.toolCalls)
|
|
34217
|
+
return {
|
|
34218
|
+
cnj: couldNotJudge(
|
|
34219
|
+
id,
|
|
34220
|
+
anchor,
|
|
34221
|
+
`the introspector recorded no tools/call answers for this run (a record written before they were recorded), so no served tool result was read (${rule})`
|
|
34222
|
+
)
|
|
34223
|
+
};
|
|
34224
|
+
const paging = runtime.served.toolsPaging;
|
|
34225
|
+
if (!paging)
|
|
34226
|
+
return {
|
|
34227
|
+
cnj: couldNotJudge(
|
|
34228
|
+
id,
|
|
34229
|
+
anchor,
|
|
34230
|
+
`the introspector recorded no tools/list paging for this run (a record written before it was recorded), so it is unknown whether every served tool was read (${rule})`
|
|
34231
|
+
)
|
|
34232
|
+
};
|
|
34233
|
+
if (!paging.complete)
|
|
34234
|
+
return {
|
|
34235
|
+
cnj: couldNotJudge(
|
|
34236
|
+
id,
|
|
34237
|
+
anchor,
|
|
34238
|
+
`tools/list was read on ${paging.pages} page(s) only, cursor ${JSON.stringify(paging.unreadCursor)} left unread: ${paging.reason}; the tools on the unread pages are not judged (${rule})`
|
|
34239
|
+
)
|
|
34240
|
+
};
|
|
34241
|
+
return { calls: runtime.served.toolCalls, tools: runtime.tools, anchor };
|
|
34242
|
+
}
|
|
34243
|
+
function noSuccessReason(c) {
|
|
34244
|
+
if (!c) return "no tools/call record for it in this run";
|
|
34245
|
+
if (c.kind === "not-sent") return `no call sent: ${c.reason}`;
|
|
34246
|
+
if (c.kind === "no-answer") return `the call got no answer: ${c.reason}`;
|
|
34247
|
+
if (c.kind === "error")
|
|
34248
|
+
return `the call answered a JSON-RPC error ${String(c.code)}${c.message ? ` ${c.message}` : ""}`;
|
|
34249
|
+
if (c.isError) return "the call answered an execution error (isError: true), not a success";
|
|
34250
|
+
return void 0;
|
|
34251
|
+
}
|
|
34252
|
+
function names(list, max = 400) {
|
|
34253
|
+
return list.length <= max ? list.join(", ") : `${list.slice(0, max).join(", ")}, ... and ${list.length - max} more`;
|
|
34254
|
+
}
|
|
34255
|
+
|
|
34256
|
+
// src/detectors/s51-served-output.ts
|
|
34257
|
+
var ID17 = "S51 served-output";
|
|
34258
|
+
var RULE17 = "S-51";
|
|
34259
|
+
var isNullish = (e) => {
|
|
34260
|
+
let x = e;
|
|
34261
|
+
while (ts2.isParenthesizedExpression(x) || ts2.isAsExpression(x)) x = x.expression;
|
|
34262
|
+
return x.kind === ts2.SyntaxKind.NullKeyword || ts2.isIdentifier(x) && x.text === "undefined" || ts2.isVoidExpression(x);
|
|
34263
|
+
};
|
|
34264
|
+
var strip = (e) => {
|
|
34265
|
+
let x = e;
|
|
34266
|
+
while (ts2.isParenthesizedExpression(x) || ts2.isAsExpression(x) || ts2.isSatisfiesExpression(x))
|
|
34267
|
+
x = x.expression;
|
|
34268
|
+
return x;
|
|
34269
|
+
};
|
|
34270
|
+
var isOutputKey = (n) => (ts2.isIdentifier(n) || ts2.isStringLiteralLike(n)) && n.text === "outputSchema";
|
|
34271
|
+
var objectHasOutput = (e) => {
|
|
34272
|
+
const x = strip(e);
|
|
34273
|
+
return ts2.isObjectLiteralExpression(x) && x.properties.some(
|
|
34274
|
+
(p) => (ts2.isPropertyAssignment(p) || ts2.isShorthandPropertyAssignment(p)) && isOutputKey(p.name)
|
|
34275
|
+
);
|
|
34276
|
+
};
|
|
34277
|
+
var LOGICAL = /* @__PURE__ */ new Set([
|
|
34278
|
+
ts2.SyntaxKind.AmpersandAmpersandToken,
|
|
34279
|
+
ts2.SyntaxKind.BarBarToken,
|
|
34280
|
+
ts2.SyntaxKind.QuestionQuestionToken
|
|
34281
|
+
]);
|
|
34282
|
+
function branches(e) {
|
|
34283
|
+
const x = strip(e);
|
|
34284
|
+
if (ts2.isConditionalExpression(x)) return [x.whenTrue, x.whenFalse];
|
|
34285
|
+
if (ts2.isBinaryExpression(x) && LOGICAL.has(x.operatorToken.kind)) {
|
|
34286
|
+
if (x.operatorToken.kind === ts2.SyntaxKind.AmpersandAmpersandToken)
|
|
34287
|
+
return [ts2.factory.createIdentifier("undefined"), x.right];
|
|
34288
|
+
return [x.left, x.right];
|
|
34289
|
+
}
|
|
34290
|
+
return void 0;
|
|
34291
|
+
}
|
|
34292
|
+
var accessesOutput = (n) => ts2.isPropertyAccessExpression(n) && n.name.text === "outputSchema" || ts2.isElementAccessExpression(n) && ts2.isStringLiteralLike(n.argumentExpression) && n.argumentExpression.text === "outputSchema";
|
|
34293
|
+
function underCondition(n) {
|
|
34294
|
+
for (let x = n.parent; x && !ts2.isFunctionLike(x) && !ts2.isSourceFile(x); x = x.parent) {
|
|
34295
|
+
if (ts2.isIfStatement(x) || ts2.isConditionalExpression(x)) return true;
|
|
34296
|
+
if (ts2.isBinaryExpression(x) && LOGICAL.has(x.operatorToken.kind)) return true;
|
|
34297
|
+
}
|
|
34298
|
+
return false;
|
|
34299
|
+
}
|
|
34300
|
+
function exemptionSites(sf, rel) {
|
|
34301
|
+
const out = [];
|
|
34302
|
+
const at = (n) => `${rel}:${sf.getLineAndCharacterOfPosition(n.getStart(sf)).line + 1}`;
|
|
34303
|
+
const text = (n) => n.getText(sf).replace(/\s+/g, " ").slice(0, 120);
|
|
34304
|
+
const visit = (n) => {
|
|
34305
|
+
if (ts2.isSpreadAssignment(n)) {
|
|
34306
|
+
const b = branches(n.expression);
|
|
34307
|
+
if (b?.some(objectHasOutput) && !b.every(objectHasOutput))
|
|
34308
|
+
out.push({ anchor: at(n), form: "X1", text: text(n) });
|
|
34309
|
+
} else if (ts2.isPropertyAssignment(n) && isOutputKey(n.name)) {
|
|
34310
|
+
const b = branches(n.initializer);
|
|
34311
|
+
if (isNullish(n.initializer) || b?.some(isNullish))
|
|
34312
|
+
out.push({ anchor: at(n), form: "X2", text: text(n) });
|
|
34313
|
+
} else if (ts2.isBinaryExpression(n) && n.operatorToken.kind === ts2.SyntaxKind.EqualsToken && accessesOutput(n.left) && (underCondition(n) || isNullish(n.right) || branches(n.right)?.some(isNullish))) {
|
|
34314
|
+
out.push({ anchor: at(n), form: "X3", text: text(n) });
|
|
34315
|
+
} else if (ts2.isDeleteExpression(n) && accessesOutput(strip(n.expression))) {
|
|
34316
|
+
out.push({ anchor: at(n), form: "X3", text: text(n) });
|
|
34317
|
+
}
|
|
34318
|
+
ts2.forEachChild(n, visit);
|
|
34319
|
+
};
|
|
34320
|
+
visit(sf);
|
|
34321
|
+
return out;
|
|
34322
|
+
}
|
|
34323
|
+
function s51Controls() {
|
|
34324
|
+
const sf = (code) => ts2.createSourceFile("c.ts", code, ts2.ScriptTarget.Latest, true, ts2.ScriptKind.TS);
|
|
34325
|
+
const red = [
|
|
34326
|
+
"f({ ...(s !== undefined ? { outputSchema: s } : {}) });",
|
|
34327
|
+
"f({ outputSchema: skip.has(n) ? undefined : s });",
|
|
34328
|
+
"if (!skip.has(n)) cfg.outputSchema = s;"
|
|
34329
|
+
].map((c) => exemptionSites(sf(c), "c.ts").length);
|
|
34330
|
+
const green = exemptionSites(
|
|
34331
|
+
sf("f({ outputSchema: s, ...(c ? { title } : {}) });"),
|
|
34332
|
+
"c.ts"
|
|
34333
|
+
).length;
|
|
34334
|
+
const v = schemaCheckControls();
|
|
34335
|
+
return {
|
|
34336
|
+
sees: red.every((n) => n === 1) && v.sees && v.refuses,
|
|
34337
|
+
spares: green === 0 && v.spares
|
|
34338
|
+
};
|
|
34339
|
+
}
|
|
34340
|
+
function runStatic5(tree) {
|
|
34341
|
+
const ctl = s51Controls();
|
|
34342
|
+
if (!ctl.sees || !ctl.spares)
|
|
34343
|
+
throw new Error(
|
|
34344
|
+
`S51 positive control FAILED: ${JSON.stringify(ctl)} \u2014 reader broken, verdict untrustworthy`
|
|
34345
|
+
);
|
|
34346
|
+
const { tools, unresolved } = productRegistrations(tree);
|
|
34347
|
+
if (tools.length === 0) {
|
|
34348
|
+
const surface = toolSurfaceAnchor(tree);
|
|
34349
|
+
if (surface || unresolved.length > 0)
|
|
34350
|
+
return couldNotJudge(
|
|
34351
|
+
ID17,
|
|
34352
|
+
surface ?? unresolved[0],
|
|
34353
|
+
noToolsLocatedReason(tree, `no registration was read (${RULE17})`)
|
|
34354
|
+
);
|
|
34355
|
+
return {
|
|
34356
|
+
id: ID17,
|
|
34357
|
+
anchor: tree.root,
|
|
34358
|
+
state: "absent",
|
|
34359
|
+
verdict: `no MCP tool registered in product source \u2014 ${RULE17} n/a`
|
|
34360
|
+
};
|
|
34361
|
+
}
|
|
34362
|
+
const unread2 = unresolved.map((a) => ({
|
|
34363
|
+
anchor: a,
|
|
34364
|
+
reason: `a tool registered here has a name the scan cannot resolve, so whether it declares an output schema is unread (${RULE17})`
|
|
34365
|
+
}));
|
|
34366
|
+
const missing = [];
|
|
34367
|
+
const declared = [];
|
|
34368
|
+
for (const t of tools) {
|
|
34369
|
+
const r = closedOutputSites(tree, t.name, t.anchor);
|
|
34370
|
+
if (r.kind === "none") missing.push(`${t.name} (${t.anchor})`);
|
|
34371
|
+
else {
|
|
34372
|
+
const loc = r.sites.find(
|
|
34373
|
+
(s) => s.path === t.name && s.kind === "unread" && /^registration/.test(s.form)
|
|
34374
|
+
);
|
|
34375
|
+
if (loc) unread2.push({ anchor: loc.anchor, reason: `${loc.form} (${RULE17})` });
|
|
34376
|
+
else declared.push(t.name);
|
|
34377
|
+
}
|
|
34378
|
+
}
|
|
34379
|
+
const exemptions = [];
|
|
34380
|
+
for (const f of tree.files)
|
|
34381
|
+
if (isProductSource(f.rel)) exemptions.push(...exemptionSites(sourceFileOf(f), f.rel));
|
|
34382
|
+
if (missing.length > 0 || exemptions.length > 0) {
|
|
34383
|
+
const parts = [];
|
|
34384
|
+
if (exemptions.length > 0)
|
|
34385
|
+
parts.push(
|
|
34386
|
+
`${exemptions.length} exemption mechanism(s) that skip the output schema for some registrations: ${exemptions.map((e) => `${e.anchor} ${e.form} \`${e.text}\``).join("; ")}`
|
|
34387
|
+
);
|
|
34388
|
+
if (missing.length > 0)
|
|
34389
|
+
parts.push(
|
|
34390
|
+
`${missing.length} of ${tools.length} registered tool(s) declare no outputSchema: ${names(missing)}`
|
|
34391
|
+
);
|
|
34392
|
+
return settle(
|
|
34393
|
+
ID17,
|
|
34394
|
+
{
|
|
34395
|
+
id: ID17,
|
|
34396
|
+
anchor: exemptions[0]?.anchor ?? missing[0].replace(/^.* \((.*)\)$/, "$1"),
|
|
34397
|
+
state: "non-conforming",
|
|
34398
|
+
verdict: `${parts.join("; ")} \u2014 every served tool carries an outputSchema and no code path exempts one (${RULE17})`
|
|
34399
|
+
},
|
|
34400
|
+
unread2
|
|
34401
|
+
);
|
|
34402
|
+
}
|
|
34403
|
+
return settle(
|
|
34404
|
+
ID17,
|
|
34405
|
+
couldNotJudge(
|
|
34406
|
+
ID17,
|
|
34407
|
+
tools[0].anchor,
|
|
34408
|
+
`static half: ${declared.length} registered tool(s) declare an outputSchema and no exemption mechanism (X1..X3) is in the registration code; unread by a static run: whether each served result's structuredContent validates against it (${names(declared)}) \u2014 run --mode=dynamic (${RULE17})`
|
|
34409
|
+
),
|
|
34410
|
+
unread2
|
|
34411
|
+
);
|
|
34412
|
+
}
|
|
34413
|
+
function runServedHalf3(runtime) {
|
|
34414
|
+
const got = servedToolCalls(ID17, RULE17, runtime);
|
|
34415
|
+
if ("cnj" in got) return got.cnj;
|
|
34416
|
+
const { calls, tools, anchor } = got;
|
|
34417
|
+
if (tools.length === 0)
|
|
34418
|
+
return { id: ID17, anchor, state: "absent", verdict: `the server serves no tool \u2014 ${RULE17} n/a` };
|
|
34419
|
+
const noSchema = tools.filter((t) => t.outputSchema === void 0).map((t) => t.name);
|
|
34420
|
+
const invalid = [];
|
|
34421
|
+
const unread2 = [];
|
|
34422
|
+
let validated = 0;
|
|
34423
|
+
for (const t of tools) {
|
|
34424
|
+
if (t.outputSchema === void 0) continue;
|
|
34425
|
+
const c = calls.find((x) => x.tool === t.name);
|
|
34426
|
+
const why = noSuccessReason(c);
|
|
34427
|
+
if (why || !c || c.kind !== "result") {
|
|
34428
|
+
unread2.push({
|
|
34429
|
+
anchor: `${anchor} tools/call ${t.name}`,
|
|
34430
|
+
reason: `${t.name}: ${why} (${RULE17})`
|
|
34431
|
+
});
|
|
34432
|
+
continue;
|
|
34433
|
+
}
|
|
34434
|
+
if (!c.hasStructured || c.structuredContent === void 0) {
|
|
34435
|
+
invalid.push(
|
|
34436
|
+
`${t.name}: a successful result with no structuredContent under its outputSchema`
|
|
34437
|
+
);
|
|
34438
|
+
continue;
|
|
34439
|
+
}
|
|
34440
|
+
const v = checkSchema(t.outputSchema, c.structuredContent);
|
|
34441
|
+
if (v.kind === "invalid") invalid.push(`${t.name}: structuredContent ${v.path} \u2014 ${v.why}`);
|
|
34442
|
+
else if (v.kind === "unread")
|
|
34443
|
+
unread2.push({
|
|
34444
|
+
anchor: `${anchor} tools/list ${t.name}`,
|
|
34445
|
+
reason: `${t.name}: the outputSchema could not be read at ${v.path} \u2014 ${v.why} (${RULE17})`
|
|
34446
|
+
});
|
|
34447
|
+
else validated++;
|
|
34448
|
+
}
|
|
34449
|
+
if (noSchema.length > 0 || invalid.length > 0) {
|
|
34450
|
+
const parts = [];
|
|
34451
|
+
if (noSchema.length > 0)
|
|
34452
|
+
parts.push(
|
|
34453
|
+
`${noSchema.length} of ${tools.length} served tool(s) carry no outputSchema: ${names(noSchema)}`
|
|
34454
|
+
);
|
|
34455
|
+
if (invalid.length > 0)
|
|
34456
|
+
parts.push(`${invalid.length} served result(s) do not validate: ${invalid.join("; ")}`);
|
|
34457
|
+
return settle(
|
|
34458
|
+
ID17,
|
|
34459
|
+
{ id: ID17, anchor, state: "non-conforming", verdict: `${parts.join("; ")} (${RULE17})` },
|
|
34460
|
+
unread2
|
|
34461
|
+
);
|
|
34462
|
+
}
|
|
34463
|
+
return settle(
|
|
34464
|
+
ID17,
|
|
34465
|
+
{
|
|
34466
|
+
id: ID17,
|
|
34467
|
+
anchor,
|
|
34468
|
+
state: "present",
|
|
34469
|
+
verdict: `${tools.length} served tool(s) declare an outputSchema; ${validated} successful result(s) read, each structuredContent valid against it (${RULE17})`
|
|
34470
|
+
},
|
|
34471
|
+
unread2
|
|
34472
|
+
);
|
|
34473
|
+
}
|
|
34474
|
+
var s51ServedOutput = {
|
|
34475
|
+
id: ID17,
|
|
34476
|
+
rule: RULE17,
|
|
34477
|
+
pin: S51_RULES_PIN,
|
|
34478
|
+
run: runStatic5,
|
|
34479
|
+
runServed: (runtime) => runServedHalf3(runtime)
|
|
34480
|
+
};
|
|
34481
|
+
|
|
34482
|
+
// src/detectors/s52-no-null-success.ts
|
|
34483
|
+
import * as ts3 from "typescript";
|
|
34484
|
+
var ID18 = "S52 no-null-success";
|
|
34485
|
+
var RULE18 = "S-52";
|
|
34486
|
+
function nullReturns(tool, read) {
|
|
34487
|
+
const red = [];
|
|
34488
|
+
const unread2 = [];
|
|
34489
|
+
for (const r of read.returns) {
|
|
34490
|
+
if (r.inCatch) continue;
|
|
34491
|
+
if (r.form === "bare-return" || r.form === "fall-through") {
|
|
34492
|
+
red.push({
|
|
34493
|
+
tool,
|
|
34494
|
+
anchor: r.anchor,
|
|
34495
|
+
form: r.form === "bare-return" ? "N1 bare `return;`" : "N1 the handler falls off its end (answers undefined)"
|
|
34496
|
+
});
|
|
34497
|
+
continue;
|
|
34498
|
+
}
|
|
34499
|
+
for (const v of returnedValues(r.expr, read.sf)) {
|
|
34500
|
+
if (v.kind === "nullish") red.push({ tool, anchor: r.anchor, form: `N1 returns ${v.form}` });
|
|
34501
|
+
else if (v.kind === "unread")
|
|
34502
|
+
unread2.push({
|
|
34503
|
+
anchor: r.anchor,
|
|
34504
|
+
reason: `${tool}: the returned value is ${v.form} (${RULE18})`
|
|
34505
|
+
});
|
|
34506
|
+
else {
|
|
34507
|
+
if (isErrorObject(v.node)) continue;
|
|
34508
|
+
const sc = prop(v.node, "structuredContent");
|
|
34509
|
+
if (sc.kind === "value") {
|
|
34510
|
+
const x = sc.value;
|
|
34511
|
+
if (x.kind === ts3.SyntaxKind.NullKeyword || ts3.isIdentifier(x) && x.text === "undefined")
|
|
34512
|
+
red.push({ tool, anchor: r.anchor, form: "N2 `structuredContent: null`" });
|
|
34513
|
+
else if (ts3.isObjectLiteralExpression(x) && x.properties.length === 0)
|
|
34514
|
+
red.push({ tool, anchor: r.anchor, form: "N4 `structuredContent: {}`" });
|
|
34515
|
+
}
|
|
34516
|
+
const content = prop(v.node, "content");
|
|
34517
|
+
if (content.kind === "value" && ts3.isArrayLiteralExpression(content.value) && content.value.elements.length === 0)
|
|
34518
|
+
red.push({ tool, anchor: r.anchor, form: "N5 `content: []`" });
|
|
34519
|
+
else if (content.kind === "absent")
|
|
34520
|
+
red.push({ tool, anchor: r.anchor, form: "N5 a result with no `content`" });
|
|
34521
|
+
}
|
|
34522
|
+
}
|
|
34523
|
+
}
|
|
34524
|
+
return { red, unread: unread2 };
|
|
34525
|
+
}
|
|
34526
|
+
function servedNullForm(c, hasSchema) {
|
|
34527
|
+
if (c.hasStructured && c.structuredContent === null) return "N2 structuredContent is null";
|
|
34528
|
+
if (hasSchema && (!c.hasStructured || c.structuredContent === void 0))
|
|
34529
|
+
return "N3 structuredContent absent under a declared outputSchema";
|
|
34530
|
+
const sc = c.structuredContent;
|
|
34531
|
+
if (typeof sc === "object" && sc !== null && !Array.isArray(sc) && Object.keys(sc).length === 0)
|
|
34532
|
+
return "N4 structuredContent is {}";
|
|
34533
|
+
if (c.contentKind !== "array")
|
|
34534
|
+
return `N5 content is ${c.contentKind === "absent" ? "absent" : "not an array"}`;
|
|
34535
|
+
if (c.content.length === 0) return "N5 content is []";
|
|
34536
|
+
const texts2 = c.content.filter((b) => b.type === "text");
|
|
34537
|
+
if (texts2.length === c.content.length && texts2.every((b) => ["", "null", "undefined", "{}"].includes((b.text ?? "").trim())))
|
|
34538
|
+
return `N6 the text answers ${JSON.stringify((texts2[0].text ?? "").trim())}`;
|
|
34539
|
+
return void 0;
|
|
34540
|
+
}
|
|
34541
|
+
function runStatic6(tree) {
|
|
34542
|
+
const { tools, unresolved } = productRegistrations(tree);
|
|
34543
|
+
if (tools.length === 0) {
|
|
34544
|
+
const surface = toolSurfaceAnchor(tree);
|
|
34545
|
+
if (surface || unresolved.length > 0)
|
|
34546
|
+
return couldNotJudge(
|
|
34547
|
+
ID18,
|
|
34548
|
+
surface ?? unresolved[0],
|
|
34549
|
+
noToolsLocatedReason(tree, `no handler was read (${RULE18})`)
|
|
34550
|
+
);
|
|
34551
|
+
return {
|
|
34552
|
+
id: ID18,
|
|
34553
|
+
anchor: tree.root,
|
|
34554
|
+
state: "absent",
|
|
34555
|
+
verdict: `no MCP tool registered in product source \u2014 ${RULE18} n/a`
|
|
34556
|
+
};
|
|
34557
|
+
}
|
|
34558
|
+
const red = [];
|
|
34559
|
+
const unread2 = unresolved.map((a) => ({
|
|
34560
|
+
anchor: a,
|
|
34561
|
+
reason: `a tool registered here has a name the scan cannot resolve, so its handler is unread (${RULE18})`
|
|
34562
|
+
}));
|
|
34563
|
+
const read = [];
|
|
34564
|
+
for (const t of tools) {
|
|
34565
|
+
const h = readHandler(tree, t);
|
|
34566
|
+
if (h.kind === "unread") {
|
|
34567
|
+
unread2.push({ anchor: h.anchor, reason: `${h.reason} (${RULE18})` });
|
|
34568
|
+
continue;
|
|
34569
|
+
}
|
|
34570
|
+
read.push(t.name);
|
|
34571
|
+
const r = nullReturns(t.name, h);
|
|
34572
|
+
red.push(...r.red);
|
|
34573
|
+
unread2.push(...r.unread);
|
|
34574
|
+
}
|
|
34575
|
+
if (red.length > 0)
|
|
34576
|
+
return settle(
|
|
34577
|
+
ID18,
|
|
34578
|
+
{
|
|
34579
|
+
id: ID18,
|
|
34580
|
+
anchor: red[0].anchor,
|
|
34581
|
+
state: "non-conforming",
|
|
34582
|
+
verdict: `${red.length} success-path return(s) answer null or empty: ${red.map((f) => `${f.tool} ${f.form} (${f.anchor})`).join("; ")} \u2014 a tool that found nothing returns a typed empty value (${RULE18})`
|
|
34583
|
+
},
|
|
34584
|
+
unread2
|
|
34585
|
+
);
|
|
34586
|
+
return settle(
|
|
34587
|
+
ID18,
|
|
34588
|
+
couldNotJudge(
|
|
34589
|
+
ID18,
|
|
34590
|
+
tools[0].anchor,
|
|
34591
|
+
`static half: no success-path return writes null or empty in the ${read.length} handler(s) read (${names(read)}); unread by a static run: what each returned expression evaluates to \u2014 run --mode=dynamic (${RULE18})`
|
|
34592
|
+
),
|
|
34593
|
+
unread2
|
|
34594
|
+
);
|
|
34595
|
+
}
|
|
34596
|
+
function runServedHalf4(runtime) {
|
|
34597
|
+
const got = servedToolCalls(ID18, RULE18, runtime);
|
|
34598
|
+
if ("cnj" in got) return got.cnj;
|
|
34599
|
+
const { calls, anchor } = got;
|
|
34600
|
+
if (runtime.tools.length === 0)
|
|
34601
|
+
return { id: ID18, anchor, state: "absent", verdict: `the server serves no tool \u2014 ${RULE18} n/a` };
|
|
34602
|
+
const red = [];
|
|
34603
|
+
const unread2 = [];
|
|
34604
|
+
let ok = 0;
|
|
34605
|
+
for (const t of runtime.tools) {
|
|
34606
|
+
const c = calls.find((x) => x.tool === t.name);
|
|
34607
|
+
const why = noSuccessReason(c);
|
|
34608
|
+
if (why || !c || c.kind !== "result") {
|
|
34609
|
+
unread2.push({
|
|
34610
|
+
anchor: `${anchor} tools/call ${t.name}`,
|
|
34611
|
+
reason: `${t.name}: ${why} (${RULE18})`
|
|
34612
|
+
});
|
|
34613
|
+
continue;
|
|
34614
|
+
}
|
|
34615
|
+
const form = servedNullForm(c, t.outputSchema !== void 0);
|
|
34616
|
+
if (form) red.push(`${t.name}: ${form}`);
|
|
34617
|
+
else ok++;
|
|
34618
|
+
}
|
|
34619
|
+
if (red.length > 0)
|
|
34620
|
+
return settle(
|
|
34621
|
+
ID18,
|
|
34622
|
+
{
|
|
34623
|
+
id: ID18,
|
|
34624
|
+
anchor,
|
|
34625
|
+
state: "non-conforming",
|
|
34626
|
+
verdict: `${red.length} successful result(s) answer null or empty: ${red.join("; ")} (${RULE18})`
|
|
34627
|
+
},
|
|
34628
|
+
unread2
|
|
34629
|
+
);
|
|
34630
|
+
return settle(
|
|
34631
|
+
ID18,
|
|
34632
|
+
{
|
|
34633
|
+
id: ID18,
|
|
34634
|
+
anchor,
|
|
34635
|
+
state: "present",
|
|
34636
|
+
verdict: `${ok} successful result(s) read, each carrying a typed value (${RULE18})`
|
|
34637
|
+
},
|
|
34638
|
+
unread2
|
|
34639
|
+
);
|
|
34640
|
+
}
|
|
34641
|
+
var s52NoNullSuccess = {
|
|
34642
|
+
id: ID18,
|
|
34643
|
+
rule: RULE18,
|
|
34644
|
+
pin: S51_RULES_PIN,
|
|
34645
|
+
run: runStatic6,
|
|
34646
|
+
runServed: (runtime) => runServedHalf4(runtime)
|
|
34647
|
+
};
|
|
34648
|
+
|
|
34649
|
+
// src/detectors/s53-structured-not-text.ts
|
|
34650
|
+
import * as ts4 from "typescript";
|
|
34651
|
+
var ID19 = "S53 structured-not-text";
|
|
34652
|
+
var RULE19 = "S-53";
|
|
34653
|
+
function classifyTextExpr(e, sf, depth = 0) {
|
|
34654
|
+
let x = e;
|
|
34655
|
+
while (ts4.isParenthesizedExpression(x) || ts4.isAsExpression(x)) x = x.expression;
|
|
34656
|
+
if (ts4.isStringLiteral(x) || ts4.isNoSubstitutionTemplateLiteral(x)) return { kind: "none" };
|
|
34657
|
+
const t = x.getText(sf);
|
|
34658
|
+
if (ts4.isCallExpression(x) && /^JSON\s*\.\s*stringify$/.test(x.expression.getText(sf)))
|
|
34659
|
+
return { kind: "data", form: "T1 JSON.stringify(...) in the text" };
|
|
34660
|
+
if (ts4.isTemplateExpression(x) || ts4.isBinaryExpression(x) && x.operatorToken.kind === ts4.SyntaxKind.PlusToken) {
|
|
34661
|
+
if (/\bJSON\s*\.\s*stringify\s*\(/.test(t))
|
|
34662
|
+
return { kind: "data", form: "T2 a serialized value inside the text" };
|
|
34663
|
+
if (/\.\s*(join|map)\s*\(/.test(t))
|
|
34664
|
+
return { kind: "data", form: "T2 a list joined into the text" };
|
|
34665
|
+
if (/\.\s*length\b/.test(t))
|
|
34666
|
+
return { kind: "data", form: "T2 a count interpolated into the text" };
|
|
34667
|
+
const spans = ts4.isTemplateExpression(x) ? x.templateSpans.map((sp) => sp.expression) : [x.left, x.right];
|
|
34668
|
+
const idSpan = spans.find(
|
|
34669
|
+
(sp) => /(?:^|\.)id$|[a-z0-9](?:Id|Ids|ID)$/.test(sp.getText(sf).trim())
|
|
34670
|
+
);
|
|
34671
|
+
if (idSpan)
|
|
34672
|
+
return {
|
|
34673
|
+
kind: "data",
|
|
34674
|
+
form: `T2 an identifier interpolated into the text (${idSpan.getText(sf).trim()})`
|
|
34675
|
+
};
|
|
34676
|
+
if (ts4.isBinaryExpression(x)) {
|
|
34677
|
+
const parts = [classifyTextExpr(x.left, sf, depth), classifyTextExpr(x.right, sf, depth)];
|
|
34678
|
+
return parts.find((p) => p.kind === "data") ?? parts.find((p) => p.kind === "unread") ?? { kind: "none" };
|
|
34679
|
+
}
|
|
34680
|
+
return {
|
|
34681
|
+
kind: "unread",
|
|
34682
|
+
form: `a template with interpolated values \`${t.replace(/\s+/g, " ").slice(0, 60)}\``
|
|
34683
|
+
};
|
|
34684
|
+
}
|
|
34685
|
+
if (ts4.isCallExpression(x) && /\.\s*join$/.test(x.expression.getText(sf)))
|
|
34686
|
+
return { kind: "data", form: "T2 a list joined into the text" };
|
|
34687
|
+
if (ts4.isConditionalExpression(x)) {
|
|
34688
|
+
const parts = [
|
|
34689
|
+
classifyTextExpr(x.whenTrue, sf, depth),
|
|
34690
|
+
classifyTextExpr(x.whenFalse, sf, depth)
|
|
34691
|
+
];
|
|
34692
|
+
return parts.find((p) => p.kind === "data") ?? parts.find((p) => p.kind === "unread") ?? { kind: "none" };
|
|
34693
|
+
}
|
|
34694
|
+
if (ts4.isIdentifier(x) && depth < 2) {
|
|
34695
|
+
const init = constInit(x);
|
|
34696
|
+
if (init) return classifyTextExpr(init, sf, depth + 1);
|
|
34697
|
+
}
|
|
34698
|
+
return { kind: "unread", form: `text \`${t.replace(/\s+/g, " ").slice(0, 60)}\`` };
|
|
34699
|
+
}
|
|
34700
|
+
function constInit(id) {
|
|
34701
|
+
for (let p = id.parent; p; p = p.parent) {
|
|
34702
|
+
if (!(ts4.isBlock(p) || ts4.isSourceFile(p))) continue;
|
|
34703
|
+
for (const st of p.statements) {
|
|
34704
|
+
if (!ts4.isVariableStatement(st) || !(st.declarationList.flags & ts4.NodeFlags.Const)) continue;
|
|
34705
|
+
for (const d of st.declarationList.declarations)
|
|
34706
|
+
if (ts4.isIdentifier(d.name) && d.name.text === id.text && d.initializer && d.getStart() < id.getStart())
|
|
34707
|
+
return d.initializer;
|
|
34708
|
+
}
|
|
34709
|
+
}
|
|
34710
|
+
return void 0;
|
|
34711
|
+
}
|
|
34712
|
+
function textOnlyReturn(obj, sf) {
|
|
34713
|
+
const content = prop(obj, "content");
|
|
34714
|
+
if (content.kind === "absent") return { kind: "none" };
|
|
34715
|
+
if (content.kind !== "value" || !ts4.isArrayLiteralExpression(content.value))
|
|
34716
|
+
return { kind: "unread", form: "a `content` that is not an array literal" };
|
|
34717
|
+
const out = [];
|
|
34718
|
+
for (const el of content.value.elements) {
|
|
34719
|
+
if (!ts4.isObjectLiteralExpression(el)) {
|
|
34720
|
+
out.push({ kind: "unread", form: "a content block that is not an object literal" });
|
|
34721
|
+
continue;
|
|
34722
|
+
}
|
|
34723
|
+
const text = prop(el, "text");
|
|
34724
|
+
if (text.kind === "value") out.push(classifyTextExpr(text.value, sf));
|
|
34725
|
+
else if (text.kind === "shorthand") out.push(classifyTextExpr(text.ident, sf));
|
|
34726
|
+
else if (text.kind === "spread")
|
|
34727
|
+
out.push({ kind: "unread", form: "a content block built with a spread" });
|
|
34728
|
+
}
|
|
34729
|
+
return out.find((p) => p.kind === "data") ?? out.find((p) => p.kind === "unread") ?? { kind: "none" };
|
|
34730
|
+
}
|
|
34731
|
+
function runStatic7(tree) {
|
|
34732
|
+
const { tools, unresolved } = productRegistrations(tree);
|
|
34733
|
+
if (tools.length === 0) {
|
|
34734
|
+
const surface = toolSurfaceAnchor(tree);
|
|
34735
|
+
if (surface || unresolved.length > 0)
|
|
34736
|
+
return couldNotJudge(
|
|
34737
|
+
ID19,
|
|
34738
|
+
surface ?? unresolved[0],
|
|
34739
|
+
noToolsLocatedReason(tree, `no handler was read (${RULE19})`)
|
|
34740
|
+
);
|
|
34741
|
+
return {
|
|
34742
|
+
id: ID19,
|
|
34743
|
+
anchor: tree.root,
|
|
34744
|
+
state: "absent",
|
|
34745
|
+
verdict: `no MCP tool registered in product source \u2014 ${RULE19} n/a`
|
|
34746
|
+
};
|
|
34747
|
+
}
|
|
34748
|
+
const red = [];
|
|
34749
|
+
const unread2 = unresolved.map((a) => ({
|
|
34750
|
+
anchor: a,
|
|
34751
|
+
reason: `a tool registered here has a name the scan cannot resolve, so its handler is unread (${RULE19})`
|
|
34752
|
+
}));
|
|
34753
|
+
const read = [];
|
|
34754
|
+
let firstRed = "";
|
|
34755
|
+
for (const t of tools) {
|
|
34756
|
+
const h = readHandler(tree, t);
|
|
34757
|
+
if (h.kind === "unread") {
|
|
34758
|
+
unread2.push({ anchor: h.anchor, reason: `${h.reason} (${RULE19})` });
|
|
34759
|
+
continue;
|
|
34760
|
+
}
|
|
34761
|
+
read.push(t.name);
|
|
34762
|
+
for (const r of h.returns) {
|
|
34763
|
+
if (r.inCatch || !r.expr) continue;
|
|
34764
|
+
for (const v of returnedValues(r.expr, h.sf)) {
|
|
34765
|
+
if (v.kind !== "object") {
|
|
34766
|
+
if (v.kind === "unread")
|
|
34767
|
+
unread2.push({
|
|
34768
|
+
anchor: r.anchor,
|
|
34769
|
+
reason: `${t.name}: the returned value is ${v.form} (${RULE19})`
|
|
34770
|
+
});
|
|
34771
|
+
continue;
|
|
34772
|
+
}
|
|
34773
|
+
if (isErrorObject(v.node)) continue;
|
|
34774
|
+
const sc = prop(v.node, "structuredContent");
|
|
34775
|
+
if (sc.kind === "spread") {
|
|
34776
|
+
unread2.push({
|
|
34777
|
+
anchor: r.anchor,
|
|
34778
|
+
reason: `${t.name}: a result object built with a spread, structuredContent unread (${RULE19})`
|
|
34779
|
+
});
|
|
34780
|
+
continue;
|
|
34781
|
+
}
|
|
34782
|
+
if (sc.kind !== "absent") continue;
|
|
34783
|
+
const c = textOnlyReturn(v.node, h.sf);
|
|
34784
|
+
if (c.kind === "data") {
|
|
34785
|
+
red.push(`${t.name} ${c.form}, no structuredContent (${r.anchor})`);
|
|
34786
|
+
firstRed ||= r.anchor;
|
|
34787
|
+
} else if (c.kind === "unread")
|
|
34788
|
+
unread2.push({ anchor: r.anchor, reason: `${t.name}: ${c.form} (${RULE19})` });
|
|
34789
|
+
}
|
|
34790
|
+
}
|
|
34791
|
+
}
|
|
34792
|
+
if (red.length > 0)
|
|
34793
|
+
return settle(
|
|
34794
|
+
ID19,
|
|
34795
|
+
{
|
|
34796
|
+
id: ID19,
|
|
34797
|
+
anchor: firstRed,
|
|
34798
|
+
state: "non-conforming",
|
|
34799
|
+
verdict: `${red.length} success-path return(s) carry data in the text only: ${red.join("; ")} \u2014 return it as structuredContent under the outputSchema, the text being its serialization (${RULE19})`
|
|
34800
|
+
},
|
|
34801
|
+
unread2
|
|
34802
|
+
);
|
|
34803
|
+
return settle(
|
|
34804
|
+
ID19,
|
|
34805
|
+
couldNotJudge(
|
|
34806
|
+
ID19,
|
|
34807
|
+
tools[0].anchor,
|
|
34808
|
+
`static half: no text-only return carrying data in the ${read.length} handler(s) read (${names(read)}); unread by a static run: whether each served text is the serialization of its structuredContent \u2014 run --mode=dynamic (${RULE19})`
|
|
34809
|
+
),
|
|
34810
|
+
unread2
|
|
34811
|
+
);
|
|
34812
|
+
}
|
|
34813
|
+
var UUID = /\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/i;
|
|
34814
|
+
var TOKEN = /\b(?=[A-Za-z0-9_]*[A-Za-z])(?=[A-Za-z0-9_]*\d)[A-Za-z0-9_]{16,}\b/;
|
|
34815
|
+
var COUNT = /(?<![\w.])\d+\s+[A-Za-z]{2,}/;
|
|
34816
|
+
var LIST_LINE = /^\s*(?:[-*•]\s+\S|\d+[.)]\s+\S|[A-Za-z_][\w ]{0,40}:\s+\S)/;
|
|
34817
|
+
var INLINE_ITEM = /^[\p{L}\p{N}_.@'+-]+$/u;
|
|
34818
|
+
var isInlineList = (text) => {
|
|
34819
|
+
const t = text.trim();
|
|
34820
|
+
if (t.includes("\n")) return false;
|
|
34821
|
+
const items = t.split(/\s*[,;]\s*/);
|
|
34822
|
+
return items.length >= 3 && items.every((i) => INLINE_ITEM.test(i));
|
|
34823
|
+
};
|
|
34824
|
+
function leadingJson(text) {
|
|
34825
|
+
const t = text.trim();
|
|
34826
|
+
if (!/^[[{]/.test(t)) {
|
|
34827
|
+
try {
|
|
34828
|
+
const v = JSON.parse(t);
|
|
34829
|
+
return typeof v === "object" && v !== null ? { value: v } : void 0;
|
|
34830
|
+
} catch {
|
|
34831
|
+
return void 0;
|
|
34832
|
+
}
|
|
34833
|
+
}
|
|
34834
|
+
const close2 = t[0] === "{" ? "}" : "]";
|
|
34835
|
+
let end = t.length;
|
|
34836
|
+
while (end > 0) {
|
|
34837
|
+
try {
|
|
34838
|
+
return { value: JSON.parse(t.slice(0, end)) };
|
|
34839
|
+
} catch {
|
|
34840
|
+
}
|
|
34841
|
+
const k = t.lastIndexOf(close2, end - 2);
|
|
34842
|
+
if (k < 0) break;
|
|
34843
|
+
end = k + 1;
|
|
34844
|
+
}
|
|
34845
|
+
return void 0;
|
|
34846
|
+
}
|
|
34847
|
+
function classifyServedText(text) {
|
|
34848
|
+
const j = leadingJson(text);
|
|
34849
|
+
if (j) return { kind: "data", form: "J the text is JSON", json: j.value };
|
|
34850
|
+
const lines2 = text.split("\n").filter((l) => l.trim() !== "");
|
|
34851
|
+
if (lines2.filter((l) => LIST_LINE.test(l)).length >= 2)
|
|
34852
|
+
return { kind: "data", form: "L the text is a list" };
|
|
34853
|
+
if (isInlineList(text)) return { kind: "data", form: "L the text is an inline list" };
|
|
34854
|
+
const id = text.match(UUID) ?? text.match(TOKEN);
|
|
34855
|
+
if (id) return { kind: "data", form: `I the text names identifier ${id[0]}` };
|
|
34856
|
+
const count = text.match(COUNT);
|
|
34857
|
+
if (count) return { kind: "data", form: `C the text states a count (${count[0]})` };
|
|
34858
|
+
if (!/\d/.test(text)) return { kind: "prose" };
|
|
34859
|
+
return { kind: "unclassifiable" };
|
|
34860
|
+
}
|
|
34861
|
+
var hasData = (sc) => sc !== void 0 && sc !== null && !(typeof sc === "object" && !Array.isArray(sc) && Object.keys(sc).length === 0);
|
|
34862
|
+
function servedTextForm(c) {
|
|
34863
|
+
const texts2 = c.content.filter((b) => b.type === "text" && typeof b.text === "string");
|
|
34864
|
+
const structured = hasData(c.structuredContent);
|
|
34865
|
+
for (const b of texts2) {
|
|
34866
|
+
const text = b.text;
|
|
34867
|
+
const k = classifyServedText(text);
|
|
34868
|
+
if (!structured) {
|
|
34869
|
+
if (k.kind === "data")
|
|
34870
|
+
return { kind: "red", form: `${k.form} and structuredContent carries no data` };
|
|
34871
|
+
if (k.kind === "unclassifiable")
|
|
34872
|
+
return {
|
|
34873
|
+
kind: "unread",
|
|
34874
|
+
form: `a text that is neither JSON, a list, an identifier nor prose: ${JSON.stringify(text.slice(0, 80))}`
|
|
34875
|
+
};
|
|
34876
|
+
continue;
|
|
34877
|
+
}
|
|
34878
|
+
if (k.kind === "data" && "json" in k && k.json !== void 0) {
|
|
34879
|
+
if (b.truncated)
|
|
34880
|
+
return {
|
|
34881
|
+
kind: "unread",
|
|
34882
|
+
form: "the text was cut at the recording cap, so its serialization cannot be compared whole"
|
|
34883
|
+
};
|
|
34884
|
+
if (!jsonEqual(k.json, c.structuredContent) && !JSON.stringify(c.structuredContent).includes(JSON.stringify(k.json)))
|
|
34885
|
+
return {
|
|
34886
|
+
kind: "red",
|
|
34887
|
+
form: "the text carries JSON that is not the serialization of structuredContent"
|
|
34888
|
+
};
|
|
34889
|
+
continue;
|
|
34890
|
+
}
|
|
34891
|
+
const flat = JSON.stringify(c.structuredContent);
|
|
34892
|
+
const tokens = [
|
|
34893
|
+
...text.match(new RegExp(UUID.source, "gi")) ?? [],
|
|
34894
|
+
...text.match(new RegExp(TOKEN.source, "g")) ?? []
|
|
34895
|
+
];
|
|
34896
|
+
const lacked = tokens.find((tk) => !flat.includes(tk));
|
|
34897
|
+
if (lacked)
|
|
34898
|
+
return { kind: "red", form: `the text names ${lacked}, which structuredContent lacks` };
|
|
34899
|
+
}
|
|
34900
|
+
return { kind: "green" };
|
|
34901
|
+
}
|
|
34902
|
+
function runServedHalf5(runtime) {
|
|
34903
|
+
const got = servedToolCalls(ID19, RULE19, runtime);
|
|
34904
|
+
if ("cnj" in got) return got.cnj;
|
|
34905
|
+
const { calls, anchor } = got;
|
|
34906
|
+
if (runtime.tools.length === 0)
|
|
34907
|
+
return { id: ID19, anchor, state: "absent", verdict: `the server serves no tool \u2014 ${RULE19} n/a` };
|
|
34908
|
+
const red = [];
|
|
34909
|
+
const unread2 = [];
|
|
34910
|
+
let ok = 0;
|
|
34911
|
+
for (const t of runtime.tools) {
|
|
34912
|
+
const c = calls.find((x) => x.tool === t.name);
|
|
34913
|
+
const why = noSuccessReason(c);
|
|
34914
|
+
if (why || !c || c.kind !== "result") {
|
|
34915
|
+
unread2.push({
|
|
34916
|
+
anchor: `${anchor} tools/call ${t.name}`,
|
|
34917
|
+
reason: `${t.name}: ${why} (${RULE19})`
|
|
34918
|
+
});
|
|
34919
|
+
continue;
|
|
34920
|
+
}
|
|
34921
|
+
const v = servedTextForm(c);
|
|
34922
|
+
if (v.kind === "red") red.push(`${t.name}: ${v.form}`);
|
|
34923
|
+
else if (v.kind === "unread")
|
|
34924
|
+
unread2.push({
|
|
34925
|
+
anchor: `${anchor} tools/call ${t.name}`,
|
|
34926
|
+
reason: `${t.name}: ${v.form} (${RULE19})`
|
|
34927
|
+
});
|
|
34928
|
+
else ok++;
|
|
34929
|
+
}
|
|
34930
|
+
if (red.length > 0)
|
|
34931
|
+
return settle(
|
|
34932
|
+
ID19,
|
|
34933
|
+
{
|
|
34934
|
+
id: ID19,
|
|
34935
|
+
anchor,
|
|
34936
|
+
state: "non-conforming",
|
|
34937
|
+
verdict: `${red.length} successful result(s) carry data in free text: ${red.join("; ")} (${RULE19})`
|
|
34938
|
+
},
|
|
34939
|
+
unread2
|
|
34940
|
+
);
|
|
34941
|
+
return settle(
|
|
34942
|
+
ID19,
|
|
34943
|
+
{
|
|
34944
|
+
id: ID19,
|
|
34945
|
+
anchor,
|
|
34946
|
+
state: "present",
|
|
34947
|
+
verdict: `${ok} successful result(s) read: data in structuredContent, text its serialization or summary (${RULE19})`
|
|
34948
|
+
},
|
|
34949
|
+
unread2
|
|
34950
|
+
);
|
|
34951
|
+
}
|
|
34952
|
+
var s53StructuredNotText = {
|
|
34953
|
+
id: ID19,
|
|
34954
|
+
rule: RULE19,
|
|
34955
|
+
pin: S51_RULES_PIN,
|
|
34956
|
+
run: runStatic7,
|
|
34957
|
+
runServed: (runtime) => runServedHalf5(runtime)
|
|
34958
|
+
};
|
|
34959
|
+
|
|
34960
|
+
// src/detectors/s54-tools-tested.ts
|
|
34961
|
+
import { readFileSync as readFileSync24, readdirSync as readdirSync17, statSync as statSync24 } from "fs";
|
|
34962
|
+
import { join as join35, relative as relative15, sep as sep7 } from "path";
|
|
34963
|
+
import * as ts5 from "typescript";
|
|
34964
|
+
var ID20 = "S54 tools-tested";
|
|
34965
|
+
var RULE20 = "S-54";
|
|
34966
|
+
var TEST_DIR = /(^|\/)(test|tests|__tests__|spec|specs|e2e)\//;
|
|
34967
|
+
var TEST_NAME = /\.(test|spec)\.[cm]?[jt]sx?$/;
|
|
34968
|
+
var CODE2 = /\.[cm]?[jt]sx?$/;
|
|
34969
|
+
var NOT_TESTS = /* @__PURE__ */ new Set([
|
|
34970
|
+
...Object.keys(SKIP_DIR_INFO).filter((d) => !SKIP_DIR_INFO[d].authored),
|
|
34971
|
+
"fixtures"
|
|
34972
|
+
]);
|
|
34973
|
+
function isTestFile(rel) {
|
|
34974
|
+
return CODE2.test(rel) && !/\.d\.[cm]?ts$/.test(rel) && (TEST_NAME.test(rel) || TEST_DIR.test(rel));
|
|
34975
|
+
}
|
|
34976
|
+
function testFiles2(root) {
|
|
34977
|
+
const files = [];
|
|
34978
|
+
const unread2 = [];
|
|
34979
|
+
const walk3 = (dir) => {
|
|
34980
|
+
let entries;
|
|
34981
|
+
try {
|
|
34982
|
+
entries = readdirSync17(dir);
|
|
34983
|
+
} catch (e) {
|
|
34984
|
+
unread2.push({
|
|
34985
|
+
anchor: relative15(root, dir) || ".",
|
|
34986
|
+
reason: `directory not listed (${e.message}) (${RULE20})`
|
|
34987
|
+
});
|
|
34988
|
+
return;
|
|
34989
|
+
}
|
|
34990
|
+
for (const name of entries) {
|
|
34991
|
+
const full = join35(dir, name);
|
|
34992
|
+
let st;
|
|
34993
|
+
try {
|
|
34994
|
+
st = statSync24(full);
|
|
34995
|
+
} catch (e) {
|
|
34996
|
+
unread2.push({
|
|
34997
|
+
anchor: relative15(root, full),
|
|
34998
|
+
reason: `not read (${e.message}) (${RULE20})`
|
|
34999
|
+
});
|
|
35000
|
+
continue;
|
|
35001
|
+
}
|
|
35002
|
+
if (st.isDirectory()) {
|
|
35003
|
+
if (!NOT_TESTS.has(name)) walk3(full);
|
|
35004
|
+
continue;
|
|
35005
|
+
}
|
|
35006
|
+
const rel = relative15(root, full).split(sep7).join("/");
|
|
35007
|
+
if (!st.isFile() || !isTestFile(rel)) continue;
|
|
35008
|
+
try {
|
|
35009
|
+
const text = readFileSync24(full, "utf8");
|
|
35010
|
+
const kind = /x$/.test(rel) ? ts5.ScriptKind.TSX : /\.[cm]?js$/.test(rel) ? ts5.ScriptKind.JS : ts5.ScriptKind.TS;
|
|
35011
|
+
files.push({ rel, sf: ts5.createSourceFile(rel, text, ts5.ScriptTarget.Latest, true, kind) });
|
|
35012
|
+
} catch (e) {
|
|
35013
|
+
unread2.push({
|
|
35014
|
+
anchor: rel,
|
|
35015
|
+
reason: `test file not read (${e.message}) (${RULE20})`
|
|
35016
|
+
});
|
|
35017
|
+
}
|
|
35018
|
+
}
|
|
35019
|
+
};
|
|
35020
|
+
walk3(root);
|
|
35021
|
+
return { files, unread: unread2 };
|
|
35022
|
+
}
|
|
35023
|
+
var up = (n) => {
|
|
35024
|
+
let x = n;
|
|
35025
|
+
while (x.parent && (ts5.isParenthesizedExpression(x.parent) || ts5.isAsExpression(x.parent) || ts5.isNonNullExpression(x.parent) || ts5.isAwaitExpression(x.parent) || ts5.isSatisfiesExpression(x.parent)))
|
|
35026
|
+
x = x.parent;
|
|
35027
|
+
return x;
|
|
35028
|
+
};
|
|
35029
|
+
var calleeName = (c) => {
|
|
35030
|
+
const e = c.expression;
|
|
35031
|
+
if (ts5.isIdentifier(e)) return e.text;
|
|
35032
|
+
if (ts5.isPropertyAccessExpression(e)) return e.name.text;
|
|
35033
|
+
return void 0;
|
|
35034
|
+
};
|
|
35035
|
+
var propName = (p) => p.name && (ts5.isIdentifier(p.name) || ts5.isStringLiteralLike(p.name)) ? p.name.text : void 0;
|
|
35036
|
+
function invoked(access) {
|
|
35037
|
+
const a = up(access);
|
|
35038
|
+
const p = a.parent;
|
|
35039
|
+
if (!p) return false;
|
|
35040
|
+
if (ts5.isCallExpression(p) && p.expression === a) return true;
|
|
35041
|
+
if (ts5.isPropertyAccessExpression(p) && p.expression === a && ["handler", "callback"].includes(p.name.text)) {
|
|
35042
|
+
const q = up(p).parent;
|
|
35043
|
+
return !!q && ts5.isCallExpression(q) && up(q.expression) === up(p);
|
|
35044
|
+
}
|
|
35045
|
+
if (ts5.isVariableDeclaration(p) && p.initializer && up(p.initializer) === a && ts5.isIdentifier(p.name)) {
|
|
35046
|
+
const bound = p.name.text;
|
|
35047
|
+
let scope2 = p;
|
|
35048
|
+
while (scope2.parent && !ts5.isBlock(scope2) && !ts5.isSourceFile(scope2)) scope2 = scope2.parent;
|
|
35049
|
+
let called = false;
|
|
35050
|
+
const visit = (n) => {
|
|
35051
|
+
if (called) return;
|
|
35052
|
+
if (ts5.isIdentifier(n) && n.text === bound && n !== p.name && invoked(n)) called = true;
|
|
35053
|
+
else ts5.forEachChild(n, visit);
|
|
35054
|
+
};
|
|
35055
|
+
visit(scope2);
|
|
35056
|
+
return called;
|
|
35057
|
+
}
|
|
35058
|
+
return false;
|
|
35059
|
+
}
|
|
35060
|
+
function callsAt(e, helpers) {
|
|
35061
|
+
const x = up(e);
|
|
35062
|
+
const p = x.parent;
|
|
35063
|
+
if (!p) return false;
|
|
35064
|
+
if (ts5.isPropertyAssignment(p) && p.initializer === x && propName(p) === "name" || ts5.isShorthandPropertyAssignment(p) && p.name === x && p.name.text === "name") {
|
|
35065
|
+
const obj = p.parent;
|
|
35066
|
+
const holder = up(obj).parent;
|
|
35067
|
+
if (holder && ts5.isCallExpression(holder) && holder.arguments.some((a) => up(a) === up(obj)) && calleeName(holder) === "callTool")
|
|
35068
|
+
return true;
|
|
35069
|
+
if (holder && ts5.isPropertyAssignment(holder) && propName(holder) === "params") {
|
|
35070
|
+
const req = holder.parent;
|
|
35071
|
+
return req.properties.some(
|
|
35072
|
+
(q) => ts5.isPropertyAssignment(q) && propName(q) === "method" && ts5.isStringLiteralLike(q.initializer) && q.initializer.text === "tools/call"
|
|
35073
|
+
);
|
|
35074
|
+
}
|
|
35075
|
+
return false;
|
|
35076
|
+
}
|
|
35077
|
+
if (ts5.isCallExpression(p) && p.arguments.some((a) => up(a) === x)) {
|
|
35078
|
+
const i = p.arguments.findIndex((a) => up(a) === x);
|
|
35079
|
+
if (calleeName(p) === "get" && i === 0 && ts5.isPropertyAccessExpression(p.expression))
|
|
35080
|
+
return invoked(p);
|
|
35081
|
+
const name = calleeName(p);
|
|
35082
|
+
return !!name && (helpers.get(name)?.has(i) ?? false);
|
|
35083
|
+
}
|
|
35084
|
+
if (ts5.isElementAccessExpression(p) && up(p.argumentExpression) === x) return invoked(p);
|
|
35085
|
+
return false;
|
|
35086
|
+
}
|
|
35087
|
+
function deriveHelpers(files) {
|
|
35088
|
+
const helpers = /* @__PURE__ */ new Map();
|
|
35089
|
+
const fns = [];
|
|
35090
|
+
for (const { sf } of files) {
|
|
35091
|
+
const visit = (n) => {
|
|
35092
|
+
if (ts5.isFunctionDeclaration(n) && n.name && n.body) fns.push({ name: n.name.text, fn: n });
|
|
35093
|
+
else if (ts5.isVariableDeclaration(n) && ts5.isIdentifier(n.name) && n.initializer && (ts5.isArrowFunction(n.initializer) || ts5.isFunctionExpression(n.initializer)))
|
|
35094
|
+
fns.push({ name: n.name.text, fn: n.initializer });
|
|
35095
|
+
ts5.forEachChild(n, visit);
|
|
35096
|
+
};
|
|
35097
|
+
visit(sf);
|
|
35098
|
+
}
|
|
35099
|
+
for (let round = 0; round < 5; round++) {
|
|
35100
|
+
let grew = false;
|
|
35101
|
+
for (const { name, fn } of fns) {
|
|
35102
|
+
fn.parameters.forEach((param, i) => {
|
|
35103
|
+
if (!ts5.isIdentifier(param.name) || helpers.get(name)?.has(i)) return;
|
|
35104
|
+
const pname = param.name.text;
|
|
35105
|
+
let hit = false;
|
|
35106
|
+
const visit = (n) => {
|
|
35107
|
+
if (hit) return;
|
|
35108
|
+
if (ts5.isIdentifier(n) && n.text === pname && n !== param.name && callsAt(n, helpers))
|
|
35109
|
+
hit = true;
|
|
35110
|
+
else ts5.forEachChild(n, visit);
|
|
35111
|
+
};
|
|
35112
|
+
if (fn.body) visit(fn.body);
|
|
35113
|
+
if (hit) {
|
|
35114
|
+
if (!helpers.has(name)) helpers.set(name, /* @__PURE__ */ new Set());
|
|
35115
|
+
helpers.get(name)?.add(i);
|
|
35116
|
+
grew = true;
|
|
35117
|
+
}
|
|
35118
|
+
});
|
|
35119
|
+
}
|
|
35120
|
+
if (!grew) break;
|
|
35121
|
+
}
|
|
35122
|
+
return helpers;
|
|
35123
|
+
}
|
|
35124
|
+
function testCalls(files, tools) {
|
|
35125
|
+
const helpers = deriveHelpers(files);
|
|
35126
|
+
const wanted = new Set(tools);
|
|
35127
|
+
const out = new Map(tools.map((t) => [t, []]));
|
|
35128
|
+
for (const { rel, sf } of files) {
|
|
35129
|
+
const visit = (n) => {
|
|
35130
|
+
if ((ts5.isStringLiteral(n) || ts5.isNoSubstitutionTemplateLiteral(n)) && wanted.has(n.text) && callsAt(n, helpers))
|
|
35131
|
+
out.get(n.text)?.push(`${rel}:${sf.getLineAndCharacterOfPosition(n.getStart(sf)).line + 1}`);
|
|
35132
|
+
ts5.forEachChild(n, visit);
|
|
35133
|
+
};
|
|
35134
|
+
visit(sf);
|
|
35135
|
+
}
|
|
35136
|
+
return out;
|
|
35137
|
+
}
|
|
35138
|
+
function s54Controls() {
|
|
35139
|
+
const f = (code) => [
|
|
35140
|
+
{
|
|
35141
|
+
rel: "c.test.ts",
|
|
35142
|
+
sf: ts5.createSourceFile("c.test.ts", code, ts5.ScriptTarget.Latest, true, ts5.ScriptKind.TS)
|
|
35143
|
+
}
|
|
35144
|
+
];
|
|
35145
|
+
const k = (code) => (testCalls(f(code), ["t"]).get("t") ?? []).length;
|
|
35146
|
+
return {
|
|
35147
|
+
sees: k('await client.callTool({ name: "t", arguments: {} });') === 1 && k('send({ method: "tools/call", params: { name: "t" } });') === 1 && k('tools.get("t")!({});') === 1 && k('function call(m, n) { return m.get(n)({}); }\ncall(tools, "t");') === 1,
|
|
35148
|
+
spares: k('expect(names).toContain("t");\nconst all = ["t"];') === 0
|
|
35149
|
+
};
|
|
35150
|
+
}
|
|
35151
|
+
function runStatic8(tree) {
|
|
35152
|
+
const ctl = s54Controls();
|
|
35153
|
+
if (!ctl.sees || !ctl.spares)
|
|
35154
|
+
throw new Error(
|
|
35155
|
+
`S54 positive control FAILED: ${JSON.stringify(ctl)} \u2014 reader broken, verdict untrustworthy`
|
|
35156
|
+
);
|
|
35157
|
+
const { tools, unresolved } = productRegistrations(tree);
|
|
35158
|
+
if (tools.length === 0) {
|
|
35159
|
+
const surface = toolSurfaceAnchor(tree);
|
|
35160
|
+
if (surface || unresolved.length > 0)
|
|
35161
|
+
return couldNotJudge(
|
|
35162
|
+
ID20,
|
|
35163
|
+
surface ?? unresolved[0],
|
|
35164
|
+
noToolsLocatedReason(tree, `no tool name was derived (${RULE20})`)
|
|
35165
|
+
);
|
|
35166
|
+
return {
|
|
35167
|
+
id: ID20,
|
|
35168
|
+
anchor: tree.root,
|
|
35169
|
+
state: "absent",
|
|
35170
|
+
verdict: `no MCP tool registered in product source \u2014 ${RULE20} n/a`
|
|
35171
|
+
};
|
|
35172
|
+
}
|
|
35173
|
+
let root = tree.root;
|
|
35174
|
+
try {
|
|
35175
|
+
if (!statSync24(root).isDirectory()) root = join35(root, "..");
|
|
35176
|
+
} catch {
|
|
35177
|
+
}
|
|
35178
|
+
const { files, unread: unread2 } = testFiles2(root);
|
|
35179
|
+
for (const a of unresolved)
|
|
35180
|
+
unread2.push({
|
|
35181
|
+
anchor: a,
|
|
35182
|
+
reason: `a tool registered here has a computed name, so whether a test calls it is unread (${RULE20})`
|
|
35183
|
+
});
|
|
35184
|
+
if (files.length === 0)
|
|
35185
|
+
return settle(
|
|
35186
|
+
ID20,
|
|
35187
|
+
couldNotJudge(
|
|
35188
|
+
ID20,
|
|
35189
|
+
tools[0].anchor,
|
|
35190
|
+
`no test file under ${root} (searched: *.test.* / *.spec.* and test/, tests/, __tests__/, spec/, specs/, e2e/ directories): a suite outside the scanned root is not read, so whether the ${tools.length} registered tool(s) are called is unread (${RULE20})`
|
|
35191
|
+
),
|
|
35192
|
+
unread2
|
|
35193
|
+
);
|
|
35194
|
+
const calls = testCalls(
|
|
35195
|
+
files,
|
|
35196
|
+
tools.map((t) => t.name)
|
|
35197
|
+
);
|
|
35198
|
+
const untested = tools.filter((t) => (calls.get(t.name) ?? []).length === 0);
|
|
35199
|
+
if (untested.length > 0)
|
|
35200
|
+
return settle(
|
|
35201
|
+
ID20,
|
|
35202
|
+
{
|
|
35203
|
+
id: ID20,
|
|
35204
|
+
anchor: untested[0].anchor,
|
|
35205
|
+
state: "non-conforming",
|
|
35206
|
+
verdict: `${untested.length} of ${tools.length} registered tool(s) are called by no test (${files.length} test file(s) read under ${root}; call positions K1..K4): ${names(untested.map((t) => `${t.name} (${t.anchor})`))} (${RULE20})`
|
|
35207
|
+
},
|
|
35208
|
+
unread2
|
|
35209
|
+
);
|
|
35210
|
+
return settle(
|
|
35211
|
+
ID20,
|
|
35212
|
+
{
|
|
35213
|
+
id: ID20,
|
|
35214
|
+
anchor: tools[0].anchor,
|
|
35215
|
+
state: "present",
|
|
35216
|
+
verdict: `${tools.length} registered tool(s), each called by at least one test (${files.length} test file(s) read under ${root}) (${RULE20})`
|
|
35217
|
+
},
|
|
35218
|
+
unread2
|
|
35219
|
+
);
|
|
35220
|
+
}
|
|
35221
|
+
function runServedHalf6(runtime) {
|
|
35222
|
+
const anchor = `${runtime.root} (served)`;
|
|
35223
|
+
const why = runtime.remote ? `a URL scan has no repository: S-54 reads the repository's test files, which the served list does not carry (${RULE20})` : `the served tools/list does not say which tests call a tool: S-54 is read from the repository (static) (${RULE20})`;
|
|
35224
|
+
return couldNotJudge(
|
|
35225
|
+
ID20,
|
|
35226
|
+
anchor,
|
|
35227
|
+
runtime.launchError ? `${why}; and the server could not be started/introspected: ${runtime.launchError}` : why
|
|
35228
|
+
);
|
|
35229
|
+
}
|
|
35230
|
+
var s54ToolsTested = {
|
|
35231
|
+
id: ID20,
|
|
35232
|
+
rule: RULE20,
|
|
35233
|
+
pin: S51_RULES_PIN,
|
|
35234
|
+
run: runStatic8,
|
|
35235
|
+
runServed: (runtime) => runServedHalf6(runtime)
|
|
35236
|
+
};
|
|
35237
|
+
|
|
33131
35238
|
// src/detectors/index.ts
|
|
33132
35239
|
var registered = [
|
|
33133
35240
|
d2,
|
|
@@ -33251,6 +35358,10 @@ var registered = [
|
|
|
33251
35358
|
s42WriteReadClaims,
|
|
33252
35359
|
s43UnionInput,
|
|
33253
35360
|
s44ClosedOutput,
|
|
35361
|
+
s51ServedOutput,
|
|
35362
|
+
s52NoNullSuccess,
|
|
35363
|
+
s53StructuredNotText,
|
|
35364
|
+
s54ToolsTested,
|
|
33254
35365
|
e5ExtensionIsolation,
|
|
33255
35366
|
a3SandboxRespected,
|
|
33256
35367
|
a4WcagGate,
|
|
@@ -33287,6 +35398,10 @@ var READS_CODE = /* @__PURE__ */ new Set([
|
|
|
33287
35398
|
"S-42",
|
|
33288
35399
|
"S-43",
|
|
33289
35400
|
"S-44",
|
|
35401
|
+
"S-51",
|
|
35402
|
+
"S-52",
|
|
35403
|
+
"S-53",
|
|
35404
|
+
"S-54",
|
|
33290
35405
|
"E-5",
|
|
33291
35406
|
"A-3"
|
|
33292
35407
|
]);
|
|
@@ -33404,13 +35519,13 @@ function parseEventsArgs(args) {
|
|
|
33404
35519
|
}
|
|
33405
35520
|
|
|
33406
35521
|
// src/gate.ts
|
|
33407
|
-
import { readFileSync as
|
|
35522
|
+
import { readFileSync as readFileSync25 } from "fs";
|
|
33408
35523
|
var OWED_FILE_NAME = "mcp-doctor.owed.json";
|
|
33409
35524
|
var FORMAT = `expected {"owed": [{"id": "<detector id, the table's first column>", "reason": "<why this row may publish undecided>"}, ...]}`;
|
|
33410
35525
|
function readOwedFile(path, opts) {
|
|
33411
35526
|
let text;
|
|
33412
35527
|
try {
|
|
33413
|
-
text =
|
|
35528
|
+
text = readFileSync25(path, "utf8");
|
|
33414
35529
|
} catch (err) {
|
|
33415
35530
|
const code = err.code;
|
|
33416
35531
|
if (code === "ENOENT" && !opts.explicit) return { kind: "none", path };
|
|
@@ -34099,7 +36214,7 @@ function selfSignedCert(commonName = "mcp-doctor events-ready receiver") {
|
|
|
34099
36214
|
const { privateKey, publicKey } = generateKeyPairSync("ec", { namedCurve: "P-256" });
|
|
34100
36215
|
const name = seq(tlv(49, seq(CN, tlv(12, Buffer.from(commonName, "utf8")))));
|
|
34101
36216
|
const serial = randomBytes(16);
|
|
34102
|
-
serial[0] = serial[0] &
|
|
36217
|
+
serial[0] = serial[0] & 63 | 64;
|
|
34103
36218
|
const now = Date.now();
|
|
34104
36219
|
const san = seq(
|
|
34105
36220
|
tlv(135, Buffer.from([127, 0, 0, 1])),
|
|
@@ -34163,7 +36278,7 @@ var HEADERS2 = [
|
|
|
34163
36278
|
"webhook-signature",
|
|
34164
36279
|
"x-mcp-subscription-id"
|
|
34165
36280
|
];
|
|
34166
|
-
var
|
|
36281
|
+
var isObj5 = (v) => Boolean(v) && typeof v === "object" && !Array.isArray(v);
|
|
34167
36282
|
function describe(o) {
|
|
34168
36283
|
switch (o.kind) {
|
|
34169
36284
|
case "result":
|
|
@@ -34178,7 +36293,7 @@ function describe(o) {
|
|
|
34178
36293
|
}
|
|
34179
36294
|
var isCode = (o, code) => o.kind === "error" && o.code === code;
|
|
34180
36295
|
var authRefused = (o) => isCode(o, -32012) || o.kind === "http" && (o.status === 401 || o.status === 403);
|
|
34181
|
-
var subId = (o) => o?.kind === "result" &&
|
|
36296
|
+
var subId = (o) => o?.kind === "result" && isObj5(o.result) && typeof o.result.id === "string" ? o.result.id : void 0;
|
|
34182
36297
|
var RpcClient = class {
|
|
34183
36298
|
constructor(ep, timeoutMs) {
|
|
34184
36299
|
this.ep = ep;
|
|
@@ -34245,10 +36360,10 @@ var RpcClient = class {
|
|
|
34245
36360
|
reason: `HTTP ${res.status} body is not JSON-RPC (${e.message})`
|
|
34246
36361
|
} : { kind: "http", status: res.status, raw: "" };
|
|
34247
36362
|
}
|
|
34248
|
-
const msg = messages.find((m) =>
|
|
34249
|
-
if (!
|
|
36363
|
+
const msg = messages.find((m) => isObj5(m) && m.id === id);
|
|
36364
|
+
if (!isObj5(msg))
|
|
34250
36365
|
return res.ok ? { kind: "no-answer", reason: `HTTP ${res.status} carried no answer to request ${id}` } : { kind: "http", status: res.status, raw };
|
|
34251
|
-
if (
|
|
36366
|
+
if (isObj5(msg.error)) {
|
|
34252
36367
|
return {
|
|
34253
36368
|
kind: "error",
|
|
34254
36369
|
code: msg.error.code,
|
|
@@ -34281,7 +36396,7 @@ async function readSse(res, id) {
|
|
|
34281
36396
|
if (data) {
|
|
34282
36397
|
const m = JSON.parse(data);
|
|
34283
36398
|
messages.push(m);
|
|
34284
|
-
if (
|
|
36399
|
+
if (isObj5(m) && m.id === id) {
|
|
34285
36400
|
raw = data;
|
|
34286
36401
|
await reader.cancel();
|
|
34287
36402
|
return { messages, raw };
|
|
@@ -34295,7 +36410,7 @@ async function readSse(res, id) {
|
|
|
34295
36410
|
function answer(role, hit, seen, redirectTarget, leakMarker) {
|
|
34296
36411
|
if (role === "redirect") return { status: 307, headers: { location: redirectTarget } };
|
|
34297
36412
|
if (hit.kind === "verification") {
|
|
34298
|
-
const challenge =
|
|
36413
|
+
const challenge = isObj5(hit.body) ? hit.body.challenge : void 0;
|
|
34299
36414
|
if (role === "noecho") {
|
|
34300
36415
|
return { status: 200, body: JSON.stringify({ challenge: leakMarker, note: leakMarker }) };
|
|
34301
36416
|
}
|
|
@@ -34313,7 +36428,7 @@ function answer(role, hit, seen, redirectTarget, leakMarker) {
|
|
|
34313
36428
|
return { status: 200 };
|
|
34314
36429
|
}
|
|
34315
36430
|
function eventIdOf(h) {
|
|
34316
|
-
if (
|
|
36431
|
+
if (isObj5(h.body) && typeof h.body.eventId === "string") return h.body.eventId;
|
|
34317
36432
|
return h.headers["webhook-id"];
|
|
34318
36433
|
}
|
|
34319
36434
|
async function listen(cert, port, route) {
|
|
@@ -34331,7 +36446,7 @@ async function listen(cert, port, route) {
|
|
|
34331
36446
|
let kind = "unreadable";
|
|
34332
36447
|
try {
|
|
34333
36448
|
body = JSON.parse(raw.toString("utf8"));
|
|
34334
|
-
kind =
|
|
36449
|
+
kind = isObj5(body) ? body.type === "verification" ? "verification" : "event" : "unreadable";
|
|
34335
36450
|
} catch {
|
|
34336
36451
|
kind = "unreadable";
|
|
34337
36452
|
}
|
|
@@ -34411,7 +36526,7 @@ async function runEventsReady(opts) {
|
|
|
34411
36526
|
clientInfo: { name: "mcp-doctor events-ready", version: "0" }
|
|
34412
36527
|
});
|
|
34413
36528
|
if (disc.kind === "result") {
|
|
34414
|
-
if (
|
|
36529
|
+
if (isObj5(disc.result) && typeof disc.result.protocolVersion === "string") {
|
|
34415
36530
|
client.setProtocolVersion(disc.result.protocolVersion);
|
|
34416
36531
|
}
|
|
34417
36532
|
await client.notify("notifications/initialized");
|
|
@@ -34422,15 +36537,15 @@ async function runEventsReady(opts) {
|
|
|
34422
36537
|
);
|
|
34423
36538
|
}
|
|
34424
36539
|
}
|
|
34425
|
-
const caps =
|
|
34426
|
-
if (!
|
|
36540
|
+
const caps = isObj5(disc.result) ? disc.result.capabilities : void 0;
|
|
36541
|
+
if (!isObj5(caps)) {
|
|
34427
36542
|
const why = `the ${via} result carries no capabilities object (${describe(disc)})`;
|
|
34428
36543
|
return EVENTS_READY_CHECKS.map((c) => couldNotJudge(c.id, via, `${why} (${c.rule})`));
|
|
34429
36544
|
}
|
|
34430
|
-
const declared =
|
|
36545
|
+
const declared = isObj5(caps.events);
|
|
34431
36546
|
const list = await client.call("events/list", {});
|
|
34432
|
-
const listed = list.kind === "result" &&
|
|
34433
|
-
const firstName = listed.find((d) =>
|
|
36547
|
+
const listed = list.kind === "result" && isObj5(list.result) && Array.isArray(list.result.events) ? list.result.events : [];
|
|
36548
|
+
const firstName = listed.find((d) => isObj5(d) && typeof d.name === "string");
|
|
34434
36549
|
const eventName = opts.event?.name ?? firstName?.name;
|
|
34435
36550
|
const args = opts.event?.arguments ?? {};
|
|
34436
36551
|
const outcomes = /* @__PURE__ */ new Map();
|
|
@@ -34666,7 +36781,7 @@ async function runEventsReady(opts) {
|
|
|
34666
36781
|
);
|
|
34667
36782
|
})();
|
|
34668
36783
|
const okEvents = hitsOf("ok").filter((h) => h.kind === "event");
|
|
34669
|
-
const triggerFailed = triggerOut && (triggerOut.kind !== "result" ||
|
|
36784
|
+
const triggerFailed = triggerOut && (triggerOut.kind !== "result" || isObj5(triggerOut.result) && triggerOut.result.isError === true);
|
|
34670
36785
|
const rowE = (() => {
|
|
34671
36786
|
const anchor = "callback verification";
|
|
34672
36787
|
if (!base) return cnj("e", anchor, NO_BASE);
|
|
@@ -34686,7 +36801,7 @@ async function runEventsReady(opts) {
|
|
|
34686
36801
|
"no verification envelope reached the conforming receiver before events/subscribe returned"
|
|
34687
36802
|
);
|
|
34688
36803
|
} else {
|
|
34689
|
-
const ch =
|
|
36804
|
+
const ch = isObj5(env.body) ? env.body.challenge : void 0;
|
|
34690
36805
|
if (typeof ch !== "string" || ch === "")
|
|
34691
36806
|
fails.push("the verification envelope carries no challenge string");
|
|
34692
36807
|
if (!env.headers["webhook-id"]) fails.push("the verification envelope has no webhook-id");
|
|
@@ -34697,7 +36812,7 @@ async function runEventsReady(opts) {
|
|
|
34697
36812
|
(h) => h.kind === "verification" && h.role !== "redirect-target"
|
|
34698
36813
|
);
|
|
34699
36814
|
const dup = (vals) => vals.length !== new Set(vals).size;
|
|
34700
|
-
if (dup(envs.map((h) =>
|
|
36815
|
+
if (dup(envs.map((h) => isObj5(h.body) ? h.body.challenge : void 0)))
|
|
34701
36816
|
fails.push("a challenge was reused across verifications");
|
|
34702
36817
|
if (dup(envs.map((h) => h.headers["webhook-id"])))
|
|
34703
36818
|
fails.push("a webhook-id was reused across verifications");
|
|
@@ -34705,7 +36820,7 @@ async function runEventsReady(opts) {
|
|
|
34705
36820
|
if (no.kind === "result") {
|
|
34706
36821
|
fails.push(`a receiver that did not echo the challenge was accepted (${describe(no)})`);
|
|
34707
36822
|
} else if (no.kind === "error" && no.code === -32015) {
|
|
34708
|
-
const reason =
|
|
36823
|
+
const reason = isObj5(no.data) ? no.data.reason : void 0;
|
|
34709
36824
|
if (typeof reason !== "string" || !REASONS.includes(reason)) {
|
|
34710
36825
|
fails.push(
|
|
34711
36826
|
`the -32015 data.reason ${JSON.stringify(reason)} is not one of ${REASONS.join("|")}`
|
|
@@ -34849,7 +36964,7 @@ async function runEventsReady(opts) {
|
|
|
34849
36964
|
const single = [...groups.values()].filter((g) => g.length === 1).map((g) => g[0]);
|
|
34850
36965
|
const sameData = single.filter(
|
|
34851
36966
|
(a) => single.some(
|
|
34852
|
-
(b) => a !== b &&
|
|
36967
|
+
(b) => a !== b && isObj5(a.body) && isObj5(b.body) && JSON.stringify(a.body.data) === JSON.stringify(b.body.data) && a.status >= 500
|
|
34853
36968
|
)
|
|
34854
36969
|
);
|
|
34855
36970
|
if (sameData.length > 0) fails.push("a retry after a 500 was sent under a new eventId");
|
|
@@ -34961,17 +37076,17 @@ function verifySignature(secret, h) {
|
|
|
34961
37076
|
|
|
34962
37077
|
// src/runtime/launch.ts
|
|
34963
37078
|
import { spawnSync as spawnSync3 } from "child_process";
|
|
34964
|
-
import { existsSync as existsSync23, readFileSync as
|
|
34965
|
-
import { dirname as dirname17, isAbsolute, join as
|
|
37079
|
+
import { existsSync as existsSync23, readFileSync as readFileSync26, statSync as statSync25 } from "fs";
|
|
37080
|
+
import { dirname as dirname17, isAbsolute, join as join36, resolve as resolve3 } from "path";
|
|
34966
37081
|
function findPackageDir(target) {
|
|
34967
37082
|
let dir;
|
|
34968
37083
|
try {
|
|
34969
|
-
dir =
|
|
37084
|
+
dir = statSync25(target).isDirectory() ? target : dirname17(target);
|
|
34970
37085
|
} catch {
|
|
34971
37086
|
return null;
|
|
34972
37087
|
}
|
|
34973
37088
|
for (let depth = 0; depth < 8; depth++) {
|
|
34974
|
-
if (existsSync23(
|
|
37089
|
+
if (existsSync23(join36(dir, "package.json"))) return dir;
|
|
34975
37090
|
const parent = dirname17(dir);
|
|
34976
37091
|
if (parent === dir) break;
|
|
34977
37092
|
dir = parent;
|
|
@@ -34996,13 +37111,13 @@ function deriveLaunchPlan(target) {
|
|
|
34996
37111
|
}
|
|
34997
37112
|
let pkg;
|
|
34998
37113
|
try {
|
|
34999
|
-
if (!
|
|
35000
|
-
return { error: `${
|
|
37114
|
+
if (!statSync25(join36(pkgDir, "package.json")).isFile()) {
|
|
37115
|
+
return { error: `${join36(pkgDir, "package.json")} is not a regular file \u2014 not read` };
|
|
35001
37116
|
}
|
|
35002
|
-
pkg = JSON.parse(
|
|
37117
|
+
pkg = JSON.parse(readFileSync26(join36(pkgDir, "package.json"), "utf8"));
|
|
35003
37118
|
} catch (err) {
|
|
35004
37119
|
return {
|
|
35005
|
-
error: `could not parse ${
|
|
37120
|
+
error: `could not parse ${join36(pkgDir, "package.json")}: ${err instanceof Error ? err.message : String(err)}`
|
|
35006
37121
|
};
|
|
35007
37122
|
}
|
|
35008
37123
|
const bin = firstBinEntry(pkg.bin);
|
|
@@ -35050,8 +37165,21 @@ const pending = new Map();
|
|
|
35050
37165
|
const lists = [];
|
|
35051
37166
|
// The one served tool-call response (S-2): a tool declared read-only that needs no argument.
|
|
35052
37167
|
const calls = [];
|
|
37168
|
+
// S-51..S-53: one record per served tool, its tools/call answer or why none was sent. The result is recorded WITH its
|
|
37169
|
+
// structuredContent and its text blocks (each text cut at 64 KiB), because those rules read the value itself: whether
|
|
37170
|
+
// it validates against the served outputSchema, whether it is null or empty, whether the data lives in the text. The
|
|
37171
|
+
// call goes through the same callability() rule as every other call (consent over --url, read-only, no invented
|
|
37172
|
+
// argument), so a tool that could not be called is named with the reason, never skipped.
|
|
37173
|
+
const toolCalls = [];
|
|
37174
|
+
const callPending = new Map();
|
|
35053
37175
|
const listPending = new Map();
|
|
35054
37176
|
let nextId = 10;
|
|
37177
|
+
// S-51..S-53 judge EVERY served tool, so tools/list is followed to its last page and each page's tools are merged
|
|
37178
|
+
// into tools / toolCalls. Until the last page has answered, toolsPaging names the cursor left unread: a reader never
|
|
37179
|
+
// calls a partial list "every tool". A server that keeps serving a cursor stops at the page cap, named as such.
|
|
37180
|
+
const TOOLS_PAGE_CAP = 50;
|
|
37181
|
+
let toolsPaging = { complete: true, pages: 1 };
|
|
37182
|
+
let ingestTools;
|
|
35055
37183
|
let probeTimer;
|
|
35056
37184
|
let transport;
|
|
35057
37185
|
// The authorization server's metadata and its authorization endpoint are PUBLIC: a server that refuses the MCP
|
|
@@ -35060,22 +37188,25 @@ let transport;
|
|
|
35060
37188
|
const publicAuthAfterFailure = async () => {
|
|
35061
37189
|
if (plan.kind !== "http") return undefined;
|
|
35062
37190
|
try {
|
|
35063
|
-
const authServer = await
|
|
37191
|
+
const { authServer, authDocs } = await readAuth();
|
|
35064
37192
|
const authorize = authServer.kind === "document" ? await probeAuthorize(authServer.document) : { kind: "not-run", reason: "the authorization-server metadata was not read, so no authorization_endpoint is known" };
|
|
35065
37193
|
const discovery = await readDiscovery().catch((e) => ({ kind: "not-run", reason: "the discovery reads failed: " + (e && e.message ? e.message : String(e)) }));
|
|
35066
|
-
return { authServer, authorize, discovery };
|
|
37194
|
+
return { authServer, authDocs, authorize, discovery };
|
|
35067
37195
|
} catch (e) { return { authServer: { kind: "unavailable", url: plan.url, reason: "the public read failed: " + (e && e.message ? e.message : String(e)) } }; }
|
|
35068
37196
|
};
|
|
35069
37197
|
const fail = (msg) => { if (settled) return; settled = true; Promise.resolve(transport && transport.close()).then(() => publicAuthAfterFailure()).catch(() => undefined).then((publicAuth) => done({ launchError: msg, ...(publicAuth ? { publicAuth } : {}) })); };
|
|
35070
|
-
const outstanding = () => pending.size + listPending.size;
|
|
37198
|
+
const outstanding = () => pending.size + listPending.size + callPending.size;
|
|
35071
37199
|
const finish = (why) => {
|
|
35072
37200
|
if (settled) return; settled = true; clearTimeout(to); clearTimeout(probeTimer);
|
|
35073
37201
|
for (const idx of pending.values()) probes[idx].outcome = { kind: "no-answer", reason: why };
|
|
37202
|
+
if (!toolsPaging.complete && / got no answer$/.test(toolsPaging.reason)) toolsPaging.reason += " (" + why + ")";
|
|
35074
37203
|
for (const rec of listPending.values()) {
|
|
37204
|
+
if (rec.toolsPageOf !== undefined) continue;
|
|
35075
37205
|
if (rec.followUpOf) rec.followUpOf.followUp = { outcome: "no-answer", detail: why };
|
|
35076
|
-
else { rec.outcome = "no-answer"; rec.detail = why; }
|
|
37206
|
+
else { rec.outcome = "no-answer"; rec.detail = why; if (rec.alsoTool) { rec.alsoTool.reason = why; delete rec.alsoTool; } }
|
|
35077
37207
|
}
|
|
35078
|
-
|
|
37208
|
+
for (const rec of callPending.values()) { rec.kind = "no-answer"; rec.reason = why; }
|
|
37209
|
+
const served = { capabilities, protocolVersion: negotiated, lists, calls, toolCalls: Array.isArray(tools) ? toolCalls : undefined, versionProbe: { kind: "not-run", reason: "not run" }, authServer: { kind: "not-run", reason: "not run" }, authorize: { kind: "not-run", reason: "not run" }, ...(initializeRecord ? { initialize: initializeRecord } : {}), toolMetaRecorded: Array.isArray(tools), toolsPaging, discovery: { kind: "not-run", reason: "not run" } };
|
|
35079
37210
|
Promise.resolve(extras(served))
|
|
35080
37211
|
.catch((e) => { served.versionProbe = { kind: "not-run", reason: "the probe threw: " + (e && e.message ? e.message : String(e)) }; })
|
|
35081
37212
|
.then(() => transport && transport.close())
|
|
@@ -35235,22 +37366,29 @@ const getPublicJson = async (url) => {
|
|
|
35235
37366
|
// The authorization server the PRM names (RFC 9728), then its metadata (RFC 8414). The doctor fetches
|
|
35236
37367
|
// ONLY a URL on the endpoint's own origin (so the scheme the caller already vetted): a server that names another origin never makes the
|
|
35237
37368
|
// doctor request it (no SSRF from the audit tool); that case is reported as unavailable, naming it.
|
|
35238
|
-
|
|
37369
|
+
// S-5 (f)(k): the two PRM copies (path-suffixed, bare) are RECORDED as served, whatever they answer, and the OIDC
|
|
37370
|
+
// discovery is read at the same-origin issuer (OIDC Discovery 1.0: the issuer, then /.well-known/openid-configuration).
|
|
37371
|
+
const readAuth = async () => {
|
|
35239
37372
|
const ep = new URL(plan.url);
|
|
35240
|
-
const
|
|
37373
|
+
const mcpUrl = ep.origin + ep.pathname;
|
|
37374
|
+
const bareUrl = ep.origin + "/.well-known/oauth-protected-resource";
|
|
37375
|
+
const suffixedUrl = ep.pathname === "/" ? undefined : bareUrl + ep.pathname;
|
|
37376
|
+
const [suffixed, bare] = await Promise.all([suffixedUrl ? publicGet(suffixedUrl, "application/json") : Promise.resolve(undefined), publicGet(bareUrl, "application/json")]);
|
|
37377
|
+
const prm = { ...(suffixed ? { suffixed } : {}), bare };
|
|
37378
|
+
const docs = (oidc) => ({ kind: "probed", mcpUrl, prm, oidc });
|
|
35241
37379
|
let issuer;
|
|
35242
|
-
for (const
|
|
35243
|
-
const
|
|
35244
|
-
const names = r.ok && Array.isArray(r.doc.authorization_servers) ? r.doc.authorization_servers.filter((x) => typeof x === "string") : [];
|
|
37380
|
+
for (const r of [suffixed, bare]) {
|
|
37381
|
+
const names = r && r.status === 200 && r.json && Array.isArray(r.json.authorization_servers) ? r.json.authorization_servers.filter((x) => typeof x === "string") : [];
|
|
35245
37382
|
if (names.length > 0) { issuer = names[0]; break; }
|
|
35246
37383
|
}
|
|
35247
|
-
if (!issuer) return { kind: "unavailable", url:
|
|
35248
|
-
let iu; try { iu = new URL(issuer); } catch { return { kind: "unavailable", url:
|
|
35249
|
-
if (iu.origin !== ep.origin) return { kind: "unavailable", url: iu.origin, reason: "the authorization server is on another origin (" + iu.host + "): not fetched from here, only a same-origin authorization server is read" };
|
|
37384
|
+
if (!issuer) return { authServer: { kind: "unavailable", url: suffixedUrl || bareUrl, reason: "the protected-resource metadata names no authorization server (read at the suffixed and the bare path)" }, authDocs: docs({ skipped: "the protected-resource metadata names no authorization server, so no issuer is known" }) };
|
|
37385
|
+
let iu; try { iu = new URL(issuer); } catch { return { authServer: { kind: "unavailable", url: suffixedUrl || bareUrl, reason: "the protected-resource metadata names an authorization server that is not a URL" }, authDocs: docs({ skipped: "the authorization server named is not a URL" }) }; }
|
|
37386
|
+
if (iu.origin !== ep.origin) return { authServer: { kind: "unavailable", url: iu.origin, reason: "the authorization server is on another origin (" + iu.host + "): not fetched from here, only a same-origin authorization server is read" }, authDocs: docs({ skipped: "the authorization server is on another origin (" + iu.host + "): its OIDC discovery is not fetched from here" }) };
|
|
35250
37387
|
const url = iu.origin + "/.well-known/oauth-authorization-server" + (iu.pathname === "/" ? "" : iu.pathname);
|
|
35251
|
-
const r = await getPublicJson(url);
|
|
35252
|
-
|
|
35253
|
-
return { kind: "
|
|
37388
|
+
const [r, oidc] = await Promise.all([getPublicJson(url), publicGet(iu.origin + iu.pathname.replace(/\/$/, "") + "/.well-known/openid-configuration", "application/json")]);
|
|
37389
|
+
const authDocs = docs(oidc);
|
|
37390
|
+
if (!r.ok) return { authServer: { kind: "unavailable", url, reason: r.reason }, authDocs };
|
|
37391
|
+
return { authServer: { kind: "document", url, status: r.status, document: r.doc }, authDocs };
|
|
35254
37392
|
};
|
|
35255
37393
|
// S-46 served half: for each known CIMD client, read ITS metadata document (the redirect URIs as the client sends
|
|
35256
37394
|
// them), then start one authorization request per redirect at the served authorization_endpoint. NO credential is
|
|
@@ -35326,9 +37464,10 @@ const extras = async (served) => {
|
|
|
35326
37464
|
served.versionProbe = { kind: "not-run", reason: "stdio transport: the MCP-Protocol-Version header exists on HTTP only" };
|
|
35327
37465
|
served.authServer = { kind: "not-run", reason: "stdio transport: no authorization-server metadata is served" };
|
|
35328
37466
|
served.authorize = { kind: "not-run", reason: "stdio transport: no authorization endpoint is served" };
|
|
37467
|
+
served.authDocs = { kind: "not-run", reason: "stdio transport: no protected-resource metadata is served" };
|
|
35329
37468
|
return;
|
|
35330
37469
|
}
|
|
35331
|
-
const [vp,
|
|
37470
|
+
const [vp, auth, discovery] = await Promise.all([
|
|
35332
37471
|
(async () => {
|
|
35333
37472
|
const v = transport.negotiatedVersion();
|
|
35334
37473
|
if (!v) return { kind: "not-run", reason: "no protocol version was negotiated, so no supported-version control request can be sent" };
|
|
@@ -35338,12 +37477,14 @@ const extras = async (served) => {
|
|
|
35338
37477
|
return { kind: "statuses", supportedVersion: v, supported, unsupported };
|
|
35339
37478
|
} catch (e) { return { kind: "not-run", reason: "the header probe failed: " + (e && e.message ? e.message : String(e)) }; }
|
|
35340
37479
|
})(),
|
|
35341
|
-
|
|
37480
|
+
readAuth().catch((e) => ({ authServer: { kind: "unavailable", url: plan.url, reason: "the read failed: " + (e && e.message ? e.message : String(e)) }, authDocs: { kind: "not-run", reason: "the read failed: " + (e && e.message ? e.message : String(e)) } })),
|
|
35342
37481
|
readDiscovery().catch((e) => ({ kind: "not-run", reason: "the discovery reads failed: " + (e && e.message ? e.message : String(e)) })),
|
|
35343
37482
|
]);
|
|
35344
37483
|
served.discovery = discovery;
|
|
35345
37484
|
served.versionProbe = vp;
|
|
37485
|
+
const as = auth.authServer;
|
|
35346
37486
|
served.authServer = as;
|
|
37487
|
+
served.authDocs = auth.authDocs;
|
|
35347
37488
|
served.authorize = as.kind === "document"
|
|
35348
37489
|
? await probeAuthorize(as.document).catch((e) => ({ kind: "not-run", reason: "the sign-in probe failed: " + (e && e.message ? e.message : String(e)) }))
|
|
35349
37490
|
: { kind: "not-run", reason: "the authorization-server metadata was not read, so no authorization_endpoint is known" };
|
|
@@ -35362,6 +37503,58 @@ const followCursor = (rec) => {
|
|
|
35362
37503
|
listPending.set(fid, { method: rec.method, followUpOf: rec });
|
|
35363
37504
|
send({ jsonrpc: "2.0", id: fid, method: rec.method, params: { cursor: rec.nextCursor } });
|
|
35364
37505
|
};
|
|
37506
|
+
// tools/list pages beyond the second: the cursor is presented back untouched, as for followCursor.
|
|
37507
|
+
const followToolsPage = (cursor) => {
|
|
37508
|
+
const fid = nextId++;
|
|
37509
|
+
listPending.set(fid, { method: "tools/list", toolsPageOf: cursor });
|
|
37510
|
+
send({ jsonrpc: "2.0", id: fid, method: "tools/list", params: { cursor } });
|
|
37511
|
+
};
|
|
37512
|
+
// One answered tools/list page after the first: its tools are merged, then the next cursor is followed.
|
|
37513
|
+
const onToolsPage = (cursor, got, msg) => {
|
|
37514
|
+
const page = msg.result && Array.isArray(msg.result.tools) ? msg.result.tools : undefined;
|
|
37515
|
+
if (got.outcome !== "answered" || !page || !ingestTools) {
|
|
37516
|
+
toolsPaging = { complete: false, pages: toolsPaging.pages, unreadCursor: cursor, reason: "the tools/list page for cursor " + JSON.stringify(cursor) + " was not read: " + (got.detail || "its result carries no tools array") };
|
|
37517
|
+
return;
|
|
37518
|
+
}
|
|
37519
|
+
ingestTools(page);
|
|
37520
|
+
const pages = toolsPaging.pages + 1;
|
|
37521
|
+
const next = msg.result.nextCursor;
|
|
37522
|
+
if (typeof next !== "string" || !next) { toolsPaging = { complete: true, pages }; return; }
|
|
37523
|
+
if (pages >= TOOLS_PAGE_CAP) {
|
|
37524
|
+
toolsPaging = { complete: false, pages, unreadCursor: next, reason: "the tools/list page cap (" + TOOLS_PAGE_CAP + " pages) was reached with a cursor still served" };
|
|
37525
|
+
return;
|
|
37526
|
+
}
|
|
37527
|
+
toolsPaging = { complete: false, pages, unreadCursor: next, reason: "tools/list page " + (pages + 1) + " got no answer" };
|
|
37528
|
+
followToolsPage(next);
|
|
37529
|
+
};
|
|
37530
|
+
// One tools/call answer read into its S-51 record (the record keeps only its tool name before it is filled).
|
|
37531
|
+
const fillToolCall = (rec, msg) => {
|
|
37532
|
+
const name = rec.tool;
|
|
37533
|
+
for (const k of Object.keys(rec)) delete rec[k];
|
|
37534
|
+
rec.tool = name;
|
|
37535
|
+
if (msg.error && typeof msg.error === "object") {
|
|
37536
|
+
Object.assign(rec, { kind: "error", code: msg.error.code, ...(typeof msg.error.message === "string" ? { message: msg.error.message } : {}) });
|
|
37537
|
+
} else if (msg.result && typeof msg.result === "object" && !Array.isArray(msg.result)) {
|
|
37538
|
+
const r = msg.result;
|
|
37539
|
+
const CAP = 65536;
|
|
37540
|
+
const block = (b) => {
|
|
37541
|
+
if (!b || typeof b !== "object") return { type: "<" + (b === null ? "null" : typeof b) + ">" };
|
|
37542
|
+
const out = { type: typeof b.type === "string" ? b.type : "<no type>" };
|
|
37543
|
+
if (typeof b.text === "string") { out.text = b.text.slice(0, CAP); if (b.text.length > CAP) out.truncated = true; }
|
|
37544
|
+
return out;
|
|
37545
|
+
};
|
|
37546
|
+
Object.assign(rec, {
|
|
37547
|
+
kind: "result",
|
|
37548
|
+
isError: r.isError === true,
|
|
37549
|
+
hasStructured: Object.prototype.hasOwnProperty.call(r, "structuredContent"),
|
|
37550
|
+
...(r.structuredContent !== undefined ? { structuredContent: r.structuredContent } : {}),
|
|
37551
|
+
contentKind: Array.isArray(r.content) ? "array" : r.content === undefined ? "absent" : "other",
|
|
37552
|
+
content: Array.isArray(r.content) ? r.content.map(block) : [],
|
|
37553
|
+
});
|
|
37554
|
+
} else {
|
|
37555
|
+
Object.assign(rec, { kind: "no-answer", reason: "an answer with neither result nor error" });
|
|
37556
|
+
}
|
|
37557
|
+
};
|
|
35365
37558
|
const onMessage = (msg) => {
|
|
35366
37559
|
// A request or notification FROM the server carries a method: it is not an answer.
|
|
35367
37560
|
if (msg.method !== undefined) return;
|
|
@@ -35424,13 +37617,17 @@ const onMessage = (msg) => {
|
|
|
35424
37617
|
const props = schemaOf(t).properties;
|
|
35425
37618
|
return Boolean(props && typeof props === "object" && Object.prototype.hasOwnProperty.call(props, "cursor"));
|
|
35426
37619
|
};
|
|
35427
|
-
|
|
37620
|
+
const toolRecord = (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, outputSchema: t && t.outputSchema && typeof t.outputSchema === "object" && !Array.isArray(t.outputSchema) ? t.outputSchema : undefined, title: t && typeof t.title === "string" ? t.title : undefined, annotations: t && t.annotations && typeof t.annotations === "object" && !Array.isArray(t.annotations) ? { readOnlyHint: t.annotations.readOnlyHint, destructiveHint: t.annotations.destructiveHint, idempotentHint: t.annotations.idempotentHint, openWorldHint: t.annotations.openWorldHint, title: t.annotations.title } : undefined, ...(t && t._meta !== undefined ? { meta: t._meta } : {}) });
|
|
37621
|
+
tools = served.map(toolRecord);
|
|
35428
37622
|
const methods = ["tools/list"];
|
|
35429
37623
|
if (capabilities.resources) methods.push("resources/list", "resources/templates/list");
|
|
35430
37624
|
if (capabilities.prompts) methods.push("prompts/list");
|
|
35431
37625
|
const first = listRecord("tools/list", msg);
|
|
35432
37626
|
lists.push(first);
|
|
35433
|
-
if (first.outcome === "answered" && typeof first.nextCursor === "string" && first.nextCursor)
|
|
37627
|
+
if (first.outcome === "answered" && typeof first.nextCursor === "string" && first.nextCursor) {
|
|
37628
|
+
toolsPaging = { complete: false, pages: 1, unreadCursor: first.nextCursor, reason: "tools/list page 2 got no answer" };
|
|
37629
|
+
followCursor(first);
|
|
37630
|
+
}
|
|
35434
37631
|
// The other declared list methods, asked for their first page: S-3 / S-12 read what they serve.
|
|
35435
37632
|
for (const m of methods.slice(1)) {
|
|
35436
37633
|
const lid = nextId++;
|
|
@@ -35439,13 +37636,33 @@ const onMessage = (msg) => {
|
|
|
35439
37636
|
listPending.set(lid, rec);
|
|
35440
37637
|
send({ jsonrpc: "2.0", id: lid, method: m, params: {} });
|
|
35441
37638
|
}
|
|
37639
|
+
// One S-51 record per tool of a page; skip is the S-2 tool of page 1, whose record that call fills.
|
|
37640
|
+
const recordCalls = (page, skip) => {
|
|
37641
|
+
for (const t of page) {
|
|
37642
|
+
const name = String(t && t.name);
|
|
37643
|
+
const gate = callability(t, []);
|
|
37644
|
+
if (!gate.callable) { toolCalls.push({ tool: name, kind: "not-sent", reason: gate.reason }); continue; }
|
|
37645
|
+
const rec = { tool: name, kind: "no-answer", reason: "pending" };
|
|
37646
|
+
toolCalls.push(rec);
|
|
37647
|
+
if (t === skip) continue;
|
|
37648
|
+
const cid = nextId++;
|
|
37649
|
+
callPending.set(cid, rec);
|
|
37650
|
+
send({ jsonrpc: "2.0", id: cid, method: "tools/call", params: { name: t.name, arguments: {} } });
|
|
37651
|
+
}
|
|
37652
|
+
};
|
|
37653
|
+
// The first callable tool is the S-2 call below, which fills this record from its own answer.
|
|
37654
|
+
recordCalls(served, served.find((x) => callability(x, []).callable));
|
|
37655
|
+
// A later tools/list page: its tools join tools and get their S-51 records through the same callability() rule.
|
|
37656
|
+
// Declared divergence: the C-11 cursor-argument probe below reads page 1's tools only.
|
|
37657
|
+
ingestTools = (page) => { for (const t of page) tools.push(toolRecord(t)); recordCalls(page, undefined); };
|
|
35442
37658
|
// S-2 is verified "on the response returned" to a tool call: ONE tool that callability() admits
|
|
35443
|
-
// with no argument supplied is called with {}; only the KEYS of
|
|
35444
|
-
//
|
|
37659
|
+
// with no argument supplied is called with {}; its S-2 record keeps only the KEYS of the result. The same answer
|
|
37660
|
+
// fills that tool's S-51 record (toolCalls, above), so the tool is called once. No such tool: no call is invented.
|
|
35445
37661
|
const safe = served.find((t) => callability(t, []).callable);
|
|
35446
37662
|
if (safe) {
|
|
35447
37663
|
const cid = nextId++;
|
|
35448
|
-
|
|
37664
|
+
// The S-51 record of this same tool reads this same answer: the tool is called once, never twice.
|
|
37665
|
+
const rec = { method: "tools/call " + String(safe.name), alsoTool: toolCalls.find((c) => c.tool === String(safe.name) && c.kind === "no-answer") };
|
|
35449
37666
|
calls.push(rec);
|
|
35450
37667
|
listPending.set(cid, rec);
|
|
35451
37668
|
send({ jsonrpc: "2.0", id: cid, method: "tools/call", params: { name: safe.name, arguments: {} } });
|
|
@@ -35463,12 +37680,20 @@ const onMessage = (msg) => {
|
|
|
35463
37680
|
}
|
|
35464
37681
|
if (outstanding() === 0) { finish("no probe pending"); return; }
|
|
35465
37682
|
probeTimer = setTimeout(() => finish("no answer within the 5 s probe deadline"), 5000);
|
|
37683
|
+
} else if (callPending.has(msg.id)) {
|
|
37684
|
+
const rec = callPending.get(msg.id); callPending.delete(msg.id);
|
|
37685
|
+
fillToolCall(rec, msg);
|
|
37686
|
+
if (outstanding() === 0) finish("no probe pending");
|
|
35466
37687
|
} else if (listPending.has(msg.id)) {
|
|
35467
37688
|
const rec = listPending.get(msg.id); listPending.delete(msg.id);
|
|
35468
|
-
if (rec.
|
|
37689
|
+
if (rec.toolsPageOf !== undefined) {
|
|
37690
|
+
onToolsPage(rec.toolsPageOf, listRecord(rec.method, msg), msg);
|
|
37691
|
+
} else if (rec.followUpOf) {
|
|
35469
37692
|
const got = listRecord(rec.method, msg);
|
|
35470
37693
|
rec.followUpOf.followUp = { outcome: got.outcome, detail: got.detail, entries: got.entries };
|
|
37694
|
+
if (rec.method === "tools/list" && rec.followUpOf.method === "tools/list") onToolsPage(rec.followUpOf.nextCursor, got, msg);
|
|
35471
37695
|
} else {
|
|
37696
|
+
if (rec.alsoTool) { fillToolCall(rec.alsoTool, msg); delete rec.alsoTool; }
|
|
35472
37697
|
Object.assign(rec, listRecord(rec.method, msg));
|
|
35473
37698
|
if (rec.outcome === "answered" && typeof rec.nextCursor === "string" && rec.nextCursor) followCursor(rec);
|
|
35474
37699
|
}
|
|
@@ -35490,17 +37715,17 @@ const onMessage = (msg) => {
|
|
|
35490
37715
|
transport = plan.kind === "http" ? makeHttpTransport() : makeStdioTransport();
|
|
35491
37716
|
if (transport) send({ jsonrpc: "2.0", id: 1, method: "initialize", params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "mcp-doctor", version: "0" } } });
|
|
35492
37717
|
`;
|
|
35493
|
-
var
|
|
37718
|
+
var isObj6 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
35494
37719
|
var outcomeOf = (v) => v === "answered" || v === "refused" ? v : "no-answer";
|
|
35495
37720
|
function readServed(raw) {
|
|
35496
|
-
if (!
|
|
37721
|
+
if (!isObj6(raw)) return void 0;
|
|
35497
37722
|
const readList = (l) => {
|
|
35498
|
-
const r =
|
|
37723
|
+
const r = isObj6(l) ? l : {};
|
|
35499
37724
|
const method = typeof r.method === "string" ? r.method : "<unnamed list>";
|
|
35500
|
-
const fu =
|
|
37725
|
+
const fu = isObj6(r.followUp) ? r.followUp : void 0;
|
|
35501
37726
|
return {
|
|
35502
37727
|
method,
|
|
35503
|
-
outcome:
|
|
37728
|
+
outcome: isObj6(l) ? outcomeOf(r.outcome) : "no-answer",
|
|
35504
37729
|
...typeof r.detail === "string" ? { detail: r.detail } : {},
|
|
35505
37730
|
...Array.isArray(r.resultKeys) ? { resultKeys: r.resultKeys.map(String) } : {},
|
|
35506
37731
|
...r.resultType !== void 0 ? { resultType: r.resultType } : {},
|
|
@@ -35519,35 +37744,37 @@ function readServed(raw) {
|
|
|
35519
37744
|
};
|
|
35520
37745
|
const lists = (Array.isArray(raw.lists) ? raw.lists : []).map(readList);
|
|
35521
37746
|
const vp = raw.versionProbe;
|
|
35522
|
-
const versionProbe =
|
|
37747
|
+
const versionProbe = isObj6(vp) && vp.kind === "statuses" && typeof vp.supportedVersion === "string" && typeof vp.supported === "number" && typeof vp.unsupported === "number" ? {
|
|
35523
37748
|
kind: "statuses",
|
|
35524
37749
|
supportedVersion: vp.supportedVersion,
|
|
35525
37750
|
supported: vp.supported,
|
|
35526
37751
|
unsupported: vp.unsupported
|
|
35527
37752
|
} : {
|
|
35528
37753
|
kind: "not-run",
|
|
35529
|
-
reason:
|
|
37754
|
+
reason: isObj6(vp) && vp.kind === "not-run" && typeof vp.reason === "string" ? vp.reason : "unreadable version-probe record"
|
|
35530
37755
|
};
|
|
35531
37756
|
const as = raw.authServer;
|
|
35532
|
-
const authServer =
|
|
37757
|
+
const authServer = isObj6(as) && as.kind === "document" && typeof as.url === "string" && typeof as.status === "number" && isObj6(as.document) ? { kind: "document", url: as.url, status: as.status, document: as.document } : isObj6(as) && as.kind === "unavailable" && typeof as.url === "string" ? {
|
|
35533
37758
|
kind: "unavailable",
|
|
35534
37759
|
url: as.url,
|
|
35535
37760
|
reason: typeof as.reason === "string" ? as.reason : "no reason given"
|
|
35536
37761
|
} : {
|
|
35537
37762
|
kind: "not-run",
|
|
35538
|
-
reason:
|
|
37763
|
+
reason: isObj6(as) && as.kind === "not-run" && typeof as.reason === "string" ? as.reason : "unreadable authorization-server record"
|
|
35539
37764
|
};
|
|
35540
37765
|
const authorize = readAuthorize(raw.authorize);
|
|
35541
|
-
const
|
|
37766
|
+
const authDocs = readAuthDocs(raw.authDocs);
|
|
37767
|
+
const init = isObj6(raw.initialize) ? raw.initialize : void 0;
|
|
35542
37768
|
const discovery = readDiscovery(raw.discovery);
|
|
35543
37769
|
return {
|
|
35544
|
-
capabilities:
|
|
37770
|
+
capabilities: isObj6(raw.capabilities) ? raw.capabilities : {},
|
|
35545
37771
|
...typeof raw.protocolVersion === "string" ? { protocolVersion: raw.protocolVersion } : {},
|
|
35546
37772
|
lists,
|
|
35547
37773
|
calls: (Array.isArray(raw.calls) ? raw.calls : []).map(readList),
|
|
35548
37774
|
versionProbe,
|
|
35549
37775
|
authServer,
|
|
35550
37776
|
...authorize ? { authorize } : {},
|
|
37777
|
+
...authDocs ? { authDocs } : {},
|
|
35551
37778
|
...init ? {
|
|
35552
37779
|
initialize: {
|
|
35553
37780
|
resultKeys: Array.isArray(init.resultKeys) ? init.resultKeys.map(String) : [],
|
|
@@ -35555,43 +37782,106 @@ function readServed(raw) {
|
|
|
35555
37782
|
}
|
|
35556
37783
|
} : {},
|
|
35557
37784
|
...raw.toolMetaRecorded === true ? { toolMetaRecorded: true } : {},
|
|
35558
|
-
...discovery ? { discovery } : {}
|
|
37785
|
+
...discovery ? { discovery } : {},
|
|
37786
|
+
...Array.isArray(raw.toolCalls) ? { toolCalls: raw.toolCalls.map(readToolCall) } : {},
|
|
37787
|
+
...isObj6(raw.toolsPaging) ? { toolsPaging: readToolsPaging(raw.toolsPaging) } : {}
|
|
35559
37788
|
};
|
|
35560
37789
|
}
|
|
35561
|
-
function
|
|
37790
|
+
function readToolsPaging(r) {
|
|
37791
|
+
const pages = typeof r.pages === "number" ? r.pages : 0;
|
|
37792
|
+
if (r.complete === true) return { complete: true, pages };
|
|
37793
|
+
return {
|
|
37794
|
+
complete: false,
|
|
37795
|
+
pages,
|
|
37796
|
+
...r.unreadCursor !== void 0 ? { unreadCursor: r.unreadCursor } : {},
|
|
37797
|
+
reason: typeof r.reason === "string" ? r.reason : "the paging record names no reason"
|
|
37798
|
+
};
|
|
37799
|
+
}
|
|
37800
|
+
function readToolCall(raw) {
|
|
37801
|
+
const r = isObj6(raw) ? raw : {};
|
|
37802
|
+
const tool = typeof r.tool === "string" ? r.tool : "<unnamed tool>";
|
|
37803
|
+
const reason = typeof r.reason === "string" ? r.reason : "no reason recorded";
|
|
37804
|
+
if (r.kind === "not-sent") return { tool, kind: "not-sent", reason };
|
|
37805
|
+
if (r.kind === "error")
|
|
37806
|
+
return {
|
|
37807
|
+
tool,
|
|
37808
|
+
kind: "error",
|
|
37809
|
+
code: r.code,
|
|
37810
|
+
...typeof r.message === "string" ? { message: r.message } : {}
|
|
37811
|
+
};
|
|
37812
|
+
if (r.kind === "result" && typeof r.hasStructured === "boolean" && Array.isArray(r.content)) {
|
|
37813
|
+
const contentKind = r.contentKind === "array" || r.contentKind === "absent" || r.contentKind === "other" ? r.contentKind : "other";
|
|
37814
|
+
return {
|
|
37815
|
+
tool,
|
|
37816
|
+
kind: "result",
|
|
37817
|
+
isError: r.isError === true,
|
|
37818
|
+
hasStructured: r.hasStructured,
|
|
37819
|
+
...r.structuredContent !== void 0 ? { structuredContent: r.structuredContent } : {},
|
|
37820
|
+
contentKind,
|
|
37821
|
+
content: r.content.filter(isObj6).map((b) => ({
|
|
37822
|
+
type: typeof b.type === "string" ? b.type : "<no type>",
|
|
37823
|
+
...typeof b.text === "string" ? { text: b.text } : {},
|
|
37824
|
+
...b.truncated === true ? { truncated: true } : {}
|
|
37825
|
+
}))
|
|
37826
|
+
};
|
|
37827
|
+
}
|
|
37828
|
+
if (r.kind === "no-answer") return { tool, kind: "no-answer", reason };
|
|
37829
|
+
return { tool, kind: "no-answer", reason: "unreadable tool-call record" };
|
|
37830
|
+
}
|
|
37831
|
+
function readGet(g) {
|
|
37832
|
+
const r = isObj6(g) ? g : {};
|
|
37833
|
+
return {
|
|
37834
|
+
url: typeof r.url === "string" ? r.url : "<unnamed url>",
|
|
37835
|
+
...typeof r.status === "number" ? { status: r.status } : {},
|
|
37836
|
+
...typeof r.contentType === "string" ? { contentType: r.contentType } : {},
|
|
37837
|
+
...isObj6(r.json) ? { json: r.json } : {},
|
|
37838
|
+
...typeof r.text === "string" ? { text: r.text } : {},
|
|
37839
|
+
...typeof r.detail === "string" ? { detail: r.detail } : isObj6(g) ? {} : { detail: "unreadable GET record" }
|
|
37840
|
+
};
|
|
37841
|
+
}
|
|
37842
|
+
function readAuthDocs(raw) {
|
|
35562
37843
|
if (raw === void 0) return void 0;
|
|
35563
|
-
|
|
35564
|
-
const
|
|
37844
|
+
if (isObj6(raw) && raw.kind === "probed" && typeof raw.mcpUrl === "string" && isObj6(raw.prm) && isObj6(raw.prm.bare)) {
|
|
37845
|
+
const oidc = isObj6(raw.oidc) && typeof raw.oidc.skipped === "string" ? { skipped: raw.oidc.skipped } : readGet(raw.oidc);
|
|
35565
37846
|
return {
|
|
35566
|
-
|
|
35567
|
-
|
|
35568
|
-
|
|
35569
|
-
|
|
35570
|
-
|
|
35571
|
-
|
|
37847
|
+
kind: "probed",
|
|
37848
|
+
mcpUrl: raw.mcpUrl,
|
|
37849
|
+
prm: {
|
|
37850
|
+
...raw.prm.suffixed !== void 0 ? { suffixed: readGet(raw.prm.suffixed) } : {},
|
|
37851
|
+
bare: readGet(raw.prm.bare)
|
|
37852
|
+
},
|
|
37853
|
+
oidc
|
|
35572
37854
|
};
|
|
37855
|
+
}
|
|
37856
|
+
return {
|
|
37857
|
+
kind: "not-run",
|
|
37858
|
+
reason: isObj6(raw) && raw.kind === "not-run" && typeof raw.reason === "string" ? raw.reason : "unreadable protected-resource record"
|
|
35573
37859
|
};
|
|
35574
|
-
|
|
37860
|
+
}
|
|
37861
|
+
function readDiscovery(raw) {
|
|
37862
|
+
if (raw === void 0) return void 0;
|
|
37863
|
+
const get = readGet;
|
|
37864
|
+
if (isObj6(raw) && raw.kind === "probed" && Array.isArray(raw.cards) && isObj6(raw.landing))
|
|
35575
37865
|
return { kind: "probed", cards: raw.cards.map(get), landing: get(raw.landing) };
|
|
35576
37866
|
return {
|
|
35577
37867
|
kind: "not-run",
|
|
35578
|
-
reason:
|
|
37868
|
+
reason: isObj6(raw) && raw.kind === "not-run" && typeof raw.reason === "string" ? raw.reason : "unreadable discovery record"
|
|
35579
37869
|
};
|
|
35580
37870
|
}
|
|
35581
37871
|
function readAuthorize(raw) {
|
|
35582
|
-
if (!
|
|
37872
|
+
if (!isObj6(raw)) return void 0;
|
|
35583
37873
|
if (raw.kind !== "probed" || !Array.isArray(raw.clients))
|
|
35584
37874
|
return {
|
|
35585
37875
|
kind: "not-run",
|
|
35586
37876
|
reason: typeof raw.reason === "string" ? raw.reason : "unreadable sign-in probe record"
|
|
35587
37877
|
};
|
|
35588
37878
|
const str = (v) => typeof v === "string" ? v : void 0;
|
|
35589
|
-
const clients = raw.clients.filter(
|
|
37879
|
+
const clients = raw.clients.filter(isObj6).map((c) => {
|
|
35590
37880
|
const host = str(c.host) ?? "<unnamed host>";
|
|
35591
37881
|
const clientId = str(c.clientId) ?? "<unnamed client>";
|
|
35592
37882
|
if (c.kind !== "probed" || !Array.isArray(c.attempts))
|
|
35593
37883
|
return { host, clientId, kind: "unavailable", reason: str(c.reason) ?? "no reason given" };
|
|
35594
|
-
const attempts = c.attempts.filter(
|
|
37884
|
+
const attempts = c.attempts.filter(isObj6).map((a) => ({
|
|
35595
37885
|
redirect: str(a.redirect) ?? "<unnamed redirect>",
|
|
35596
37886
|
...typeof a.status === "number" ? { status: a.status } : {},
|
|
35597
37887
|
...str(a.location) ? { location: str(a.location) } : {},
|
|
@@ -35608,14 +37898,14 @@ function readEvalCounts(target) {
|
|
|
35608
37898
|
if (!pkgDir) return { counts };
|
|
35609
37899
|
let dir = pkgDir;
|
|
35610
37900
|
for (let depth = 0; depth < 8; depth++) {
|
|
35611
|
-
const candidate =
|
|
37901
|
+
const candidate = join36(dir, "evals", "evals.json");
|
|
35612
37902
|
if (existsSync23(candidate)) {
|
|
35613
37903
|
let text;
|
|
35614
37904
|
try {
|
|
35615
|
-
if (!
|
|
37905
|
+
if (!statSync25(candidate).isFile()) {
|
|
35616
37906
|
return { counts, unreadable: `${candidate} is not a regular file \u2014 not read` };
|
|
35617
37907
|
}
|
|
35618
|
-
text =
|
|
37908
|
+
text = readFileSync26(candidate, "utf8");
|
|
35619
37909
|
} catch (err) {
|
|
35620
37910
|
return {
|
|
35621
37911
|
counts,
|
|
@@ -35639,7 +37929,7 @@ function readEvalCounts(target) {
|
|
|
35639
37929
|
}
|
|
35640
37930
|
function statSyncSafe(p) {
|
|
35641
37931
|
try {
|
|
35642
|
-
return
|
|
37932
|
+
return statSync25(p).isDirectory();
|
|
35643
37933
|
} catch {
|
|
35644
37934
|
return false;
|
|
35645
37935
|
}
|
|
@@ -35776,7 +38066,7 @@ function introspect(plan, root, evalSource, expectedCommit, evalsNote, secrets)
|
|
|
35776
38066
|
};
|
|
35777
38067
|
}
|
|
35778
38068
|
if (parsed.launchError) {
|
|
35779
|
-
const pub =
|
|
38069
|
+
const pub = isObj6(parsed.publicAuth) ? readServed(parsed.publicAuth) : void 0;
|
|
35780
38070
|
return {
|
|
35781
38071
|
root,
|
|
35782
38072
|
tools: [],
|
|
@@ -35785,6 +38075,7 @@ function introspect(plan, root, evalSource, expectedCommit, evalsNote, secrets)
|
|
|
35785
38075
|
publicAuth: {
|
|
35786
38076
|
authServer: pub.authServer,
|
|
35787
38077
|
...pub.authorize ? { authorize: pub.authorize } : {},
|
|
38078
|
+
...pub.authDocs ? { authDocs: pub.authDocs } : {},
|
|
35788
38079
|
...pub.discovery ? { discovery: pub.discovery } : {}
|
|
35789
38080
|
}
|
|
35790
38081
|
} : {}
|
|
@@ -35865,7 +38156,7 @@ function isLiveDetector(d) {
|
|
|
35865
38156
|
}
|
|
35866
38157
|
|
|
35867
38158
|
// src/urlArgs.ts
|
|
35868
|
-
import { statSync as
|
|
38159
|
+
import { statSync as statSync26 } from "fs";
|
|
35869
38160
|
var VALUE_OPTIONS2 = [
|
|
35870
38161
|
"--url",
|
|
35871
38162
|
"--header",
|
|
@@ -35983,7 +38274,7 @@ function parseUrlArgs(args, env) {
|
|
|
35983
38274
|
const src = values["--source"][0];
|
|
35984
38275
|
let isDir2 = false;
|
|
35985
38276
|
try {
|
|
35986
|
-
isDir2 =
|
|
38277
|
+
isDir2 = statSync26(src).isDirectory();
|
|
35987
38278
|
} catch {
|
|
35988
38279
|
isDir2 = false;
|
|
35989
38280
|
}
|
|
@@ -36004,7 +38295,7 @@ function parseUrlArgs(args, env) {
|
|
|
36004
38295
|
}
|
|
36005
38296
|
|
|
36006
38297
|
// src/kit/rule-ids.ts
|
|
36007
|
-
import { readFileSync as
|
|
38298
|
+
import { readFileSync as readFileSync27 } from "fs";
|
|
36008
38299
|
var StandardUnreadableError = class extends Error {
|
|
36009
38300
|
constructor(path, cause) {
|
|
36010
38301
|
super(
|
|
@@ -36044,7 +38335,7 @@ function stateless(pattern) {
|
|
|
36044
38335
|
function deriveRuleIds(path, pattern) {
|
|
36045
38336
|
let blob;
|
|
36046
38337
|
try {
|
|
36047
|
-
blob =
|
|
38338
|
+
blob = readFileSync27(path, "utf8");
|
|
36048
38339
|
} catch (e) {
|
|
36049
38340
|
throw new StandardUnreadableError(path, e);
|
|
36050
38341
|
}
|
|
@@ -36505,11 +38796,11 @@ function renderJson(surface, results, skipped, coverage, gate) {
|
|
|
36505
38796
|
function renderResults(surface, results, coverageLine) {
|
|
36506
38797
|
const cols = { item: 24, anchor: 26, state: 15 };
|
|
36507
38798
|
const header = `${pad("item", cols.item)} | ${pad("file:line", cols.anchor)} | ${pad("state", cols.state)} | verdict`;
|
|
36508
|
-
const
|
|
38799
|
+
const sep8 = "-".repeat(header.length);
|
|
36509
38800
|
const rows = results.map(
|
|
36510
38801
|
(r) => `${pad(r.id, cols.item)} | ${pad(r.anchor, cols.anchor)} | ${pad(r.state, cols.state)} | ${r.verdict}`
|
|
36511
38802
|
);
|
|
36512
|
-
const table = [`surface: ${surface}`, coverageLine, header,
|
|
38803
|
+
const table = [`surface: ${surface}`, coverageLine, header, sep8, ...rows].join("\n");
|
|
36513
38804
|
const unjudged = results.filter((r) => r.state === "could-not-judge");
|
|
36514
38805
|
if (unjudged.length === 0) return table;
|
|
36515
38806
|
const cnjHeader = `could-not-judge (${unjudged.length}) \u2014 the doctor could NOT read these; this is NOT a clean bill:`;
|
|
@@ -36592,7 +38883,7 @@ var USAGE = [
|
|
|
36592
38883
|
function readVersion() {
|
|
36593
38884
|
try {
|
|
36594
38885
|
const here = dirname19(fileURLToPath2(import.meta.url));
|
|
36595
|
-
const manifest = JSON.parse(
|
|
38886
|
+
const manifest = JSON.parse(readFileSync28(join37(here, "..", "package.json"), "utf8"));
|
|
36596
38887
|
return manifest.version ?? null;
|
|
36597
38888
|
} catch {
|
|
36598
38889
|
return null;
|
|
@@ -36660,10 +38951,10 @@ function runEventsMode(endpoint, rest, options) {
|
|
|
36660
38951
|
}
|
|
36661
38952
|
function defaultOwedPath(target) {
|
|
36662
38953
|
try {
|
|
36663
|
-
if (
|
|
38954
|
+
if (statSync27(target).isFile()) return join37(dirname19(target), OWED_FILE_NAME);
|
|
36664
38955
|
} catch {
|
|
36665
38956
|
}
|
|
36666
|
-
return
|
|
38957
|
+
return join37(target, OWED_FILE_NAME);
|
|
36667
38958
|
}
|
|
36668
38959
|
function main() {
|
|
36669
38960
|
const argv = process.argv.slice(2);
|