@vantageos/mcp-doctor 0.23.0 → 0.25.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/dist/doctor.js CHANGED
@@ -1,8 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
+ dotted,
3
4
  isJudgeable,
5
+ lineOf,
4
6
  parseFile,
5
- scanR4FilterPaths
7
+ propRead,
8
+ scanR4FilterPaths,
9
+ sourceOf,
10
+ unwrap,
11
+ walk
6
12
  } from "./chunk-OLW7SIJF.js";
7
13
 
8
14
  // src/doctor.ts
@@ -51,7 +57,7 @@ function isCommentLine(raw) {
51
57
  }
52
58
  var UNSCANNED_RE = /\.(?:m?js|cjs|jsx|mts|cts)$/;
53
59
  var NOT_PRODUCT_NAME_RE = /\.d\.[mc]?ts$|\.(?:test|spec)\.[mc]?[jt]sx?$|\.config\.[mc]?[jt]s$|\.min\./;
54
- function walk(dir, out, onSkip, unscanned = [], seen = { files: 0 }) {
60
+ function walk2(dir, out, onSkip, unscanned = [], seen = { files: 0 }) {
55
61
  let entries;
56
62
  try {
57
63
  entries = readdirSync(dir);
@@ -73,7 +79,7 @@ function walk(dir, out, onSkip, unscanned = [], seen = { files: 0 }) {
73
79
  onSkip(full);
74
80
  continue;
75
81
  }
76
- walk(full, out, onSkip, unscanned, seen);
82
+ walk2(full, out, onSkip, unscanned, seen);
77
83
  continue;
78
84
  }
79
85
  if (!st.isFile()) {
@@ -190,7 +196,7 @@ function loadTree(root, backendRoot) {
190
196
  throw new SubjectUnreadableError(root, "the directory is empty (0 entries)");
191
197
  }
192
198
  const seen = { files: 0 };
193
- walk(root, filePaths, (d, reason) => recordSkip(tree, d, root, reason), unscanned, seen);
199
+ walk2(root, filePaths, (d, reason) => recordSkip(tree, d, root, reason), unscanned, seen);
194
200
  for (const p of filePaths) {
195
201
  try {
196
202
  tree.files.push(loadFile(p, baseDir));
@@ -654,7 +660,7 @@ function findDiskFiles(tree, pred) {
654
660
  const out = [];
655
661
  const refused = [];
656
662
  const base = baseOf(tree);
657
- const walk3 = (dir) => {
663
+ const walk4 = (dir) => {
658
664
  let entries;
659
665
  try {
660
666
  entries = readdirSync2(dir);
@@ -679,7 +685,7 @@ function findDiskFiles(tree, pred) {
679
685
  recordSkip(tree, full, base);
680
686
  continue;
681
687
  }
682
- walk3(full);
688
+ walk4(full);
683
689
  } else {
684
690
  const rel2 = relative2(base, full).split(sep2).join("/");
685
691
  if (!pred(name, rel2)) continue;
@@ -701,7 +707,7 @@ function findDiskFiles(tree, pred) {
701
707
  }
702
708
  }
703
709
  };
704
- walk3(base);
710
+ walk4(base);
705
711
  return Object.assign(out, { refused });
706
712
  }
707
713
  function readText(path) {
@@ -1961,6 +1967,38 @@ function splitArgs(text, open, max = Number.POSITIVE_INFINITY) {
1961
1967
  }
1962
1968
  return null;
1963
1969
  }
1970
+ function parameterBehindLocal(body, local, paramNames, nameParam) {
1971
+ const decl = new RegExp(`\\bconst\\s+${local.replace(/\$/g, "\\$")}\\s*(?::[^=\\n]+)?=(?!=)`);
1972
+ const m = body.match(decl);
1973
+ if (!m || m.index === void 0) return -1;
1974
+ const start = m.index + m[0].length;
1975
+ let depth = 0;
1976
+ let end = body.length;
1977
+ for (let i = start; i < body.length; i++) {
1978
+ const c = body[i];
1979
+ if (c === '"' || c === "'" || c === "`") {
1980
+ for (i++; i < body.length && body[i] !== c; i++) if (body[i] === "\\") i++;
1981
+ continue;
1982
+ }
1983
+ if ("([{".includes(c)) depth++;
1984
+ else if (")]}".includes(c)) depth--;
1985
+ else if (c === ";" && depth <= 0) {
1986
+ end = i;
1987
+ break;
1988
+ }
1989
+ if (depth < 0) {
1990
+ end = i;
1991
+ break;
1992
+ }
1993
+ }
1994
+ const init = body.slice(start, end);
1995
+ const read = [];
1996
+ paramNames.forEach((p, k) => {
1997
+ if (p && p !== nameParam && new RegExp(`(?<![\\w$.])${p.replace(/\$/g, "\\$")}(?![\\w$])`).test(init))
1998
+ read.push(k);
1999
+ });
2000
+ return read.length === 1 ? read[0] : -1;
2001
+ }
1964
2002
  function scanWrappers(tree) {
1965
2003
  const cached = wrapperScans.get(tree);
1966
2004
  if (cached) return cached;
@@ -1980,7 +2018,7 @@ function scanWrappers(tree) {
1980
2018
  lineStart.push(off);
1981
2019
  off += l.raw.length + 1;
1982
2020
  }
1983
- const lineOf5 = (idx) => {
2021
+ const lineOf6 = (idx) => {
1984
2022
  let lo = 0;
1985
2023
  let hi = lineStart.length - 1;
1986
2024
  while (lo < hi) {
@@ -2031,12 +2069,13 @@ function scanWrappers(tree) {
2031
2069
  const k = paramNames.indexOf(c[1]);
2032
2070
  if (k < 0) continue;
2033
2071
  idxs.add(k);
2034
- scan.internal.add(`${file.rel}:${lineOf5(bodyOpen + (c.index ?? 0))}`);
2072
+ scan.internal.add(`${file.rel}:${lineOf6(bodyOpen + (c.index ?? 0))}`);
2035
2073
  const after = body.slice((c.index ?? 0) + c[0].length, (c.index ?? 0) + c[0].length + 3e3);
2036
2074
  const dm = after.match(/(?:^|[\s{,])description\b\s*(?::\s*([A-Za-z_$][\w$]*))?\s*[,}]/);
2037
2075
  if (dm) {
2038
2076
  const ref = dm[1] ?? "description";
2039
2077
  descIdx = paramNames.indexOf(ref);
2078
+ if (descIdx < 0) descIdx = parameterBehindLocal(body, ref, paramNames, c[1]);
2040
2079
  }
2041
2080
  }
2042
2081
  if (idxs.size !== 1) return;
@@ -2046,7 +2085,7 @@ function scanWrappers(tree) {
2046
2085
  descIdx,
2047
2086
  file,
2048
2087
  declLine: line.n,
2049
- endLine: lineOf5(bodyEnd)
2088
+ endLine: lineOf6(bodyEnd)
2050
2089
  });
2051
2090
  });
2052
2091
  }
@@ -2787,7 +2826,7 @@ function governingWorkflows(tree) {
2787
2826
  }
2788
2827
  return [];
2789
2828
  }
2790
- function lineOf(text, re) {
2829
+ function lineOf2(text, re) {
2791
2830
  const m = re.exec(text);
2792
2831
  if (!m) return 1;
2793
2832
  return text.slice(0, m.index).split("\n").length;
@@ -3148,7 +3187,7 @@ function collect(base) {
3148
3187
  const out = [];
3149
3188
  const unmeasured = [];
3150
3189
  const relOf = (full) => relative3(base, full).split(sep3).join("/");
3151
- const walk3 = (dir, depth) => {
3190
+ const walk4 = (dir, depth) => {
3152
3191
  if (depth > 8) {
3153
3192
  unmeasured.push(`${relOf(dir)}/ (deeper than 8 levels, not walked)`);
3154
3193
  return;
@@ -3172,7 +3211,7 @@ function collect(base) {
3172
3211
  continue;
3173
3212
  }
3174
3213
  if (st.isDirectory()) {
3175
- if (!WALK_SKIP.has(name)) walk3(full, depth + 1);
3214
+ if (!WALK_SKIP.has(name)) walk4(full, depth + 1);
3176
3215
  } else if (candidate) {
3177
3216
  if (!st.isFile()) {
3178
3217
  unmeasured.push(`${rel2} (not a regular file, not read)`);
@@ -3190,7 +3229,7 @@ function collect(base) {
3190
3229
  }
3191
3230
  }
3192
3231
  };
3193
- walk3(base, 0);
3232
+ walk4(base, 0);
3194
3233
  return { bundles: out, unmeasured };
3195
3234
  }
3196
3235
  var kb = (n) => `${(n / 1024).toFixed(1)} KB gz`;
@@ -6659,16 +6698,16 @@ function hostToolProblems(tree) {
6659
6698
  const unresolvedSites = findUnresolvedToolSites(tree);
6660
6699
  const named = [];
6661
6700
  for (const c of caps) {
6662
- for (const ts6 of TOOL_SETTINGS) {
6663
- if (c.key !== ts6.cap) continue;
6701
+ for (const ts9 of TOOL_SETTINGS) {
6702
+ if (c.key !== ts9.cap) continue;
6664
6703
  const m = c.body.match(
6665
- new RegExp(`["'\`]?${ts6.setting}["'\`]?\\s*:\\s*["'\`]([^"'\`]+)["'\`]`)
6704
+ new RegExp(`["'\`]?${ts9.setting}["'\`]?\\s*:\\s*["'\`]([^"'\`]+)["'\`]`)
6666
6705
  );
6667
6706
  if (m)
6668
6707
  named.push({
6669
6708
  name: m[1],
6670
- kind: ts6.kind,
6671
- from: `${ts6.cap}.${ts6.setting}`,
6709
+ kind: ts9.kind,
6710
+ from: `${ts9.cap}.${ts9.setting}`,
6672
6711
  anchor: c.anchor
6673
6712
  });
6674
6713
  }
@@ -9173,7 +9212,7 @@ function jsonToS(v, root, seen, depth = 0) {
9173
9212
  return v.enum !== void 0 || v.const !== void 0 ? SCALAR : { k: "any" };
9174
9213
  return parts.length === 1 ? parts[0] : { k: "all", parts };
9175
9214
  }
9176
- function walk2(s, path, useAt, out, loc) {
9215
+ function walk3(s, path, useAt, out, loc) {
9177
9216
  const offsetsFor = (...offs) => offs.filter((o) => o !== void 0);
9178
9217
  switch (s.k) {
9179
9218
  case "union": {
@@ -9202,18 +9241,18 @@ function walk2(s, path, useAt, out, loc) {
9202
9241
  anchor: loc(unreadB[0].at ?? s.at ?? useAt).anchor
9203
9242
  });
9204
9243
  }
9205
- for (const b of branches2) if (b.k !== "unread") walk2(b, path, useAt, out, loc);
9244
+ for (const b of branches2) if (b.k !== "unread") walk3(b, path, useAt, out, loc);
9206
9245
  return;
9207
9246
  }
9208
9247
  case "array":
9209
- if (s.items) walk2(s.items, `${path}[]`, useAt, out, loc);
9210
- s.prefix.forEach((p, i) => walk2(p, `${path}[${i}]`, useAt, out, loc));
9248
+ if (s.items) walk3(s.items, `${path}[]`, useAt, out, loc);
9249
+ s.prefix.forEach((p, i) => walk3(p, `${path}[${i}]`, useAt, out, loc));
9211
9250
  return;
9212
9251
  case "object":
9213
- for (const p of s.props) walk2(p.schema, `${path}.${p.label}`, p.at ?? useAt, out, loc);
9252
+ for (const p of s.props) walk3(p.schema, `${path}.${p.label}`, p.at ?? useAt, out, loc);
9214
9253
  return;
9215
9254
  case "all":
9216
- for (const p of s.parts) walk2(p, path, useAt, out, loc);
9255
+ for (const p of s.parts) walk3(p, path, useAt, out, loc);
9217
9256
  return;
9218
9257
  case "unread":
9219
9258
  out.push({
@@ -9541,7 +9580,7 @@ function runStatic(tree) {
9541
9580
  const finalSchema = located.kind === "json" ? jsonSchemaOf(located.node, ctx) : evalZod(located.node, ctx);
9542
9581
  j.argumentCount += countArgs(finalSchema);
9543
9582
  const sites = [];
9544
- walk2(finalSchema, tool.name, void 0, sites, loc);
9583
+ walk3(finalSchema, tool.name, void 0, sites, loc);
9545
9584
  judgeSites(dedupe(sites), false, j);
9546
9585
  }
9547
9586
  return verdictOf(j, "static, from source", tools[0].anchor);
@@ -9584,7 +9623,7 @@ function runServedHalf(runtime) {
9584
9623
  const schema = jsonToS(t.inputSchema, { root: t.inputSchema }, /* @__PURE__ */ new Set());
9585
9624
  j.argumentCount += countArgs(schema);
9586
9625
  const sites = [];
9587
- walk2(schema, t.name, void 0, sites, () => ({ anchor: `${anchor} tools/list ${t.name}` }));
9626
+ walk3(schema, t.name, void 0, sites, () => ({ anchor: `${anchor} tools/list ${t.name}` }));
9588
9627
  judgeSites(dedupe(sites), true, j);
9589
9628
  }
9590
9629
  return verdictOf(j, "served tools/list inputSchema", anchor);
@@ -9764,7 +9803,7 @@ function controlSites(text) {
9764
9803
  if (located.kind !== "zod") return [];
9765
9804
  const ctx = moduleCtx(file, null);
9766
9805
  const sites = [];
9767
- walk2(evalZod(located.node, ctx), "c", void 0, sites, () => ({ anchor: "<s43-control>" }));
9806
+ walk3(evalZod(located.node, ctx), "c", void 0, sites, () => ({ anchor: "<s43-control>" }));
9768
9807
  return sites;
9769
9808
  }
9770
9809
  function s43Controls() {
@@ -10309,7 +10348,7 @@ function ceilingCensus(tree) {
10309
10348
  continue;
10310
10349
  }
10311
10350
  if (!isRecord(json) || !("contextCeiling" in json)) continue;
10312
- const anchor = `${f.rel}:${lineOf(text, /"contextCeiling"/)}`;
10351
+ const anchor = `${f.rel}:${lineOf2(text, /"contextCeiling"/)}`;
10313
10352
  const c = json.contextCeiling;
10314
10353
  if (!isRecord(c)) {
10315
10354
  census.partial.push({
@@ -11464,11 +11503,67 @@ var BARE_STRING_RE = /^\s*["'`]([^"'`]+)["'`]\s*,?\s*$/;
11464
11503
  var BACKWARD_LOOKBACK = 10;
11465
11504
  var FORWARD_LOOKAHEAD = 6;
11466
11505
  var DESCRIPTION_KEY_RE = /\bdescription\s*:/;
11506
+ function templateLength(s) {
11507
+ let i = 1;
11508
+ while (i < s.length) {
11509
+ const c = s[i];
11510
+ if (c === "\\") i += 2;
11511
+ else if (c === "`") return i + 1;
11512
+ else if (c === "$" && s[i + 1] === "{") {
11513
+ let depth = 1;
11514
+ i += 2;
11515
+ while (i < s.length && depth > 0) {
11516
+ const d = s[i];
11517
+ if (d === "`") {
11518
+ const inner = templateLength(s.slice(i));
11519
+ if (inner < 0) return -1;
11520
+ i += inner;
11521
+ continue;
11522
+ }
11523
+ if (d === '"' || d === "'") {
11524
+ for (i++; i < s.length && s[i] !== d; i++) if (s[i] === "\\") i++;
11525
+ } else if (d === "{") depth++;
11526
+ else if (d === "}") depth--;
11527
+ i++;
11528
+ }
11529
+ } else i++;
11530
+ }
11531
+ return -1;
11532
+ }
11533
+ function readDeclaredDescription(text) {
11534
+ let rest = text.replace(/^\s+/, "");
11535
+ let acc = "";
11536
+ let first = true;
11537
+ for (; ; ) {
11538
+ const q = rest[0];
11539
+ let len2 = -1;
11540
+ if (q === "`") len2 = templateLength(rest);
11541
+ else if (q === '"' || q === "'") {
11542
+ let i = 1;
11543
+ while (i < rest.length && rest[i] !== q && rest[i] !== "\n") i += rest[i] === "\\" ? 2 : 1;
11544
+ if (rest[i] === q) len2 = i + 1;
11545
+ }
11546
+ if (len2 < 0) {
11547
+ const expr = rest.split("\n")[0].trim().slice(0, 60);
11548
+ return { kind: "non-literal", expr: first ? expr : `\u2026+ ${expr}` };
11549
+ }
11550
+ first = false;
11551
+ const piece = rest.slice(0, len2);
11552
+ const lit = q === "`" ? readDescriptionValue(piece) : void 0;
11553
+ acc += lit?.kind === "literal" ? lit.text : q === "`" ? piece : piece.slice(1, -1);
11554
+ rest = rest.slice(len2).replace(/^\s+/, "");
11555
+ if (rest.startsWith("+")) {
11556
+ rest = rest.slice(1).replace(/^\s+/, "");
11557
+ continue;
11558
+ }
11559
+ return { kind: "literal", text: acc };
11560
+ }
11561
+ }
11467
11562
  function findInlineDescription(tree, siteAnchor, toolName2) {
11468
11563
  const forwarded = wrapperDescriptionArg(tree, siteAnchor);
11469
11564
  if (forwarded !== void 0) {
11470
11565
  const resolved = /^[A-Za-z_$][\w$]*$/.test(forwarded) ? constExpression(tree, forwarded) : null;
11471
- const v = readDescriptionValue(resolved ?? forwarded);
11566
+ const v = readDeclaredDescription(resolved ?? forwarded);
11472
11567
  if (v.kind === "literal" && v.text.length > 0) return v.text;
11473
11568
  if (v.kind === "non-literal") return v;
11474
11569
  }
@@ -11494,7 +11589,7 @@ function findInlineDescription(tree, siteAnchor, toolName2) {
11494
11589
  if (key && key.index !== void 0) {
11495
11590
  const after = line.raw.slice(key.index + key[0].length);
11496
11591
  const tail = file.lines.slice(n, n + 8).filter((l) => !l.comment).map((l) => l.raw).join("\n");
11497
- const v = readDescriptionValue(`${after}
11592
+ const v = readDeclaredDescription(`${after}
11498
11593
  ${tail}`);
11499
11594
  if (v.kind === "literal" && v.text.length > 0) return v.text;
11500
11595
  if (v.kind === "non-literal") {
@@ -11508,6 +11603,12 @@ ${tail}`);
11508
11603
  if (n >= siteLine) {
11509
11604
  const bare = line.raw.match(BARE_STRING_RE);
11510
11605
  if (bare && bare[1] !== toolName2) return bare[1];
11606
+ if (!bare && /^\s*(["'`]).*\1\s*\+\s*$/.test(line.raw)) {
11607
+ const chain = file.lines.slice(n - 1, n + 8).filter((l) => !l.comment).map((l) => l.raw).join("\n");
11608
+ const v = readDeclaredDescription(chain);
11609
+ if (v.kind === "literal" && v.text.length > 0 && v.text !== toolName2) return v.text;
11610
+ if (v.kind === "non-literal" && !nonLiteral) nonLiteral = v;
11611
+ }
11511
11612
  }
11512
11613
  }
11513
11614
  return nonLiteral;
@@ -13097,7 +13198,7 @@ function workflowEvidence(text) {
13097
13198
  if (NOTIFY_RE.test(window)) signal = i + 1;
13098
13199
  }
13099
13200
  });
13100
- const identity = IDENTITY_CHECK_RE.test(text) ? lineOf(text, IDENTITY_CHECK_RE) : null;
13201
+ const identity = IDENTITY_CHECK_RE.test(text) ? lineOf2(text, IDENTITY_CHECK_RE) : null;
13101
13202
  return { signal, identity };
13102
13203
  }
13103
13204
  var c28DeployFailureSignal = {
@@ -13146,7 +13247,7 @@ var c28DeployFailureSignal = {
13146
13247
  for (const w of deploys) {
13147
13248
  const ev = workflowEvidence(w.text);
13148
13249
  if (ev.signal === null && ev.identity === null) {
13149
- reds.push(`${w.rel}:${lineOf(w.text, DEPLOY_RE)}`);
13250
+ reds.push(`${w.rel}:${lineOf2(w.text, DEPLOY_RE)}`);
13150
13251
  } else {
13151
13252
  oks.push({
13152
13253
  rel: w.rel,
@@ -13196,7 +13297,7 @@ function pluginPackages(tree) {
13196
13297
  function filesUnder(dir, unread2, rel2) {
13197
13298
  const out = /* @__PURE__ */ new Map();
13198
13299
  let incomplete = false;
13199
- const walk3 = (d, prefix) => {
13300
+ const walk4 = (d, prefix) => {
13200
13301
  let names2;
13201
13302
  try {
13202
13303
  names2 = readdirSync8(d);
@@ -13209,7 +13310,7 @@ function filesUnder(dir, unread2, rel2) {
13209
13310
  const full = join12(d, n);
13210
13311
  const r = prefix ? `${prefix}/${n}` : n;
13211
13312
  try {
13212
- if (statSync11(full).isDirectory()) walk3(full, r);
13313
+ if (statSync11(full).isDirectory()) walk4(full, r);
13213
13314
  else out.set(r, readFileSync11(full));
13214
13315
  } catch (e) {
13215
13316
  out.set(r, null);
@@ -13220,7 +13321,7 @@ function filesUnder(dir, unread2, rel2) {
13220
13321
  }
13221
13322
  }
13222
13323
  };
13223
- walk3(dir, "");
13324
+ walk4(dir, "");
13224
13325
  return { files: out, incomplete };
13225
13326
  }
13226
13327
  function absenceOf(base, rel2) {
@@ -14076,7 +14177,7 @@ function writesFile(text, f) {
14076
14177
  function testFiles(tree, unread2) {
14077
14178
  const base = baseOf(tree);
14078
14179
  const out = [];
14079
- const walk3 = (dir, rel2) => {
14180
+ const walk4 = (dir, rel2) => {
14080
14181
  let names2;
14081
14182
  try {
14082
14183
  names2 = readdirSync10(dir);
@@ -14093,14 +14194,14 @@ function testFiles(tree, unread2) {
14093
14194
  } catch {
14094
14195
  continue;
14095
14196
  }
14096
- if (st.isDirectory()) walk3(full, `${rel2}/${name}`);
14197
+ if (st.isDirectory()) walk4(full, `${rel2}/${name}`);
14097
14198
  else if (/\.[cm]?[jt]sx?$/.test(name))
14098
14199
  out.push({ rel: `${rel2}/${name}`, text: readText(full) ?? "" });
14099
14200
  }
14100
14201
  };
14101
14202
  for (const d of ["tests", "test", "__tests__"]) {
14102
14203
  try {
14103
- if (statSync13(join14(base, d)).isDirectory()) walk3(join14(base, d), d);
14204
+ if (statSync13(join14(base, d)).isDirectory()) walk4(join14(base, d), d);
14104
14205
  } catch {
14105
14206
  }
14106
14207
  }
@@ -15346,7 +15447,7 @@ function walkManifests(tree, dir, out, unread2) {
15346
15447
  }
15347
15448
  }
15348
15449
  }
15349
- function lineOf2(text, pkg) {
15450
+ function lineOf3(text, pkg) {
15350
15451
  const i = text.split("\n").findIndex((l) => l.includes(`"${pkg}"`));
15351
15452
  return i < 0 ? 1 : i + 1;
15352
15453
  }
@@ -15387,7 +15488,7 @@ function c41Collect(tree) {
15387
15488
  if (alias) {
15388
15489
  decls.push({
15389
15490
  manifest,
15390
- line: lineOf2(text, pkg),
15491
+ line: lineOf3(text, pkg),
15391
15492
  field: `${field} (alias ${pkg})`,
15392
15493
  pkg: alias.pkg,
15393
15494
  spec: alias.spec
@@ -15395,7 +15496,7 @@ function c41Collect(tree) {
15395
15496
  continue;
15396
15497
  }
15397
15498
  if (!pkg.startsWith(SCOPE)) continue;
15398
- decls.push({ manifest, line: lineOf2(text, pkg), field, pkg, spec });
15499
+ decls.push({ manifest, line: lineOf3(text, pkg), field, pkg, spec });
15399
15500
  }
15400
15501
  }
15401
15502
  }
@@ -16411,10 +16512,137 @@ var d5 = {
16411
16512
  };
16412
16513
 
16413
16514
  // src/detectors/d6.ts
16515
+ import * as ts from "typescript";
16414
16516
  var COMMUNITY_RE = /["'`]io\.modelcontextprotocol\/ui["'`]\s*:|_meta\s*\[\s*["'`]io\.modelcontextprotocol\/ui["'`]\s*\]/;
16415
16517
  var FLAT_RE = /["'`]ui\/resourceUri["'`]\s*:|_meta\s*\[\s*["'`]ui\/resourceUri["'`]\s*\]/;
16416
- var NESTED_UI_RE = /_meta\s*:\s*\{\s*ui\b/;
16417
- var RESOURCE_URI_RE = /\bresourceUri\b/;
16518
+ var RESOURCE_REGISTRATIONS = /* @__PURE__ */ new Set([
16519
+ "registerResource",
16520
+ "resource",
16521
+ "registerResourceTemplate",
16522
+ "registerAppResource"
16523
+ ]);
16524
+ function staticKey(name) {
16525
+ if (ts.isIdentifier(name) || ts.isStringLiteralLike(name) || ts.isNumericLiteral(name))
16526
+ return name.text;
16527
+ if (ts.isComputedPropertyName(name) && ts.isStringLiteralLike(name.expression))
16528
+ return name.expression.text;
16529
+ return void 0;
16530
+ }
16531
+ function scanKind(rel2) {
16532
+ return rel2.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS;
16533
+ }
16534
+ function scanFileForBinding(file, scan) {
16535
+ const text = file.lines.map((l) => l.raw).join("\n");
16536
+ if (!text.includes("_meta") && !text.includes("registerAppTool")) return;
16537
+ const sf = ts.createSourceFile(file.rel, text, ts.ScriptTarget.Latest, true, scanKind(file.rel));
16538
+ const at = (n) => `${file.rel}:${sf.getLineAndCharacterOfPosition(n.getStart(sf)).line + 1}`;
16539
+ const unread2 = (n, why) => {
16540
+ scan.unread.push({ anchor: at(n), why });
16541
+ };
16542
+ const bind = (n) => {
16543
+ scan.bound ??= { anchor: at(n) };
16544
+ };
16545
+ const readUiObject = (obj) => {
16546
+ let named = false;
16547
+ let opaque = false;
16548
+ for (const p of obj.properties) {
16549
+ if (ts.isSpreadAssignment(p)) {
16550
+ opaque = true;
16551
+ continue;
16552
+ }
16553
+ if (ts.isShorthandPropertyAssignment(p)) {
16554
+ if (p.name.text === "resourceUri") named = true;
16555
+ continue;
16556
+ }
16557
+ if (ts.isPropertyAssignment(p) || ts.isMethodDeclaration(p)) {
16558
+ const k = staticKey(p.name);
16559
+ if (k === void 0) opaque = true;
16560
+ else if (k === "resourceUri") named = true;
16561
+ }
16562
+ }
16563
+ if (named) bind(obj);
16564
+ else if (opaque)
16565
+ unread2(obj, "a `ui` object built from a spread or a computed key that names no resourceUri");
16566
+ else scan.partial ??= { anchor: at(obj) };
16567
+ };
16568
+ const readUiValue = (v, site) => {
16569
+ const e = ts.isParenthesizedExpression(v) ? v.expression : v;
16570
+ if (ts.isObjectLiteralExpression(e)) readUiObject(e);
16571
+ else
16572
+ unread2(
16573
+ site,
16574
+ `\`ui\` is the expression \`${e.getText(sf).slice(0, 40)}\`, not an object literal`
16575
+ );
16576
+ };
16577
+ const readMetaObject = (obj) => {
16578
+ let sawUi = false;
16579
+ let opaque = false;
16580
+ for (const p of obj.properties) {
16581
+ if (ts.isSpreadAssignment(p)) {
16582
+ opaque = true;
16583
+ continue;
16584
+ }
16585
+ if (ts.isShorthandPropertyAssignment(p)) {
16586
+ if (p.name.text === "ui") {
16587
+ sawUi = true;
16588
+ unread2(p, "`ui` is a shorthand variable, not an object literal");
16589
+ }
16590
+ continue;
16591
+ }
16592
+ if (!ts.isPropertyAssignment(p)) continue;
16593
+ const k = staticKey(p.name);
16594
+ if (k === void 0) {
16595
+ opaque = true;
16596
+ continue;
16597
+ }
16598
+ if (k === "ui") {
16599
+ sawUi = true;
16600
+ readUiValue(p.initializer, p);
16601
+ }
16602
+ }
16603
+ if (!sawUi && opaque)
16604
+ unread2(obj, "a `_meta` object built from a spread or a computed key, no `ui` beside it");
16605
+ };
16606
+ const visit = (n) => {
16607
+ if (ts.isCallExpression(n)) {
16608
+ const c = n.expression;
16609
+ const name = ts.isIdentifier(c) ? c.text : ts.isPropertyAccessExpression(c) ? c.name.text : "";
16610
+ if (name === "registerAppTool") bind(n);
16611
+ if (RESOURCE_REGISTRATIONS.has(name)) return;
16612
+ }
16613
+ if (ts.isPropertyAssignment(n) && staticKey(n.name) === "_meta") {
16614
+ const v = ts.isParenthesizedExpression(n.initializer) ? n.initializer.expression : n.initializer;
16615
+ if (ts.isObjectLiteralExpression(v)) readMetaObject(v);
16616
+ else
16617
+ unread2(
16618
+ n,
16619
+ `\`_meta\` is the expression \`${v.getText(sf).slice(0, 40)}\`, not an object literal`
16620
+ );
16621
+ }
16622
+ if (ts.isBinaryExpression(n) && n.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
16623
+ const last = lastSegment2(n.left);
16624
+ if (last?.name === "resourceUri" && lastSegment2(last.obj)?.name === "ui") {
16625
+ const owner = lastSegment2(last.obj);
16626
+ if (owner && lastSegment2(owner.obj)?.name === "_meta") bind(n);
16627
+ } else if (last?.name === "ui" && lastSegment2(last.obj)?.name === "_meta") {
16628
+ readUiValue(n.right, n);
16629
+ }
16630
+ }
16631
+ ts.forEachChild(n, visit);
16632
+ };
16633
+ visit(sf);
16634
+ }
16635
+ function lastSegment2(e) {
16636
+ if (ts.isPropertyAccessExpression(e)) return { obj: e.expression, name: e.name.text };
16637
+ if (ts.isElementAccessExpression(e) && ts.isStringLiteralLike(e.argumentExpression))
16638
+ return { obj: e.expression, name: e.argumentExpression.text };
16639
+ return void 0;
16640
+ }
16641
+ function scanUiBinding(tree) {
16642
+ const scan = { bound: null, partial: null, unread: [] };
16643
+ for (const file of tree.files) scanFileForBinding(file, scan);
16644
+ return scan;
16645
+ }
16418
16646
  var d6 = {
16419
16647
  id: "D6 mcp-apps ui-key",
16420
16648
  rule: "A-6",
@@ -16422,15 +16650,11 @@ var d6 = {
16422
16650
  run(tree) {
16423
16651
  let community = null;
16424
16652
  let flat = null;
16425
- let nested2 = null;
16426
- let sawResourceUri = false;
16427
16653
  for (const file of tree.files) {
16428
16654
  for (const line of file.lines) {
16429
16655
  if (line.comment) continue;
16430
16656
  if (!community && COMMUNITY_RE.test(line.raw)) community = { file: file.rel, line: line.n };
16431
16657
  if (!flat && FLAT_RE.test(line.raw)) flat = { file: file.rel, line: line.n };
16432
- if (!nested2 && NESTED_UI_RE.test(line.raw)) nested2 = { file: file.rel, line: line.n };
16433
- if (RESOURCE_URI_RE.test(line.raw)) sawResourceUri = true;
16434
16658
  }
16435
16659
  }
16436
16660
  if (community) {
@@ -16449,17 +16673,29 @@ var d6 = {
16449
16673
  verdict: "flat ui/resourceUri key (deprecated) -> _meta.ui.resourceUri"
16450
16674
  };
16451
16675
  }
16452
- if (nested2 && sawResourceUri) {
16676
+ const binding = scanUiBinding(tree);
16677
+ if (binding.bound) {
16453
16678
  return {
16454
16679
  id: this.id,
16455
- anchor: `${nested2.file}:${nested2.line}`,
16680
+ anchor: binding.bound.anchor,
16456
16681
  state: "present",
16457
16682
  verdict: "GA nested _meta.ui.resourceUri"
16458
16683
  };
16459
16684
  }
16460
16685
  const ui = uiResourceSites(tree);
16461
16686
  if (ui.length > 0) {
16462
- const partial = nested2 ? ` (a nested _meta.ui at ${nested2.file}:${nested2.line} names no resourceUri)` : "";
16687
+ if (binding.unread.length > 0) {
16688
+ const u = binding.unread[0];
16689
+ const reason = `could not determine binding: the App serves ${ui.length} ui:// resource(s) and no \`_meta.ui.resourceUri\` was read, but ${u.anchor} holds a shape the reader cannot follow (${u.why})${binding.unread.length > 1 ? `; ${binding.unread.length - 1} more` : ""} (A-6)`;
16690
+ return {
16691
+ id: this.id,
16692
+ anchor: u.anchor,
16693
+ state: "could-not-judge",
16694
+ reason,
16695
+ verdict: `could not judge: ${reason}`
16696
+ };
16697
+ }
16698
+ const partial = binding.partial ? ` (a nested _meta.ui at ${binding.partial.anchor} names no resourceUri)` : "";
16463
16699
  return {
16464
16700
  id: this.id,
16465
16701
  anchor: ui[0].anchor,
@@ -17798,7 +18034,7 @@ function findExtensionManifests(tree) {
17798
18034
  } catch {
17799
18035
  return out;
17800
18036
  }
17801
- const walk3 = (dir) => {
18037
+ const walk4 = (dir) => {
17802
18038
  let entries;
17803
18039
  try {
17804
18040
  entries = readdirSync13(dir);
@@ -17820,7 +18056,7 @@ function findExtensionManifests(tree) {
17820
18056
  recordSkip(tree, full, base);
17821
18057
  continue;
17822
18058
  }
17823
- walk3(full);
18059
+ walk4(full);
17824
18060
  } else if (name === "extension.json") {
17825
18061
  if (!st.isFile()) {
17826
18062
  recordSkip(tree, full, base, "not a regular file (FIFO, socket or device) \u2014 not read");
@@ -17830,7 +18066,7 @@ function findExtensionManifests(tree) {
17830
18066
  }
17831
18067
  }
17832
18068
  };
17833
- walk3(base);
18069
+ walk4(base);
17834
18070
  return out;
17835
18071
  }
17836
18072
 
@@ -18531,7 +18767,7 @@ function findHooksDirs(tree, unreadable2, gaps) {
18531
18767
  unreadable2.push({ anchor, reason });
18532
18768
  }
18533
18769
  };
18534
- const walk3 = (dir) => {
18770
+ const walk4 = (dir) => {
18535
18771
  let entries;
18536
18772
  try {
18537
18773
  entries = readdirSync14(dir);
@@ -18571,10 +18807,10 @@ function findHooksDirs(tree, unreadable2, gaps) {
18571
18807
  }
18572
18808
  out.push({ anchor: `${name}/`, tokens });
18573
18809
  }
18574
- walk3(full);
18810
+ walk4(full);
18575
18811
  }
18576
18812
  };
18577
- walk3(base);
18813
+ walk4(base);
18578
18814
  return out;
18579
18815
  }
18580
18816
  var LIFECYCLE_OBJ_RE = /\blifecycle\s*:\s*\{/;
@@ -19094,7 +19330,7 @@ function collectHooksDirSources(tree, unreadable2, gaps) {
19094
19330
  unreadable2.push({ anchor, reason });
19095
19331
  }
19096
19332
  };
19097
- const walk3 = (dir) => {
19333
+ const walk4 = (dir) => {
19098
19334
  let entries;
19099
19335
  try {
19100
19336
  entries = readdirSync15(dir);
@@ -19149,10 +19385,10 @@ function collectHooksDirSources(tree, unreadable2, gaps) {
19149
19385
  });
19150
19386
  }
19151
19387
  }
19152
- walk3(full);
19388
+ walk4(full);
19153
19389
  }
19154
19390
  };
19155
- walk3(base);
19391
+ walk4(base);
19156
19392
  return out;
19157
19393
  }
19158
19394
  var LIFECYCLE_OBJ_RE2 = /\blifecycle\s*:\s*\{/;
@@ -19519,6 +19755,194 @@ var dServer2 = guardUnreadablePackageJson(dServer2Inner, {
19519
19755
  authoritative: false
19520
19756
  });
19521
19757
 
19758
+ // src/detectors/dServer6Flow.ts
19759
+ import * as ts2 from "typescript";
19760
+ var LOG_CALL_RE = /^(?:console|logger|log)\.(?:log|info|warn|error|debug|trace)$/;
19761
+ var STREAM_WRITE_RE = /^process\.(?:stderr|stdout)\.write$/;
19762
+ var ALWAYS_INFRA_PROPS = /* @__PURE__ */ new Set(["hostname"]);
19763
+ var OBJECT_INFRA_PROPS = /* @__PURE__ */ new Set(["host", "url", "origin", "href"]);
19764
+ var SERVERISH_NAME_RE = /server|srv|listener|endpoint|url|uri|origin/i;
19765
+ var INFRA_NAME_RE = /host|url|uri|origin|endpoint|addr/i;
19766
+ var SERVER_FACTORY_RE = /(?:^|\.)(?:serve|createServer|listen)$/;
19767
+ var MAX_DEPTH = 4;
19768
+ function scriptKind(rel2) {
19769
+ if (/\.tsx$/i.test(rel2)) return ts2.ScriptKind.TSX;
19770
+ if (/\.jsx$/i.test(rel2)) return ts2.ScriptKind.JSX;
19771
+ if (/\.(?:js|mjs|cjs)$/i.test(rel2)) return ts2.ScriptKind.JS;
19772
+ return ts2.ScriptKind.TS;
19773
+ }
19774
+ function declsIn(scope2, name) {
19775
+ const out = [];
19776
+ if (ts2.isFunctionLike(scope2)) {
19777
+ for (const p of scope2.parameters) {
19778
+ let found = false;
19779
+ const visitName = (n) => {
19780
+ if (ts2.isIdentifier(n)) found ||= n.text === name;
19781
+ else for (const e of n.elements) if (ts2.isBindingElement(e)) visitName(e.name);
19782
+ };
19783
+ visitName(p.name);
19784
+ if (found) out.push({ kind: "opaque" });
19785
+ }
19786
+ }
19787
+ walk(
19788
+ scope2,
19789
+ (n) => {
19790
+ if (ts2.isVariableDeclaration(n)) {
19791
+ if (ts2.isIdentifier(n.name)) {
19792
+ if (n.name.text === name) out.push({ kind: "var", init: n.initializer, node: n });
19793
+ } else if (ts2.isObjectBindingPattern(n.name)) {
19794
+ for (const el of n.name.elements) {
19795
+ if (!ts2.isIdentifier(el.name) || el.name.text !== name) continue;
19796
+ const prop2 = el.propertyName && ts2.isIdentifier(el.propertyName) ? el.propertyName.text : el.propertyName && ts2.isStringLiteralLike(el.propertyName) ? el.propertyName.text : el.propertyName ? void 0 : el.name.text;
19797
+ if (prop2 && n.initializer && !el.dotDotDotToken)
19798
+ out.push({ kind: "binding", prop: prop2, init: n.initializer, node: el });
19799
+ else out.push({ kind: "opaque" });
19800
+ }
19801
+ } else if (ts2.isArrayBindingPattern(n.name)) {
19802
+ for (const el of n.name.elements)
19803
+ if (ts2.isBindingElement(el) && ts2.isIdentifier(el.name) && el.name.text === name)
19804
+ out.push({ kind: "opaque" });
19805
+ }
19806
+ }
19807
+ },
19808
+ true
19809
+ );
19810
+ return out;
19811
+ }
19812
+ function declOf(id) {
19813
+ for (let s = id.parent; s; s = s.parent) {
19814
+ if (!(ts2.isFunctionLike(s) || ts2.isSourceFile(s))) continue;
19815
+ const ds = declsIn(s, id.text);
19816
+ if (ds.length === 0) continue;
19817
+ return ds.length === 1 ? ds[0] : { kind: "opaque" };
19818
+ }
19819
+ return void 0;
19820
+ }
19821
+ function isServerish(e, depth) {
19822
+ const u = unwrap(e);
19823
+ if (depth > MAX_DEPTH) return false;
19824
+ if (ts2.isNewExpression(u)) return dotted(u.expression) === "URL";
19825
+ if (ts2.isCallExpression(u)) {
19826
+ const c = dotted(u.expression);
19827
+ return c !== void 0 && SERVER_FACTORY_RE.test(c);
19828
+ }
19829
+ const pr = propRead(u);
19830
+ if (pr) return OBJECT_INFRA_PROPS.has(pr.name) && isServerish(pr.obj, depth + 1);
19831
+ if (ts2.isIdentifier(u)) {
19832
+ if (SERVERISH_NAME_RE.test(u.text)) return true;
19833
+ const d = declOf(u);
19834
+ return d?.kind === "var" && d.init !== void 0 && isServerish(d.init, depth + 1);
19835
+ }
19836
+ return false;
19837
+ }
19838
+ function pathOf(obj, name) {
19839
+ const d = dotted(obj);
19840
+ return d === void 0 ? void 0 : `${d}.${name}`;
19841
+ }
19842
+ function infraProp(obj, name) {
19843
+ return ALWAYS_INFRA_PROPS.has(name) || OBJECT_INFRA_PROPS.has(name) && isServerish(obj, 0);
19844
+ }
19845
+ function leaves(e, out = []) {
19846
+ const u = unwrap(e);
19847
+ if (ts2.isTemplateExpression(u)) {
19848
+ for (const s of u.templateSpans) leaves(s.expression, out);
19849
+ } else if (ts2.isBinaryExpression(u) && u.operatorToken.kind === ts2.SyntaxKind.PlusToken) {
19850
+ leaves(u.left, out);
19851
+ leaves(u.right, out);
19852
+ } else if (ts2.isConditionalExpression(u)) {
19853
+ leaves(u.whenTrue, out);
19854
+ leaves(u.whenFalse, out);
19855
+ } else if (ts2.isObjectLiteralExpression(u)) {
19856
+ for (const p of u.properties) {
19857
+ if (ts2.isPropertyAssignment(p)) leaves(p.initializer, out);
19858
+ else if (ts2.isShorthandPropertyAssignment(p)) out.push(p.name);
19859
+ }
19860
+ } else if (ts2.isArrayLiteralExpression(u)) {
19861
+ for (const x of u.elements) if (!ts2.isSpreadElement(x)) leaves(x, out);
19862
+ } else if (ts2.isCallExpression(u)) {
19863
+ const callee = dotted(u.expression);
19864
+ if (callee === "String" || callee === "JSON.stringify") {
19865
+ for (const a of u.arguments) leaves(a, out);
19866
+ } else if (ts2.isPropertyAccessExpression(u.expression) && u.expression.name.text === "toString") {
19867
+ leaves(u.expression.expression, out);
19868
+ } else out.push(u);
19869
+ } else {
19870
+ out.push(u);
19871
+ }
19872
+ return out;
19873
+ }
19874
+ function classify3(e, depth) {
19875
+ if (depth > MAX_DEPTH) return null;
19876
+ const u = unwrap(e);
19877
+ const pr = propRead(u);
19878
+ if (pr) {
19879
+ return infraProp(pr.obj, pr.name) ? {
19880
+ kind: "hit",
19881
+ via: `${u.getText()} (a ${pr.name} read off ${pr.obj.getText()})`,
19882
+ path: pathOf(pr.obj, pr.name)
19883
+ } : null;
19884
+ }
19885
+ if (ts2.isIdentifier(u)) {
19886
+ const d = declOf(u);
19887
+ if (!d) return null;
19888
+ if (d.kind === "binding") {
19889
+ return infraProp(d.init, d.prop) ? {
19890
+ kind: "hit",
19891
+ via: `${u.text} (destructured: ${d.prop} of ${d.init.getText()}${d.prop === u.text ? "" : `, renamed ${u.text}`})`,
19892
+ path: pathOf(d.init, d.prop)
19893
+ } : null;
19894
+ }
19895
+ if (d.kind === "var" && d.init) {
19896
+ const inner = unwrap(d.init);
19897
+ for (const l of leaves(inner)) {
19898
+ const v = classify3(l, depth + 1);
19899
+ if (v?.kind === "hit") return { kind: "hit", via: `${u.text} <- ${v.via}`, path: v.path };
19900
+ if (v?.kind === "unknown") return v;
19901
+ }
19902
+ const flowsFromCall = ts2.isCallExpression(inner) || ts2.isNewExpression(inner);
19903
+ if (flowsFromCall && INFRA_NAME_RE.test(u.text) && depth === 0)
19904
+ return {
19905
+ kind: "unknown",
19906
+ reason: `${u.text} is assigned from ${inner.getText().slice(0, 60)}, a call whose value this reader cannot follow`
19907
+ };
19908
+ return null;
19909
+ }
19910
+ if (d.kind === "opaque" && INFRA_NAME_RE.test(u.text) && depth === 0)
19911
+ return {
19912
+ kind: "unknown",
19913
+ reason: `${u.text} is a parameter or has several declarations, so where its value comes from cannot be followed`
19914
+ };
19915
+ }
19916
+ return null;
19917
+ }
19918
+ function dServer6Flow(file) {
19919
+ const hits = [];
19920
+ const unknown = [];
19921
+ const sf = ts2.createSourceFile(
19922
+ file.rel,
19923
+ sourceOf(file),
19924
+ ts2.ScriptTarget.Latest,
19925
+ true,
19926
+ scriptKind(file.rel)
19927
+ );
19928
+ walk(sf, (n) => {
19929
+ if (!ts2.isCallExpression(n)) return;
19930
+ const callee = dotted(n.expression);
19931
+ if (!callee || !(LOG_CALL_RE.test(callee) || STREAM_WRITE_RE.test(callee))) return;
19932
+ for (const arg of n.arguments) {
19933
+ if (ts2.isSpreadElement(arg)) continue;
19934
+ for (const l of leaves(arg)) {
19935
+ const v = classify3(l, 0);
19936
+ if (v?.kind === "hit")
19937
+ hits.push({ line: lineOf(n), text: l.getText(), via: v.via, path: v.path });
19938
+ else if (v?.kind === "unknown")
19939
+ unknown.push({ line: lineOf(n), text: l.getText(), reason: v.reason });
19940
+ }
19941
+ }
19942
+ });
19943
+ return { hits, unknown };
19944
+ }
19945
+
19522
19946
  // src/detectors/dServer6.ts
19523
19947
  var LOG_OPENER_RE = /\b(?:console|logger|log)\.(?:log|info|warn|error|debug|trace)\s*\(|\bprocess\.(?:stderr|stdout)\.write\s*\(/;
19524
19948
  var SECRET_RE = /\b(?:api[_-]?key|token|secret|passwd|password|authorization|auth[_-]?token|bearer|access[_-]?key|client[_-]?secret|private[_-]?key)\b/i;
@@ -19786,6 +20210,27 @@ var dServer6 = {
19786
20210
  }
19787
20211
  }
19788
20212
  }
20213
+ for (const file of tree.files) {
20214
+ const flow = dServer6Flow(file);
20215
+ const seen = new Set(findings.filter((f) => f.form === "D").map((f) => f.site));
20216
+ for (const h of flow.hits) {
20217
+ const site = `${file.rel}:${h.line}`;
20218
+ if (seen.has(site)) continue;
20219
+ if (h.path && resolvesToLiteral(tree, h.path)) continue;
20220
+ seen.add(site);
20221
+ findings.push({
20222
+ site,
20223
+ form: "D",
20224
+ note: `identifier flow: ${h.via} reaches the log call`
20225
+ });
20226
+ }
20227
+ for (const u of flow.unknown) {
20228
+ unreadable2.push({
20229
+ anchor: `${file.rel}:${u.line}`,
20230
+ reason: `cannot follow the value of ${u.text} logged at ${file.rel}:${u.line}: ${u.reason} \u2014 internal-infrastructure detail unverifiable (C-6)`
20231
+ });
20232
+ }
20233
+ }
19789
20234
  for (const file of tree.files) {
19790
20235
  for (const line of file.lines) {
19791
20236
  if (line.comment) continue;
@@ -20225,7 +20670,7 @@ function codeText(file) {
20225
20670
  }
20226
20671
  return { file, text: parts.join(""), kind: Uint8Array.from(kinds), lineStart };
20227
20672
  }
20228
- function lineOf3(ct, off) {
20673
+ function lineOf4(ct, off) {
20229
20674
  let lo = 0;
20230
20675
  let hi = ct.lineStart.length - 1;
20231
20676
  while (lo < hi) {
@@ -20351,8 +20796,8 @@ function on401Path(ct, siteStart, siteEnd) {
20351
20796
  }
20352
20797
  }
20353
20798
  }
20354
- const first = Math.max(1, lineOf3(ct, siteStart) - PATH_LINES_BEFORE);
20355
- const last = Math.min(ct.lineStart.length, lineOf3(ct, siteEnd) + PATH_LINES_AFTER);
20799
+ const first = Math.max(1, lineOf4(ct, siteStart) - PATH_LINES_BEFORE);
20800
+ const last = Math.min(ct.lineStart.length, lineOf4(ct, siteEnd) + PATH_LINES_AFTER);
20356
20801
  const from = Math.max(blockStart, ct.lineStart[first - 1]);
20357
20802
  const to = Math.min(blockEnd2, last < ct.lineStart.length ? ct.lineStart[last] : t.length);
20358
20803
  for (const m of t.slice(from, to).matchAll(/\b401\b/g)) {
@@ -20370,7 +20815,7 @@ function scanChallengeSites(files) {
20370
20815
  const open = m.index ?? 0;
20371
20816
  const close2 = open + m[0].length - 1;
20372
20817
  if (ct.kind[open] !== 1 || ct.kind[close2] !== 1) continue;
20373
- const anchor = `${file.rel}:${lineOf3(ct, open)}`;
20818
+ const anchor = `${file.rel}:${lineOf4(ct, open)}`;
20374
20819
  const before = t.slice(Math.max(0, open - 200), open);
20375
20820
  const after = t.slice(close2 + 1, close2 + 200);
20376
20821
  let form = null;
@@ -20971,7 +21416,7 @@ function configPlaces(tree, reg) {
20971
21416
  meta: placeOf(tree, config, "_meta")
20972
21417
  };
20973
21418
  }
20974
- function lineOf4(anchor) {
21419
+ function lineOf5(anchor) {
20975
21420
  const i = anchor.lastIndexOf(":");
20976
21421
  return [anchor.slice(0, i), Number(anchor.slice(i + 1))];
20977
21422
  }
@@ -21077,7 +21522,7 @@ function judgeStatic(tree, id) {
21077
21522
  to: fn ? lineAt(gate.src.shape, fn.close) : lineAt(gate.src.shape, gate.at) + 1
21078
21523
  }));
21079
21524
  regUnread = unread2.filter((u) => {
21080
- const [rel2, n] = lineOf4(u.anchor);
21525
+ const [rel2, n] = lineOf5(u.anchor);
21081
21526
  return !spans.some((sp) => sp.rel === rel2 && n >= sp.from && n <= sp.to);
21082
21527
  });
21083
21528
  for (const { gate, fn } of installers) {
@@ -21129,7 +21574,7 @@ function judgeStatic(tree, id) {
21129
21574
  }
21130
21575
  const decided = problems.length > 0 ? {
21131
21576
  id,
21132
- anchor: lineOf4(problems[0].match(/\(([^()\s]+:\d+)\)/)?.[1] ?? "-:0").join(":"),
21577
+ anchor: lineOf5(problems[0].match(/\(([^()\s]+:\d+)\)/)?.[1] ?? "-:0").join(":"),
21133
21578
  state: "non-conforming",
21134
21579
  verdict: `${problems.join("; ")} -> every tool declares { domain, mode } (mode exactly read | write, read <-> readOnlyHint true), and the shared decision of ${CLOUD_IDENTITY} refuses tools/call and filters tools/list for every registered tool (mcp-server-standard "Agent tool roles", rules 2-4, 7)`
21135
21580
  } : {
@@ -22012,7 +22457,7 @@ function declaredEntries(dir, dep, unread2) {
22012
22457
  }
22013
22458
  function walkPackage(dir, nm, skipFixtures, unread2) {
22014
22459
  const files = [];
22015
- const walk3 = (d) => {
22460
+ const walk4 = (d) => {
22016
22461
  let names2;
22017
22462
  try {
22018
22463
  names2 = readdirSync16(d).sort();
@@ -22036,11 +22481,11 @@ function walkPackage(dir, nm, skipFixtures, unread2) {
22036
22481
  unread2.push(`${full.slice(nm.length + 1)} (test/example directory: not read)`);
22037
22482
  continue;
22038
22483
  }
22039
- walk3(full);
22484
+ walk4(full);
22040
22485
  } else if (st.isFile() && SOURCE_EXT.test(n)) files.push(full);
22041
22486
  }
22042
22487
  };
22043
- walk3(dir);
22488
+ walk4(dir);
22044
22489
  return files;
22045
22490
  }
22046
22491
  var escapeRe4 = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
@@ -24151,8 +24596,8 @@ function documentsFootprint(manifestText) {
24151
24596
  } catch {
24152
24597
  return false;
24153
24598
  }
24154
- const walk3 = (v) => {
24155
- if (Array.isArray(v)) return v.some(walk3);
24599
+ const walk4 = (v) => {
24600
+ if (Array.isArray(v)) return v.some(walk4);
24156
24601
  if (v === null || typeof v !== "object") return false;
24157
24602
  for (const [k, val] of Object.entries(v)) {
24158
24603
  if (k === "footprint") {
@@ -24160,11 +24605,11 @@ function documentsFootprint(manifestText) {
24160
24605
  if (Array.isArray(val) && val.length > 0) return true;
24161
24606
  if (val !== null && typeof val === "object" && Object.keys(val).length > 0) return true;
24162
24607
  }
24163
- if (walk3(val)) return true;
24608
+ if (walk4(val)) return true;
24164
24609
  }
24165
24610
  return false;
24166
24611
  };
24167
- return walk3(json);
24612
+ return walk4(json);
24168
24613
  }
24169
24614
 
24170
24615
  // src/detectors/s17-forward-auth.ts
@@ -24958,11 +25403,11 @@ function leavesOf(tree, v, file, depth) {
24958
25403
  }
24959
25404
  function classifyOriginValue(tree, value, file) {
24960
25405
  const v = value.trim();
24961
- const leaves = leavesOf(tree, v, file, 0);
24962
- const wild = leaves.strings.find((x) => x.slice(1, -1).includes("*"));
25406
+ const leaves2 = leavesOf(tree, v, file, 0);
25407
+ const wild = leaves2.strings.find((x) => x.slice(1, -1).includes("*"));
24963
25408
  if (wild) return { kind: "wildcard", detail: wild };
24964
- if (leaves.unresolved) return { kind: "unresolved", detail: leaves.unresolved };
24965
- if (leaves.strings.length === 0)
25409
+ if (leaves2.unresolved) return { kind: "unresolved", detail: leaves2.unresolved };
25410
+ if (leaves2.strings.length === 0)
24966
25411
  return { kind: "empty", detail: v.startsWith("[") ? v : `${v} (an empty list)` };
24967
25412
  return { kind: "ok", detail: v };
24968
25413
  }
@@ -25148,19 +25593,47 @@ var s24ToolRateLimit = {
25148
25593
  };
25149
25594
 
25150
25595
  // src/detectors/s25-resource-discipline.ts
25151
- var SUBJECT_RE2 = /registerResource\s*\(|\.resource\s*\(|\bResourceTemplate\s*\(|resources\/read|ReadResourceRequestSchema|\bresources\s*:\s*\{|type\s*:\s*["'`](?:image|audio)["'`]|\bblob\s*:/;
25596
+ import * as ts3 from "typescript";
25597
+ var SUBJECT_RE2 = /registerResource\s*\(|\.resource\s*\(|\bResourceTemplate\s*\(|resources\/read|ReadResourceRequestSchema|\bresources\s*:\s*\{|type\s*:\s*["'`](?:image|audio)["'`]/;
25152
25598
  var HANDLER_RE = /registerResource\s*\(|\.resource\s*\(|ReadResourceRequestSchema/;
25153
25599
  var DEREF_RE = /\b(?:readFile|readFileSync|createReadStream|readdir|readdirSync|stat|statSync|open|fetch)\s*\(([^)]*)\)/g;
25154
25600
  var CALLER_ARG_RE = /\b(?:uri|url|path|params|href|pathname)\b/;
25155
25601
  var VALID_RE2 = /\bresolve\s*\(|\bnormalize\s*\(|\bstartsWith\s*\(|\.includes\(\s*["'`]\.\.|\bnew URL\s*\(|\ballowlist\b|\bisAllowed\w*|\bvalidate\w*\s*\(|\bsanitize\w*\s*\(|\.parse\s*\(|\brealpath\w*\s*\(/i;
25156
25602
  var SCHEME_RE = /["'`]([^\s"'`:/]+(?: [^\s"'`:/]+)*):\/\/[^"'`]*["'`]/g;
25157
25603
  var RFC3986_SCHEME = /^[A-Za-z][A-Za-z0-9+.-]*$/;
25604
+ function blobAssignments(file) {
25605
+ const text = file.lines.map((l) => l.raw).join("\n");
25606
+ if (!text.includes("blob")) return { sites: [], unparsed: false };
25607
+ const kind = file.rel.endsWith(".tsx") ? ts3.ScriptKind.TSX : ts3.ScriptKind.TS;
25608
+ const sf = ts3.createSourceFile(file.rel, text, ts3.ScriptTarget.Latest, true, kind);
25609
+ const unparsed = (sf.parseDiagnostics ?? []).length > 0;
25610
+ const sites = [];
25611
+ const lineAt4 = (n) => sf.getLineAndCharacterOfPosition(n.getStart(sf)).line + 1;
25612
+ const visit = (n) => {
25613
+ if (ts3.isPropertyAssignment(n)) {
25614
+ const k = n.name;
25615
+ const key = ts3.isIdentifier(k) || ts3.isStringLiteralLike(k) ? k.text : ts3.isComputedPropertyName(k) && ts3.isStringLiteralLike(k.expression) ? k.expression.text : void 0;
25616
+ if (key === "blob") sites.push({ line: lineAt4(n), value: n.initializer.getText(sf) });
25617
+ } else if (ts3.isBinaryExpression(n) && n.operatorToken.kind === ts3.SyntaxKind.EqualsToken) {
25618
+ const l = n.left;
25619
+ const name = ts3.isPropertyAccessExpression(l) ? l.name.text : ts3.isElementAccessExpression(l) && ts3.isStringLiteralLike(l.argumentExpression) ? l.argumentExpression.text : void 0;
25620
+ if (name === "blob") sites.push({ line: lineAt4(n), value: n.right.getText(sf) });
25621
+ }
25622
+ ts3.forEachChild(n, visit);
25623
+ };
25624
+ visit(sf);
25625
+ return { sites, unparsed };
25626
+ }
25158
25627
  function s25Controls() {
25159
25628
  return {
25160
- sees: !RFC3986_SCHEME.test("my_app") && !RFC3986_SCHEME.test("1app") && !RFC3986_SCHEME.test("my app") && SUBJECT_RE2.test("registerResource('a', 'x://y', {}, h)"),
25161
- spares: RFC3986_SCHEME.test("my-app+v2.x") && RFC3986_SCHEME.test("https") && !SUBJECT_RE2.test("const x = 1")
25629
+ sees: !RFC3986_SCHEME.test("my_app") && !RFC3986_SCHEME.test("1app") && !RFC3986_SCHEME.test("my app") && SUBJECT_RE2.test("registerResource('a', 'x://y', {}, h)") && blobFixture("const a = { blob: raw };") === 1 && blobFixture('const a = { "blob": raw };') === 1 && blobFixture("a.blob = raw;") === 1,
25630
+ spares: RFC3986_SCHEME.test("my-app+v2.x") && RFC3986_SCHEME.test("https") && !SUBJECT_RE2.test("const x = 1") && blobFixture("const S = new Set([\"blob:\", 'blob:', `blob:`]);") === 0
25162
25631
  };
25163
25632
  }
25633
+ function blobFixture(code) {
25634
+ const lines2 = code.split("\n").map((raw, i) => ({ n: i + 1, raw, comment: false }));
25635
+ return blobAssignments({ path: "control.ts", rel: "control.ts", lines: lines2 }).sites.length;
25636
+ }
25164
25637
  var s25ResourceDiscipline = {
25165
25638
  id: "S25 resource-discipline",
25166
25639
  rule: "S-25",
@@ -25175,15 +25648,20 @@ var s25ResourceDiscipline = {
25175
25648
  const reds = [];
25176
25649
  let subject = 0;
25177
25650
  let first = "";
25651
+ const unread2 = [];
25178
25652
  for (const file of tree.files) {
25179
25653
  if (!isProductSource(file.rel)) continue;
25180
25654
  const rows = uncommentedLines(file);
25181
25655
  const text = rows.join("\n");
25182
- if (!SUBJECT_RE2.test(text)) continue;
25656
+ const blobs = blobAssignments(file);
25657
+ if (blobs.unparsed) unread2.push(file.rel);
25658
+ const blobAt = /* @__PURE__ */ new Map();
25659
+ if (!blobs.unparsed) for (const b of blobs.sites) blobAt.set(b.line, b.value);
25660
+ if (!SUBJECT_RE2.test(text) && blobAt.size === 0) continue;
25183
25661
  subject++;
25184
25662
  const at = (i) => `${file.rel}:${i + 1}`;
25185
25663
  rows.forEach((row, i) => {
25186
- if (!first && SUBJECT_RE2.test(row)) first = at(i);
25664
+ if (!first && (SUBJECT_RE2.test(row) || blobAt.has(i + 1))) first = at(i);
25187
25665
  for (const m of row.matchAll(SCHEME_RE)) {
25188
25666
  const scheme = m[1];
25189
25667
  if (scheme.includes("$") || scheme.includes("{")) continue;
@@ -25193,14 +25671,14 @@ var s25ResourceDiscipline = {
25193
25671
  );
25194
25672
  }
25195
25673
  }
25196
- const blob = row.match(/\bblob\s*:\s*(.+?)(?:,|\}|$)/);
25197
- if (blob && !/base64|btoa|b64/i.test(blob[1])) {
25674
+ const blob = blobAt.get(i + 1);
25675
+ if (blob !== void 0 && !/base64|btoa|b64/i.test(blob)) {
25198
25676
  reds.push(
25199
- `${at(i)} sets blob to a value that is not base64-encoded (${blob[1].trim().slice(0, 40)}): binary content is base64`
25677
+ `${at(i)} sets blob to a value that is not base64-encoded (${blob.trim().replace(/\s+/g, " ").slice(0, 40)}): binary content is base64`
25200
25678
  );
25201
25679
  }
25202
25680
  const near = rows.slice(Math.max(0, i - 3), i + 4).join("\n");
25203
- if ((/type\s*:\s*["'`](?:image|audio)["'`]/.test(row) || blob) && !/mimeType/.test(near)) {
25681
+ if ((/type\s*:\s*["'`](?:image|audio)["'`]/.test(row) || blob !== void 0) && !/mimeType/.test(near)) {
25204
25682
  reds.push(
25205
25683
  `${at(i)} carries binary content with no valid MIME type (no mimeType within three lines)`
25206
25684
  );
@@ -25221,6 +25699,16 @@ var s25ResourceDiscipline = {
25221
25699
  }
25222
25700
  });
25223
25701
  }
25702
+ if (reds.length === 0 && unread2.length > 0) {
25703
+ const reason = `could not determine blob assignments: ${unread2.join(", ")} did not parse, so a \`blob\` property in it was not read (S-25)`;
25704
+ return {
25705
+ id: this.id,
25706
+ anchor: `${unread2[0]}:1`,
25707
+ state: "could-not-judge",
25708
+ reason,
25709
+ verdict: `could not judge: ${reason}`
25710
+ };
25711
+ }
25224
25712
  if (subject === 0) {
25225
25713
  return absentResult(
25226
25714
  this.id,
@@ -25510,11 +25998,98 @@ function importsConvex(m, raw) {
25510
25998
 
25511
25999
  // src/detectors/s28-claim-forwarded.ts
25512
26000
  var PIN11 = STANDARD_PIN;
25513
- var CLAIM_TOKEN = /\bverified(?:Org|Person)\b/;
25514
- var ANY_CLAIM = /\bverified(?:Actor|Org|Person)\b/g;
26001
+ var CLAIM_NAME = /\bverified[A-Z][a-z]+\b/g;
26002
+ var CLAIM_KEY = /\b(verified[A-Z][a-z]+)\s*\??\s*:\s*(?:v\s*\.\s*optional\s*\(\s*)?(v\s*\.\s*(?:string|number|float64|boolean|int64|bigint|literal|id|null|bytes|array)\b)?/g;
26003
+ function claimsIn(text) {
26004
+ return new Set(text.match(CLAIM_NAME) ?? []);
26005
+ }
25515
26006
  var CALL_RE2 = /\b([A-Za-z_$][\w$]*)\s*\.\s*(query|mutation|action)\s*\(/g;
25516
- var GUARD_RE = /\b(?:unresolved\w*Denial|requireVerified\w+|requireClaim\w*)\s*\(|verified-org-unresolved/;
26007
+ var GUARD_RE = /\b(?:requireVerified[A-Z][A-Za-z]*FromServiceAccount|requireClaim\w*)\s*\(/;
25517
26008
  var FLEET_WIDE = /fleet-wide:\s*\S[^\n]{7,}/;
26009
+ var REFUSAL_CALL = /\brequireVerified[A-Z][A-Za-z]*FromServiceAccount\s*\(/;
26010
+ var CLAIM_ABSENT_IF = /\bif\s*\(\s*(?:!\s*(?:\w+\s*\.\s*)?verified[A-Z][a-z]+\b|(?:\w+\s*\.\s*)?verified[A-Z][a-z]+\s*(?:===|==)\s*(?:undefined|null)\b)\s*\)/g;
26011
+ var HELPER_NAME_SHAPE = /Verified|Actor|Caller|Profile/;
26012
+ var NOT_A_CALL = /* @__PURE__ */ new Set([
26013
+ "if",
26014
+ "for",
26015
+ "while",
26016
+ "switch",
26017
+ "catch",
26018
+ "function",
26019
+ "return",
26020
+ "typeof",
26021
+ "await",
26022
+ "new",
26023
+ "super",
26024
+ "query",
26025
+ "mutation",
26026
+ "action",
26027
+ "v"
26028
+ ]);
26029
+ function refusesIn(region) {
26030
+ if (REFUSAL_CALL.test(region)) return true;
26031
+ for (const hit of region.matchAll(CLAIM_ABSENT_IF)) {
26032
+ const after = hit.index + hit[0].length;
26033
+ const rest = region.slice(after);
26034
+ const brace = /^\s*\{/.exec(rest);
26035
+ const body = brace ? region.slice(after, matchClose2(region, after + brace[0].length - 1) + 1) : rest.slice(0, rest.indexOf(";") + 1);
26036
+ if (/\bthrow\b/.test(body)) return true;
26037
+ }
26038
+ return false;
26039
+ }
26040
+ function functionBodies(m) {
26041
+ const out = /* @__PURE__ */ new Map();
26042
+ const add = (name, body) => out.set(name, [...out.get(name) ?? [], body]);
26043
+ for (const hit of m.matchAll(/\bfunction\s+([A-Za-z_$][\w$]*)\s*(?:<[^(]*>)?\s*\(/g)) {
26044
+ const open = hit.index + hit[0].length - 1;
26045
+ const close2 = matchClose2(m, open);
26046
+ if (close2 < 0) continue;
26047
+ let i = close2 + 1;
26048
+ let angle = 0;
26049
+ for (; i < m.length; i++) {
26050
+ const ch = m[i];
26051
+ if (ch === "<") angle++;
26052
+ else if (ch === ">") angle--;
26053
+ else if (ch === "{" && angle <= 0) break;
26054
+ else if (ch === ";" && angle <= 0) {
26055
+ i = m.length;
26056
+ break;
26057
+ }
26058
+ }
26059
+ const end = i < m.length ? matchClose2(m, i) : -1;
26060
+ if (end > 0) add(hit[1], m.slice(close2 + 1, end + 1));
26061
+ }
26062
+ for (const hit of m.matchAll(
26063
+ /\b(?:const|let)\s+([A-Za-z_$][\w$]*)\s*(?::[^=]*)?=\s*(?:async\s*)?(?:\([^)]*\)|[A-Za-z_$][\w$]*)\s*(?::[^=]*?)?=>\s*/g
26064
+ )) {
26065
+ const at = hit.index + hit[0].length;
26066
+ if (m[at] === "{") {
26067
+ const end = matchClose2(m, at);
26068
+ if (end > 0) add(hit[1], m.slice(at, end + 1));
26069
+ } else add(hit[1], m.slice(at, m.indexOf(";", at) < 0 ? m.length : m.indexOf(";", at)));
26070
+ }
26071
+ return out;
26072
+ }
26073
+ function judgeRefusal(mRegion, defs) {
26074
+ const unfollowed = /* @__PURE__ */ new Set();
26075
+ const seen = /* @__PURE__ */ new Set();
26076
+ let refuses = false;
26077
+ const visit = (region, depth) => {
26078
+ if (refusesIn(region)) refuses = true;
26079
+ for (const c of region.matchAll(/(?<![.\w$])([A-Za-z_$][\w$]*)\s*\(/g)) {
26080
+ const name = c[1];
26081
+ if (NOT_A_CALL.has(name) || seen.has(name)) continue;
26082
+ seen.add(name);
26083
+ const bodies = defs.get(name);
26084
+ if (bodies === void 0) {
26085
+ if (depth === 0 && HELPER_NAME_SHAPE.test(name)) unfollowed.add(name);
26086
+ } else if (depth < 6) for (const b of bodies) visit(b, depth + 1);
26087
+ else if (depth === 0) unfollowed.add(name);
26088
+ }
26089
+ };
26090
+ visit(mRegion, 0);
26091
+ return { refuses, unfollowed: [...unfollowed].sort() };
26092
+ }
25518
26093
  var SCOPE_MARKERS = /\bwithOrgScope\b|\brequireAuthenticatedCaller\b|\bresolveInboxReader\b|\bresolveVerified\w*\b|\brequireScope\b|\bgetUserIdentity\b|\bisMaster\b|\bscope\b/;
25519
26094
  var ACTOR_SET_RE = /\bconst\s+(VERIFIED_\w*DOORS)\b[^=]*=\s*new\s+Set\s*(?:<[^>]*>)?\s*\(\s*\[([\s\S]*?)\]\s*\)/;
25520
26095
  function masked(file) {
@@ -25610,6 +26185,8 @@ function discoverBackend(root) {
25610
26185
  }
25611
26186
  function readDoors(backendRoot, unread2) {
25612
26187
  const doors = /* @__PURE__ */ new Map();
26188
+ const read = [];
26189
+ const defs = /* @__PURE__ */ new Map();
25613
26190
  for (const path of listTs(backendRoot, unread2)) {
25614
26191
  let text;
25615
26192
  try {
@@ -25624,12 +26201,22 @@ function readDoors(backendRoot, unread2) {
25624
26201
  lines: text.split("\n").map((raw, i) => ({ n: i + 1, raw, comment: false }))
25625
26202
  };
25626
26203
  const m = masked(file);
26204
+ read.push({ path, text, m });
26205
+ for (const [name, bodies] of functionBodies(m))
26206
+ defs.set(name, [...defs.get(name) ?? [], ...bodies]);
26207
+ }
26208
+ for (const { path, text, m } of read) {
25627
26209
  const module = relative15(backendRoot, path).replace(/\.ts$/, "").split("\\").join("/");
25628
26210
  const re = /\bexport\s+const\s+([A-Za-z_$][\w$]*)\s*=\s*(?:query|mutation|action)\s*\(/g;
25629
26211
  for (let hit = re.exec(m); hit; hit = re.exec(m)) {
25630
26212
  const open = hit.index + hit[0].length - 1;
25631
26213
  const close2 = matchClose2(m, open);
25632
- if (close2 < 0) continue;
26214
+ if (close2 < 0) {
26215
+ unread2.push(
26216
+ `${path}: the region of door ${hit[1]} could not be read (unbalanced delimiters)`
26217
+ );
26218
+ continue;
26219
+ }
25633
26220
  let start = hit.index;
25634
26221
  const lines2 = text.slice(0, start).split("\n");
25635
26222
  let k = lines2.length - 2;
@@ -25643,7 +26230,7 @@ function readDoors(backendRoot, unread2) {
25643
26230
  if (am) {
25644
26231
  const at = hit.index + am.index + am[0].length;
25645
26232
  let argsText = "";
25646
- if (m[at] === "{") argsText = text.slice(at, matchClose2(m, at) + 1);
26233
+ if (m[at] === "{") argsText = m.slice(at, matchClose2(m, at) + 1);
25647
26234
  else {
25648
26235
  const id = /^[A-Za-z_$][\w$]*/.exec(m.slice(at));
25649
26236
  if (id) {
@@ -25651,11 +26238,12 @@ function readDoors(backendRoot, unread2) {
25651
26238
  if (dm) {
25652
26239
  let p = dm.index + dm[0].length;
25653
26240
  if (m.slice(p).startsWith("v.object(")) p += "v.object(".length;
25654
- if (m[p] === "{") argsText = text.slice(p, matchClose2(m, p) + 1);
26241
+ if (m[p] === "{") argsText = m.slice(p, matchClose2(m, p) + 1);
25655
26242
  }
25656
26243
  }
25657
26244
  }
25658
- for (const c of argsText.match(ANY_CLAIM) ?? []) if (!claims.includes(c)) claims.push(c);
26245
+ for (const c of argsText.matchAll(CLAIM_KEY))
26246
+ if (c[2] === void 0 && !claims.includes(c[1])) claims.push(c[1]);
25659
26247
  }
25660
26248
  let exit;
25661
26249
  if (/\brequireServiceAccount\b/.test(mRegion))
@@ -25668,10 +26256,13 @@ function readDoors(backendRoot, unread2) {
25668
26256
  const fw = FLEET_WIDE.exec(region);
25669
26257
  if (fw) exit = `fleet-wide declaration (${fw[0].slice(11).trim().slice(0, 80)})`;
25670
26258
  }
26259
+ const refusal = judgeRefusal(mRegion, defs);
25671
26260
  doors.set(`${module}:${hit[1]}`, {
25672
26261
  claims,
25673
26262
  exit,
25674
- resolvesCaller: SCOPE_MARKERS.test(mRegion)
26263
+ resolvesCaller: SCOPE_MARKERS.test(mRegion),
26264
+ refusesClaimless: refusal.refuses,
26265
+ unfollowed: refusal.unfollowed
25675
26266
  });
25676
26267
  }
25677
26268
  }
@@ -25702,22 +26293,16 @@ function definitionOf(name, files) {
25702
26293
  return void 0;
25703
26294
  }
25704
26295
  function readHelper(name, files, seen = /* @__PURE__ */ new Set(), depth = 0) {
25705
- if (seen.has(name) || depth > 3) return { forwards: false, optional: false };
26296
+ const none = () => ({ claims: /* @__PURE__ */ new Set(), optional: false });
26297
+ if (seen.has(name) || depth > 3) return none();
25706
26298
  seen.add(name);
25707
26299
  const def = definitionOf(name, files);
25708
- if (!def) return { forwards: false, optional: false };
25709
- let forwards = CLAIM_TOKEN.test(def.mask);
26300
+ if (!def) return none();
26301
+ const claims = claimsIn(def.mask);
25710
26302
  const optional = /:\s*\{\s*\}|return\s*\{\s*\}|\?\?\s*\{\s*\}/.test(def.mask);
25711
- if (!forwards) {
25712
- for (const c of def.mask.matchAll(/\b([A-Za-z_$][\w$]*)\s*\(/g)) {
25713
- const sub = readHelper(c[1], files, seen, depth + 1);
25714
- if (sub.forwards) {
25715
- forwards = true;
25716
- break;
25717
- }
25718
- }
25719
- }
25720
- return { forwards, optional };
26303
+ for (const c of def.mask.matchAll(/\b([A-Za-z_$][\w$]*)\s*\(/g))
26304
+ for (const k of readHelper(c[1], files, seen, depth + 1).claims) claims.add(k);
26305
+ return { claims, optional };
25721
26306
  }
25722
26307
  var IDENT4 = /^\s*([A-Za-z_$][\w$]*)\s*(?:as\s+[\w$.<>[\]]+\s*)?$/;
25723
26308
  function esc6(name) {
@@ -25854,20 +26439,15 @@ function readFetchers(files, scan, onCall) {
25854
26439
  continue;
25855
26440
  }
25856
26441
  const argText2 = parts[1] ? fr.m.slice(parts[1][0], parts[1][1]) : "";
25857
- let wrapperClaim = CLAIM_TOKEN.test(argText2);
25858
- if (!wrapperClaim) {
25859
- for (const h of argText2.matchAll(/(?:\.\.\.\s*|\b)([A-Za-z_$][\w$]*)\s*(?:\(\s*\))?/g))
25860
- if (h[1] !== first[1] && readHelper(h[1], files).forwards) {
25861
- wrapperClaim = true;
25862
- break;
25863
- }
25864
- }
26442
+ const wrapperClaims = claimsIn(argText2);
26443
+ for (const h of argText2.matchAll(/(?:\.\.\.\s*|\b)([A-Za-z_$][\w$]*)\s*(?:\(\s*\))?/g))
26444
+ if (h[1] !== first[1]) for (const k of readHelper(h[1], files).claims) wrapperClaims.add(k);
25865
26445
  const label2 = toolNameBefore(fr.text, hit.index).name;
25866
26446
  const before = fr.m.slice(Math.max(0, fn.open - 240), fn.open);
25867
26447
  const named = /\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*(?::[^=]*)?=\s*(?:async\s*)?$/.exec(before) ?? /\bfunction\s*\*?\s*([A-Za-z_$][\w$]*)\s*(?:<[^<>]*>)?\s*$/.exec(before);
25868
26448
  const where = `${fr.f.rel}:${lineAt2(fr.text, fn.open)}`;
25869
26449
  const name = named ? named[1] : "(anonymous)";
25870
- const via = { name, where, label: label2, wrapperClaim };
26450
+ const via = { name, where, label: label2, wrapperClaims };
25871
26451
  const cnj = (at, offset, note) => scan.cnj.push({
25872
26452
  file: at.f.rel,
25873
26453
  line: lineAt2(at.text, offset),
@@ -26010,11 +26590,15 @@ function scanS28(tree) {
26010
26590
  const hit = ACTOR_SET_RE.exec(text);
26011
26591
  if (hit) for (const s of hit[2].matchAll(/["'`]([\w/]+:[\w]+)["'`]/g)) actorDoors.add(s[1]);
26012
26592
  }
26593
+ const acceptedBy = (door, forwarded) => {
26594
+ const info = doors?.get(door);
26595
+ return [...forwarded].filter((c) => info === void 0 || info.claims.includes(c));
26596
+ };
26013
26597
  const judge2 = (text, m, at, door, argText2, tool, site) => {
26014
26598
  const region = m.slice(tool.start, at);
26015
26599
  const regionRaw = text.slice(tool.start, at);
26016
26600
  const guard = GUARD_RE.test(region) || GUARD_RE.test(regionRaw);
26017
- let direct = CLAIM_TOKEN.test(argText2);
26601
+ let direct = acceptedBy(door, claimsIn(argText2)).length > 0;
26018
26602
  let viaHelper;
26019
26603
  let virtual = argText2;
26020
26604
  const bare = /^\s*([A-Za-z_$][\w$]*)\s*$/.exec(argText2);
@@ -26026,7 +26610,7 @@ function scanS28(tree) {
26026
26610
  const c = matchClose2(region, region.lastIndexOf("(", o));
26027
26611
  pieces.push(region.slice(o, c < 0 ? o + 400 : c));
26028
26612
  }
26029
- for (const a of region.matchAll(new RegExp(`\\b${v}\\.verified(?:Org|Person|Actor)\\b`, "g")))
26613
+ for (const a of region.matchAll(new RegExp(`\\b${v}\\.verified[A-Z][a-z]+\\b`, "g")))
26030
26614
  pieces.push(a[0]);
26031
26615
  const decl = new RegExp(`\\b(?:const|let)\\s+${v}\\b[^=]*=\\s*\\{`).exec(region);
26032
26616
  if (decl) {
@@ -26035,21 +26619,23 @@ function scanS28(tree) {
26035
26619
  pieces.push(region.slice(o, c < 0 ? o + 600 : c + 1));
26036
26620
  }
26037
26621
  virtual = pieces.join("\n");
26038
- direct = CLAIM_TOKEN.test(virtual);
26622
+ direct = acceptedBy(door, claimsIn(virtual)).length > 0;
26039
26623
  }
26040
26624
  if (!direct) {
26041
26625
  for (const sp of virtual.matchAll(/\.\.\.\s*([A-Za-z_$][\w$]*)/g)) {
26042
26626
  const h = readHelper(sp[1], files);
26043
- if (h.forwards) {
26044
- viaHelper = h;
26627
+ const matched = acceptedBy(door, h.claims);
26628
+ if (matched.length > 0) {
26629
+ viaHelper = { ...h, matched };
26045
26630
  break;
26046
26631
  }
26047
26632
  }
26048
26633
  if (!viaHelper) {
26049
26634
  for (const sp of virtual.matchAll(/\b([A-Za-z_$][\w$]*)\s*\(\s*\)/g)) {
26050
26635
  const h = readHelper(sp[1], files);
26051
- if (h.forwards) {
26052
- viaHelper = h;
26636
+ const matched = acceptedBy(door, h.claims);
26637
+ if (matched.length > 0) {
26638
+ viaHelper = { ...h, matched };
26053
26639
  break;
26054
26640
  }
26055
26641
  }
@@ -26061,11 +26647,32 @@ function scanS28(tree) {
26061
26647
  }
26062
26648
  if (viaHelper) {
26063
26649
  if (viaHelper.optional && !guard) {
26064
- scan.violate.push(
26065
- site(
26066
- "forwards its claim through an optional helper (it returns {} when the bearer holds none) and no refusal precedes the call in the handler: a bearer with no resolvable organisation is sent claimless"
26067
- )
26068
- );
26650
+ const info2 = doors?.get(door);
26651
+ if (!doors || !info2) {
26652
+ scan.cnj.push(
26653
+ site(
26654
+ `forwards its claim through an optional helper with no refusal before the call, and the source of the door ${door} is not available to show whether it refuses a call without the claim (${doors ? `not defined in the supplied backend (${backendRoot})${unreadNote}` : "no backend source found"})`
26655
+ )
26656
+ );
26657
+ } else if (info2.refusesClaimless) {
26658
+ scan.conform.push(
26659
+ site(
26660
+ "forwards the verified claim through an optional helper and the door's own source refuses a call that carries none"
26661
+ )
26662
+ );
26663
+ } else if (info2.unfollowed.length > 0) {
26664
+ scan.cnj.push(
26665
+ site(
26666
+ `forwards its claim through an optional helper with no refusal before the call; the door ${door} shows no refusal of a claimless service-account call in the source this scan read, and it calls ${info2.unfollowed.join(", ")}, which this scan does not read and which could hold the refusal`
26667
+ )
26668
+ );
26669
+ } else {
26670
+ scan.violate.push(
26671
+ site(
26672
+ "forwards its claim through an optional helper (it returns {} when the bearer holds none), no refusal precedes the call in the handler, and the door's own source shows no branch that refuses a call without the claim: a bearer with no resolvable claim is sent claimless and served"
26673
+ )
26674
+ );
26675
+ }
26069
26676
  } else {
26070
26677
  scan.conform.push(
26071
26678
  site(
@@ -26119,13 +26726,17 @@ function scanS28(tree) {
26119
26726
  tool: tool.name ?? via.label,
26120
26727
  note: note + where
26121
26728
  });
26122
- if (via.wrapperClaim) {
26729
+ const added = acceptedBy(door, via.wrapperClaims);
26730
+ if (added.length > 0) {
26123
26731
  scan.conform.push(
26124
- site(`forwards the verified claim: the fetcher ${via.name} adds it to every call`)
26732
+ site(
26733
+ `forwards the verified claim: the fetcher ${via.name} adds ${added.join(", ")}, which this door accepts`
26734
+ )
26125
26735
  );
26126
26736
  return;
26127
26737
  }
26128
- judge2(fr.text, fr.m, at, door, argText2, tool, site);
26738
+ const addedNone = via.wrapperClaims.size > 0 ? `; the fetcher ${via.name} adds ${[...via.wrapperClaims].join(", ")}, none of which this door accepts` : "";
26739
+ judge2(fr.text, fr.m, at, door, argText2, tool, (note) => site(note + addedNone));
26129
26740
  });
26130
26741
  for (const { f, text, m } of files) {
26131
26742
  for (let hit = CALL_RE2.exec(m); hit; hit = CALL_RE2.exec(m)) {
@@ -29195,7 +29806,7 @@ function readDoorAccess(backendRoot, unread2) {
29195
29806
  const c = o < 0 ? -1 : matchClose2(m, o);
29196
29807
  return c < 0 ? void 0 : text.slice(o, c + 1);
29197
29808
  };
29198
- const walk3 = (body, seen, depth) => {
29809
+ const walk4 = (body, seen, depth) => {
29199
29810
  for (const h of body.matchAll(/\bdb\s*\.\s*insert\s*\(\s*["'`](\w+)["'`]/g))
29200
29811
  acc.writes.add(h[1]);
29201
29812
  for (const h of body.matchAll(/\bdb\s*\.\s*query\s*\(\s*["'`](\w+)["'`]/g))
@@ -29209,10 +29820,10 @@ function readDoorAccess(backendRoot, unread2) {
29209
29820
  if (seen.has(c[1])) continue;
29210
29821
  seen.add(c[1]);
29211
29822
  const sub = fnBodyRaw(c[1]);
29212
- if (sub) walk3(sub, seen, depth + 1);
29823
+ if (sub) walk4(sub, seen, depth + 1);
29213
29824
  }
29214
29825
  };
29215
- walk3(raw, /* @__PURE__ */ new Set([hit[1]]), 0);
29826
+ walk4(raw, /* @__PURE__ */ new Set([hit[1]]), 0);
29216
29827
  out.set(`${module}:${hit[1]}`, acc);
29217
29828
  }
29218
29829
  }
@@ -33916,7 +34527,7 @@ var s49ServerMetadata = {
33916
34527
  // src/detectors/s50-served-discovery.ts
33917
34528
  var ID16 = "S50 served-discovery";
33918
34529
  var RULE17 = "S-50";
33919
- function pathOf(url) {
34530
+ function pathOf2(url) {
33920
34531
  try {
33921
34532
  return new URL(url).pathname;
33922
34533
  } catch {
@@ -33936,23 +34547,23 @@ function judgeCards(cards, v) {
33936
34547
  const served = cards.filter((c) => c.status === 200 && c.json);
33937
34548
  const noAnswer = cards.filter((c) => c.status === void 0);
33938
34549
  const good = served.find((c) => cardGaps(c.json).length === 0);
33939
- if (good) return v.ok.push(`server card at ${pathOf(good.url)}`);
34550
+ if (good) return v.ok.push(`server card at ${pathOf2(good.url)}`);
33940
34551
  if (served.length > 0) {
33941
34552
  for (const c of served)
33942
34553
  v.red.push(
33943
- `the card at ${pathOf(c.url)} lacks ${cardGaps(c.json).join(", ")}`
34554
+ `the card at ${pathOf2(c.url)} lacks ${cardGaps(c.json).join(", ")}`
33944
34555
  );
33945
34556
  return;
33946
34557
  }
33947
- const seen = cards.filter((c) => c.status !== void 0).map((c) => `${pathOf(c.url)} ${c.status}${c.status === 200 ? " (not JSON)" : ""}`);
34558
+ const seen = cards.filter((c) => c.status !== void 0).map((c) => `${pathOf2(c.url)} ${c.status}${c.status === 200 ? " (not JSON)" : ""}`);
33948
34559
  if (noAnswer.length > 0 && seen.length === 0)
33949
34560
  return v.unread.push(
33950
- `no card candidate answered: ${noAnswer.map((c) => `${pathOf(c.url)} ${c.detail ?? "no answer"}`).join(", ")}`
34561
+ `no card candidate answered: ${noAnswer.map((c) => `${pathOf2(c.url)} ${c.detail ?? "no answer"}`).join(", ")}`
33951
34562
  );
33952
34563
  v.red.push(`no server card served (${seen.join(", ")})`);
33953
34564
  if (noAnswer.length > 0)
33954
34565
  v.unread.push(
33955
- `card candidates unanswered: ${noAnswer.map((c) => `${pathOf(c.url)} ${c.detail ?? ""}`).join(", ")}`
34566
+ `card candidates unanswered: ${noAnswer.map((c) => `${pathOf2(c.url)} ${c.detail ?? ""}`).join(", ")}`
33956
34567
  );
33957
34568
  }
33958
34569
  function judgeLanding(landing, v) {
@@ -34045,7 +34656,7 @@ var s50ServedDiscovery = {
34045
34656
  };
34046
34657
 
34047
34658
  // src/detectors/s51-served-output.ts
34048
- import * as ts2 from "typescript";
34659
+ import * as ts5 from "typescript";
34049
34660
 
34050
34661
  // src/detectors/jsonSchemaCheck.ts
34051
34662
  var ANNOTATIONS = /* @__PURE__ */ new Set([
@@ -34395,15 +35006,15 @@ function schemaCheckControls() {
34395
35006
  }
34396
35007
 
34397
35008
  // src/detectors/outputContract.ts
34398
- import * as ts from "typescript";
35009
+ import * as ts4 from "typescript";
34399
35010
  var lineOfPos = (sf, pos) => sf.getLineAndCharacterOfPosition(pos).line + 1;
34400
35011
  var startLine = (n) => lineOfPos(n.getSourceFile(), n.getStart(n.getSourceFile()));
34401
35012
  function isFunctionLikeExpr(e) {
34402
- return ts.isArrowFunction(e) || ts.isFunctionExpression(e);
35013
+ return ts4.isArrowFunction(e) || ts4.isFunctionExpression(e);
34403
35014
  }
34404
35015
  var unwrapExpr = (e) => {
34405
35016
  let x = e;
34406
- while (ts.isParenthesizedExpression(x) || ts.isAsExpression(x) || ts.isSatisfiesExpression(x) || ts.isNonNullExpression(x) || ts.isAwaitExpression(x) || ts.isTypeAssertionExpression(x))
35017
+ while (ts4.isParenthesizedExpression(x) || ts4.isAsExpression(x) || ts4.isSatisfiesExpression(x) || ts4.isNonNullExpression(x) || ts4.isAwaitExpression(x) || ts4.isTypeAssertionExpression(x))
34407
35018
  x = x.expression;
34408
35019
  return x;
34409
35020
  };
@@ -34411,10 +35022,10 @@ function sameFileFunction(sf, name) {
34411
35022
  let found;
34412
35023
  const visit = (n) => {
34413
35024
  if (found) return;
34414
- if (ts.isFunctionDeclaration(n) && n.name?.text === name && n.body) found = n;
34415
- else if (ts.isVariableDeclaration(n) && ts.isIdentifier(n.name) && n.name.text === name && n.initializer && isFunctionLikeExpr(unwrapExpr(n.initializer)))
35025
+ if (ts4.isFunctionDeclaration(n) && n.name?.text === name && n.body) found = n;
35026
+ else if (ts4.isVariableDeclaration(n) && ts4.isIdentifier(n.name) && n.name.text === name && n.initializer && isFunctionLikeExpr(unwrapExpr(n.initializer)))
34416
35027
  found = unwrapExpr(n.initializer);
34417
- else ts.forEachChild(n, visit);
35028
+ else ts4.forEachChild(n, visit);
34418
35029
  };
34419
35030
  visit(sf);
34420
35031
  return found;
@@ -34424,25 +35035,25 @@ function completes(stmts) {
34424
35035
  return stmtCompletes(stmts[stmts.length - 1]);
34425
35036
  }
34426
35037
  function stmtCompletes(s) {
34427
- if (ts.isReturnStatement(s) || ts.isThrowStatement(s)) return false;
34428
- if (ts.isBlock(s)) return completes(s.statements);
34429
- if (ts.isIfStatement(s))
35038
+ if (ts4.isReturnStatement(s) || ts4.isThrowStatement(s)) return false;
35039
+ if (ts4.isBlock(s)) return completes(s.statements);
35040
+ if (ts4.isIfStatement(s))
34430
35041
  return !s.elseStatement || stmtCompletes(s.thenStatement) || stmtCompletes(s.elseStatement);
34431
- if (ts.isTryStatement(s)) {
35042
+ if (ts4.isTryStatement(s)) {
34432
35043
  if (s.finallyBlock && !completes(s.finallyBlock.statements)) return false;
34433
35044
  return completes(s.tryBlock.statements) || (s.catchClause ? completes(s.catchClause.block.statements) : false);
34434
35045
  }
34435
- if (ts.isSwitchStatement(s)) {
35046
+ if (ts4.isSwitchStatement(s)) {
34436
35047
  const clauses = s.caseBlock.clauses;
34437
- if (!clauses.some((c) => ts.isDefaultClause(c))) return true;
35048
+ if (!clauses.some((c) => ts4.isDefaultClause(c))) return true;
34438
35049
  return clauses.some((c) => c.statements.length === 0 || completes(c.statements));
34439
35050
  }
34440
35051
  return true;
34441
35052
  }
34442
35053
  function collectReturns(body, sf, rel2, out, inCatch = false) {
34443
35054
  const visit = (n, catching) => {
34444
- if (n !== body && ts.isFunctionLike(n)) return;
34445
- if (ts.isReturnStatement(n)) {
35055
+ if (n !== body && ts4.isFunctionLike(n)) return;
35056
+ if (ts4.isReturnStatement(n)) {
34446
35057
  out.push({
34447
35058
  anchor: `${rel2}:${startLine(n)}`,
34448
35059
  ...n.expression ? { expr: n.expression } : {},
@@ -34451,11 +35062,11 @@ function collectReturns(body, sf, rel2, out, inCatch = false) {
34451
35062
  });
34452
35063
  return;
34453
35064
  }
34454
- if (ts.isCatchClause(n)) {
35065
+ if (ts4.isCatchClause(n)) {
34455
35066
  visit(n.block, true);
34456
35067
  return;
34457
35068
  }
34458
- ts.forEachChild(n, (c) => visit(c, catching));
35069
+ ts4.forEachChild(n, (c) => visit(c, catching));
34459
35070
  };
34460
35071
  visit(body, inCatch);
34461
35072
  void sf;
@@ -34464,7 +35075,7 @@ function functionReturns(fn, sf, rel2) {
34464
35075
  const out = [];
34465
35076
  const body = fn.body;
34466
35077
  if (!body) return out;
34467
- if (!ts.isBlock(body)) {
35078
+ if (!ts4.isBlock(body)) {
34468
35079
  out.push({
34469
35080
  anchor: `${rel2}:${startLine(body)}`,
34470
35081
  expr: body,
@@ -34488,19 +35099,19 @@ function registrationCall(sf, line, name) {
34488
35099
  const a = startLine(n);
34489
35100
  const b = lineOfPos(sf, n.getEnd());
34490
35101
  if (a > line || b < line) return;
34491
- if (ts.isCallExpression(n)) {
35102
+ if (ts4.isCallExpression(n)) {
34492
35103
  const names2 = n.arguments.some((arg) => {
34493
35104
  const u = unwrapExpr(arg);
34494
- if (ts.isStringLiteralLike(u)) return u.text === name;
34495
- return (ts.isIdentifier(u) || ts.isPropertyAccessExpression(u)) && startLine(u) === line;
35105
+ if (ts4.isStringLiteralLike(u)) return u.text === name;
35106
+ return (ts4.isIdentifier(u) || ts4.isPropertyAccessExpression(u)) && startLine(u) === line;
34496
35107
  });
34497
35108
  if (names2 && n.arguments.some((arg) => {
34498
35109
  const x = unwrapExpr(arg);
34499
- return isFunctionLikeExpr(x) || ts.isIdentifier(x) || ts.isCallExpression(x);
35110
+ return isFunctionLikeExpr(x) || ts4.isIdentifier(x) || ts4.isCallExpression(x);
34500
35111
  }))
34501
35112
  best = n;
34502
35113
  }
34503
- ts.forEachChild(n, visit);
35114
+ ts4.forEachChild(n, visit);
34504
35115
  };
34505
35116
  visit(sf);
34506
35117
  return best;
@@ -34509,9 +35120,9 @@ function caseClause(sf, name) {
34509
35120
  let found;
34510
35121
  const visit = (n) => {
34511
35122
  if (found) return;
34512
- if (ts.isCaseClause(n) && ts.isStringLiteralLike(n.expression) && n.expression.text === name)
35123
+ if (ts4.isCaseClause(n) && ts4.isStringLiteralLike(n.expression) && n.expression.text === name)
34513
35124
  found = n;
34514
- else ts.forEachChild(n, visit);
35125
+ else ts4.forEachChild(n, visit);
34515
35126
  };
34516
35127
  visit(sf);
34517
35128
  return found;
@@ -34541,10 +35152,10 @@ function readHandler(tree, tool) {
34541
35152
  if (call) {
34542
35153
  const last = [...call.arguments].reverse().find((a) => {
34543
35154
  const x = unwrapExpr(a);
34544
- return isFunctionLikeExpr(x) || ts.isIdentifier(x) || ts.isCallExpression(x) && x.arguments.some((w) => isFunctionLikeExpr(unwrapExpr(w)));
35155
+ return isFunctionLikeExpr(x) || ts4.isIdentifier(x) || ts4.isCallExpression(x) && x.arguments.some((w) => isFunctionLikeExpr(unwrapExpr(w)));
34545
35156
  });
34546
35157
  let u = last ? unwrapExpr(last) : void 0;
34547
- if (u && ts.isCallExpression(u))
35158
+ if (u && ts4.isCallExpression(u))
34548
35159
  u = [...u.arguments].map(unwrapExpr).reverse().find(isFunctionLikeExpr);
34549
35160
  if (u && isFunctionLikeExpr(u))
34550
35161
  return {
@@ -34554,7 +35165,7 @@ function readHandler(tree, tool) {
34554
35165
  sf,
34555
35166
  file
34556
35167
  };
34557
- if (u && ts.isIdentifier(u)) {
35168
+ if (u && ts4.isIdentifier(u)) {
34558
35169
  const fn = sameFileFunction(sf, u.text);
34559
35170
  if (fn)
34560
35171
  return {
@@ -34612,20 +35223,20 @@ function productRegistrations(tree) {
34612
35223
  function returnedValues(expr, sf, depth = 0) {
34613
35224
  if (expr === void 0) return [{ kind: "nullish", form: "undefined" }];
34614
35225
  const e = unwrapExpr(expr);
34615
- if (e.kind === ts.SyntaxKind.NullKeyword) return [{ kind: "nullish", form: "null" }];
34616
- if (ts.isIdentifier(e) && e.text === "undefined") return [{ kind: "nullish", form: "undefined" }];
34617
- if (ts.isVoidExpression(e)) return [{ kind: "nullish", form: "void" }];
34618
- if (ts.isObjectLiteralExpression(e)) return [{ kind: "object", node: e }];
34619
- if (ts.isConditionalExpression(e))
35226
+ if (e.kind === ts4.SyntaxKind.NullKeyword) return [{ kind: "nullish", form: "null" }];
35227
+ if (ts4.isIdentifier(e) && e.text === "undefined") return [{ kind: "nullish", form: "undefined" }];
35228
+ if (ts4.isVoidExpression(e)) return [{ kind: "nullish", form: "void" }];
35229
+ if (ts4.isObjectLiteralExpression(e)) return [{ kind: "object", node: e }];
35230
+ if (ts4.isConditionalExpression(e))
34620
35231
  return [...returnedValues(e.whenTrue, sf, depth), ...returnedValues(e.whenFalse, sf, depth)];
34621
35232
  if (depth >= 4)
34622
35233
  return [{ kind: "unread", form: `\`${e.getText(sf).slice(0, 60)}\` (followed too deep)` }];
34623
- if (ts.isIdentifier(e)) {
35234
+ if (ts4.isIdentifier(e)) {
34624
35235
  const init = constInitOf(e);
34625
35236
  if (init) return returnedValues(init, sf, depth + 1).filter((v) => v.kind !== "nullish");
34626
35237
  return [{ kind: "unread", form: `identifier \`${e.text}\` not bound to a const in reach` }];
34627
35238
  }
34628
- if (ts.isCallExpression(e) && ts.isIdentifier(e.expression)) {
35239
+ if (ts4.isCallExpression(e) && ts4.isIdentifier(e.expression)) {
34629
35240
  const fn = sameFileFunction(sf, e.expression.text);
34630
35241
  if (fn) {
34631
35242
  const out = [];
@@ -34641,11 +35252,11 @@ function returnedValues(expr, sf, depth = 0) {
34641
35252
  }
34642
35253
  function constInitOf(id) {
34643
35254
  for (let x = id.parent; x; x = x.parent) {
34644
- if (!(ts.isBlock(x) || ts.isSourceFile(x))) continue;
35255
+ if (!(ts4.isBlock(x) || ts4.isSourceFile(x))) continue;
34645
35256
  for (const st of x.statements) {
34646
- if (!ts.isVariableStatement(st) || !(st.declarationList.flags & ts.NodeFlags.Const)) continue;
35257
+ if (!ts4.isVariableStatement(st) || !(st.declarationList.flags & ts4.NodeFlags.Const)) continue;
34647
35258
  for (const d of st.declarationList.declarations)
34648
- if (ts.isIdentifier(d.name) && d.name.text === id.text && d.initializer && d.getStart() < id.getStart())
35259
+ if (ts4.isIdentifier(d.name) && d.name.text === id.text && d.initializer && d.getStart() < id.getStart())
34649
35260
  return d.initializer;
34650
35261
  }
34651
35262
  }
@@ -34653,17 +35264,17 @@ function constInitOf(id) {
34653
35264
  }
34654
35265
  function prop(obj, name) {
34655
35266
  for (const p of obj.properties) {
34656
- if (ts.isPropertyAssignment(p) && (ts.isIdentifier(p.name) || ts.isStringLiteralLike(p.name)) && p.name.text === name)
35267
+ if (ts4.isPropertyAssignment(p) && (ts4.isIdentifier(p.name) || ts4.isStringLiteralLike(p.name)) && p.name.text === name)
34657
35268
  return { kind: "value", value: p.initializer };
34658
- if (ts.isShorthandPropertyAssignment(p) && p.name.text === name)
35269
+ if (ts4.isShorthandPropertyAssignment(p) && p.name.text === name)
34659
35270
  return { kind: "shorthand", ident: p.name };
34660
35271
  }
34661
- if (obj.properties.some((p) => ts.isSpreadAssignment(p))) return { kind: "spread" };
35272
+ if (obj.properties.some((p) => ts4.isSpreadAssignment(p))) return { kind: "spread" };
34662
35273
  return { kind: "absent" };
34663
35274
  }
34664
35275
  function isErrorObject(obj) {
34665
35276
  const p = prop(obj, "isError");
34666
- return p.kind === "value" && p.value.kind === ts.SyntaxKind.TrueKeyword;
35277
+ return p.kind === "value" && p.value.kind === ts4.SyntaxKind.TrueKeyword;
34667
35278
  }
34668
35279
  function servedToolCalls(id, rule, runtime) {
34669
35280
  const anchor = `${runtime.root} (served)`;
@@ -34720,42 +35331,42 @@ var ID17 = "S51 served-output";
34720
35331
  var RULE18 = "S-51";
34721
35332
  var isNullish = (e) => {
34722
35333
  let x = e;
34723
- while (ts2.isParenthesizedExpression(x) || ts2.isAsExpression(x)) x = x.expression;
34724
- return x.kind === ts2.SyntaxKind.NullKeyword || ts2.isIdentifier(x) && x.text === "undefined" || ts2.isVoidExpression(x);
35334
+ while (ts5.isParenthesizedExpression(x) || ts5.isAsExpression(x)) x = x.expression;
35335
+ return x.kind === ts5.SyntaxKind.NullKeyword || ts5.isIdentifier(x) && x.text === "undefined" || ts5.isVoidExpression(x);
34725
35336
  };
34726
35337
  var strip = (e) => {
34727
35338
  let x = e;
34728
- while (ts2.isParenthesizedExpression(x) || ts2.isAsExpression(x) || ts2.isSatisfiesExpression(x))
35339
+ while (ts5.isParenthesizedExpression(x) || ts5.isAsExpression(x) || ts5.isSatisfiesExpression(x))
34729
35340
  x = x.expression;
34730
35341
  return x;
34731
35342
  };
34732
- var isOutputKey = (n) => (ts2.isIdentifier(n) || ts2.isStringLiteralLike(n)) && n.text === "outputSchema";
35343
+ var isOutputKey = (n) => (ts5.isIdentifier(n) || ts5.isStringLiteralLike(n)) && n.text === "outputSchema";
34733
35344
  var objectHasOutput = (e) => {
34734
35345
  const x = strip(e);
34735
- return ts2.isObjectLiteralExpression(x) && x.properties.some(
34736
- (p) => (ts2.isPropertyAssignment(p) || ts2.isShorthandPropertyAssignment(p)) && isOutputKey(p.name)
35346
+ return ts5.isObjectLiteralExpression(x) && x.properties.some(
35347
+ (p) => (ts5.isPropertyAssignment(p) || ts5.isShorthandPropertyAssignment(p)) && isOutputKey(p.name)
34737
35348
  );
34738
35349
  };
34739
35350
  var LOGICAL = /* @__PURE__ */ new Set([
34740
- ts2.SyntaxKind.AmpersandAmpersandToken,
34741
- ts2.SyntaxKind.BarBarToken,
34742
- ts2.SyntaxKind.QuestionQuestionToken
35351
+ ts5.SyntaxKind.AmpersandAmpersandToken,
35352
+ ts5.SyntaxKind.BarBarToken,
35353
+ ts5.SyntaxKind.QuestionQuestionToken
34743
35354
  ]);
34744
35355
  function branches(e) {
34745
35356
  const x = strip(e);
34746
- if (ts2.isConditionalExpression(x)) return [x.whenTrue, x.whenFalse];
34747
- if (ts2.isBinaryExpression(x) && LOGICAL.has(x.operatorToken.kind)) {
34748
- if (x.operatorToken.kind === ts2.SyntaxKind.AmpersandAmpersandToken)
34749
- return [ts2.factory.createIdentifier("undefined"), x.right];
35357
+ if (ts5.isConditionalExpression(x)) return [x.whenTrue, x.whenFalse];
35358
+ if (ts5.isBinaryExpression(x) && LOGICAL.has(x.operatorToken.kind)) {
35359
+ if (x.operatorToken.kind === ts5.SyntaxKind.AmpersandAmpersandToken)
35360
+ return [ts5.factory.createIdentifier("undefined"), x.right];
34750
35361
  return [x.left, x.right];
34751
35362
  }
34752
35363
  return void 0;
34753
35364
  }
34754
- var accessesOutput = (n) => ts2.isPropertyAccessExpression(n) && n.name.text === "outputSchema" || ts2.isElementAccessExpression(n) && ts2.isStringLiteralLike(n.argumentExpression) && n.argumentExpression.text === "outputSchema";
35365
+ var accessesOutput = (n) => ts5.isPropertyAccessExpression(n) && n.name.text === "outputSchema" || ts5.isElementAccessExpression(n) && ts5.isStringLiteralLike(n.argumentExpression) && n.argumentExpression.text === "outputSchema";
34755
35366
  function underCondition(n) {
34756
- for (let x = n.parent; x && !ts2.isFunctionLike(x) && !ts2.isSourceFile(x); x = x.parent) {
34757
- if (ts2.isIfStatement(x) || ts2.isConditionalExpression(x)) return true;
34758
- if (ts2.isBinaryExpression(x) && LOGICAL.has(x.operatorToken.kind)) return true;
35367
+ for (let x = n.parent; x && !ts5.isFunctionLike(x) && !ts5.isSourceFile(x); x = x.parent) {
35368
+ if (ts5.isIfStatement(x) || ts5.isConditionalExpression(x)) return true;
35369
+ if (ts5.isBinaryExpression(x) && LOGICAL.has(x.operatorToken.kind)) return true;
34759
35370
  }
34760
35371
  return false;
34761
35372
  }
@@ -34764,26 +35375,26 @@ function exemptionSites(sf, rel2) {
34764
35375
  const at = (n) => `${rel2}:${sf.getLineAndCharacterOfPosition(n.getStart(sf)).line + 1}`;
34765
35376
  const text = (n) => n.getText(sf).replace(/\s+/g, " ").slice(0, 120);
34766
35377
  const visit = (n) => {
34767
- if (ts2.isSpreadAssignment(n)) {
35378
+ if (ts5.isSpreadAssignment(n)) {
34768
35379
  const b = branches(n.expression);
34769
35380
  if (b?.some(objectHasOutput) && !b.every(objectHasOutput))
34770
35381
  out.push({ anchor: at(n), form: "X1", text: text(n) });
34771
- } else if (ts2.isPropertyAssignment(n) && isOutputKey(n.name)) {
35382
+ } else if (ts5.isPropertyAssignment(n) && isOutputKey(n.name)) {
34772
35383
  const b = branches(n.initializer);
34773
35384
  if (isNullish(n.initializer) || b?.some(isNullish))
34774
35385
  out.push({ anchor: at(n), form: "X2", text: text(n) });
34775
- } else if (ts2.isBinaryExpression(n) && n.operatorToken.kind === ts2.SyntaxKind.EqualsToken && accessesOutput(n.left) && (underCondition(n) || isNullish(n.right) || branches(n.right)?.some(isNullish))) {
35386
+ } else if (ts5.isBinaryExpression(n) && n.operatorToken.kind === ts5.SyntaxKind.EqualsToken && accessesOutput(n.left) && (underCondition(n) || isNullish(n.right) || branches(n.right)?.some(isNullish))) {
34776
35387
  out.push({ anchor: at(n), form: "X3", text: text(n) });
34777
- } else if (ts2.isDeleteExpression(n) && accessesOutput(strip(n.expression))) {
35388
+ } else if (ts5.isDeleteExpression(n) && accessesOutput(strip(n.expression))) {
34778
35389
  out.push({ anchor: at(n), form: "X3", text: text(n) });
34779
35390
  }
34780
- ts2.forEachChild(n, visit);
35391
+ ts5.forEachChild(n, visit);
34781
35392
  };
34782
35393
  visit(sf);
34783
35394
  return out;
34784
35395
  }
34785
35396
  function s51Controls() {
34786
- const sf = (code) => ts2.createSourceFile("c.ts", code, ts2.ScriptTarget.Latest, true, ts2.ScriptKind.TS);
35397
+ const sf = (code) => ts5.createSourceFile("c.ts", code, ts5.ScriptTarget.Latest, true, ts5.ScriptKind.TS);
34787
35398
  const red = [
34788
35399
  "f({ ...(s !== undefined ? { outputSchema: s } : {}) });",
34789
35400
  "f({ outputSchema: skip.has(n) ? undefined : s });",
@@ -34942,7 +35553,7 @@ var s51ServedOutput = {
34942
35553
  };
34943
35554
 
34944
35555
  // src/detectors/s52-no-null-success.ts
34945
- import * as ts3 from "typescript";
35556
+ import * as ts6 from "typescript";
34946
35557
  var ID18 = "S52 no-null-success";
34947
35558
  var RULE19 = "S-52";
34948
35559
  function nullReturns(tool, read) {
@@ -34970,13 +35581,13 @@ function nullReturns(tool, read) {
34970
35581
  const sc = prop(v.node, "structuredContent");
34971
35582
  if (sc.kind === "value") {
34972
35583
  const x = sc.value;
34973
- if (x.kind === ts3.SyntaxKind.NullKeyword || ts3.isIdentifier(x) && x.text === "undefined")
35584
+ if (x.kind === ts6.SyntaxKind.NullKeyword || ts6.isIdentifier(x) && x.text === "undefined")
34974
35585
  red.push({ tool, anchor: r.anchor, form: "N2 `structuredContent: null`" });
34975
- else if (ts3.isObjectLiteralExpression(x) && x.properties.length === 0)
35586
+ else if (ts6.isObjectLiteralExpression(x) && x.properties.length === 0)
34976
35587
  red.push({ tool, anchor: r.anchor, form: "N4 `structuredContent: {}`" });
34977
35588
  }
34978
35589
  const content = prop(v.node, "content");
34979
- if (content.kind === "value" && ts3.isArrayLiteralExpression(content.value) && content.value.elements.length === 0)
35590
+ if (content.kind === "value" && ts6.isArrayLiteralExpression(content.value) && content.value.elements.length === 0)
34980
35591
  red.push({ tool, anchor: r.anchor, form: "N5 `content: []`" });
34981
35592
  else if (content.kind === "absent")
34982
35593
  red.push({ tool, anchor: r.anchor, form: "N5 a result with no `content`" });
@@ -35109,24 +35720,24 @@ var s52NoNullSuccess = {
35109
35720
  };
35110
35721
 
35111
35722
  // src/detectors/s53-structured-not-text.ts
35112
- import * as ts4 from "typescript";
35723
+ import * as ts7 from "typescript";
35113
35724
  var ID19 = "S53 structured-not-text";
35114
35725
  var RULE20 = "S-53";
35115
35726
  function classifyTextExpr(e, sf, depth = 0) {
35116
35727
  let x = e;
35117
- while (ts4.isParenthesizedExpression(x) || ts4.isAsExpression(x)) x = x.expression;
35118
- if (ts4.isStringLiteral(x) || ts4.isNoSubstitutionTemplateLiteral(x)) return { kind: "none" };
35728
+ while (ts7.isParenthesizedExpression(x) || ts7.isAsExpression(x)) x = x.expression;
35729
+ if (ts7.isStringLiteral(x) || ts7.isNoSubstitutionTemplateLiteral(x)) return { kind: "none" };
35119
35730
  const t = x.getText(sf);
35120
- if (ts4.isCallExpression(x) && /^JSON\s*\.\s*stringify$/.test(x.expression.getText(sf)))
35731
+ if (ts7.isCallExpression(x) && /^JSON\s*\.\s*stringify$/.test(x.expression.getText(sf)))
35121
35732
  return { kind: "data", form: "T1 JSON.stringify(...) in the text" };
35122
- if (ts4.isTemplateExpression(x) || ts4.isBinaryExpression(x) && x.operatorToken.kind === ts4.SyntaxKind.PlusToken) {
35733
+ if (ts7.isTemplateExpression(x) || ts7.isBinaryExpression(x) && x.operatorToken.kind === ts7.SyntaxKind.PlusToken) {
35123
35734
  if (/\bJSON\s*\.\s*stringify\s*\(/.test(t))
35124
35735
  return { kind: "data", form: "T2 a serialized value inside the text" };
35125
35736
  if (/\.\s*(join|map)\s*\(/.test(t))
35126
35737
  return { kind: "data", form: "T2 a list joined into the text" };
35127
35738
  if (/\.\s*length\b/.test(t))
35128
35739
  return { kind: "data", form: "T2 a count interpolated into the text" };
35129
- const spans = ts4.isTemplateExpression(x) ? x.templateSpans.map((sp) => sp.expression) : [x.left, x.right];
35740
+ const spans = ts7.isTemplateExpression(x) ? x.templateSpans.map((sp) => sp.expression) : [x.left, x.right];
35130
35741
  const idSpan = spans.find(
35131
35742
  (sp) => /(?:^|\.)id$|[a-z0-9](?:Id|Ids|ID)$/.test(sp.getText(sf).trim())
35132
35743
  );
@@ -35135,7 +35746,7 @@ function classifyTextExpr(e, sf, depth = 0) {
35135
35746
  kind: "data",
35136
35747
  form: `T2 an identifier interpolated into the text (${idSpan.getText(sf).trim()})`
35137
35748
  };
35138
- if (ts4.isBinaryExpression(x)) {
35749
+ if (ts7.isBinaryExpression(x)) {
35139
35750
  const parts = [classifyTextExpr(x.left, sf, depth), classifyTextExpr(x.right, sf, depth)];
35140
35751
  return parts.find((p) => p.kind === "data") ?? parts.find((p) => p.kind === "unread") ?? { kind: "none" };
35141
35752
  }
@@ -35144,16 +35755,16 @@ function classifyTextExpr(e, sf, depth = 0) {
35144
35755
  form: `a template with interpolated values \`${t.replace(/\s+/g, " ").slice(0, 60)}\``
35145
35756
  };
35146
35757
  }
35147
- if (ts4.isCallExpression(x) && /\.\s*join$/.test(x.expression.getText(sf)))
35758
+ if (ts7.isCallExpression(x) && /\.\s*join$/.test(x.expression.getText(sf)))
35148
35759
  return { kind: "data", form: "T2 a list joined into the text" };
35149
- if (ts4.isConditionalExpression(x)) {
35760
+ if (ts7.isConditionalExpression(x)) {
35150
35761
  const parts = [
35151
35762
  classifyTextExpr(x.whenTrue, sf, depth),
35152
35763
  classifyTextExpr(x.whenFalse, sf, depth)
35153
35764
  ];
35154
35765
  return parts.find((p) => p.kind === "data") ?? parts.find((p) => p.kind === "unread") ?? { kind: "none" };
35155
35766
  }
35156
- if (ts4.isIdentifier(x) && depth < 2) {
35767
+ if (ts7.isIdentifier(x) && depth < 2) {
35157
35768
  const init = constInit(x);
35158
35769
  if (init) return classifyTextExpr(init, sf, depth + 1);
35159
35770
  }
@@ -35161,11 +35772,11 @@ function classifyTextExpr(e, sf, depth = 0) {
35161
35772
  }
35162
35773
  function constInit(id) {
35163
35774
  for (let p = id.parent; p; p = p.parent) {
35164
- if (!(ts4.isBlock(p) || ts4.isSourceFile(p))) continue;
35775
+ if (!(ts7.isBlock(p) || ts7.isSourceFile(p))) continue;
35165
35776
  for (const st of p.statements) {
35166
- if (!ts4.isVariableStatement(st) || !(st.declarationList.flags & ts4.NodeFlags.Const)) continue;
35777
+ if (!ts7.isVariableStatement(st) || !(st.declarationList.flags & ts7.NodeFlags.Const)) continue;
35167
35778
  for (const d of st.declarationList.declarations)
35168
- if (ts4.isIdentifier(d.name) && d.name.text === id.text && d.initializer && d.getStart() < id.getStart())
35779
+ if (ts7.isIdentifier(d.name) && d.name.text === id.text && d.initializer && d.getStart() < id.getStart())
35169
35780
  return d.initializer;
35170
35781
  }
35171
35782
  }
@@ -35174,11 +35785,11 @@ function constInit(id) {
35174
35785
  function textOnlyReturn(obj, sf) {
35175
35786
  const content = prop(obj, "content");
35176
35787
  if (content.kind === "absent") return { kind: "none" };
35177
- if (content.kind !== "value" || !ts4.isArrayLiteralExpression(content.value))
35788
+ if (content.kind !== "value" || !ts7.isArrayLiteralExpression(content.value))
35178
35789
  return { kind: "unread", form: "a `content` that is not an array literal" };
35179
35790
  const out = [];
35180
35791
  for (const el of content.value.elements) {
35181
- if (!ts4.isObjectLiteralExpression(el)) {
35792
+ if (!ts7.isObjectLiteralExpression(el)) {
35182
35793
  out.push({ kind: "unread", form: "a content block that is not an object literal" });
35183
35794
  continue;
35184
35795
  }
@@ -35422,7 +36033,7 @@ var s53StructuredNotText = {
35422
36033
  // src/detectors/s54-tools-tested.ts
35423
36034
  import { readFileSync as readFileSync26, readdirSync as readdirSync18, statSync as statSync24 } from "fs";
35424
36035
  import { join as join36, relative as relative17, sep as sep9 } from "path";
35425
- import * as ts5 from "typescript";
36036
+ import * as ts8 from "typescript";
35426
36037
  var ID20 = "S54 tools-tested";
35427
36038
  var RULE21 = "S-54";
35428
36039
  var TEST_DIR = /(^|\/)(test|tests|__tests__|spec|specs|e2e)\//;
@@ -35438,7 +36049,7 @@ function isTestFile(rel2) {
35438
36049
  function testFiles2(root) {
35439
36050
  const files = [];
35440
36051
  const unread2 = [];
35441
- const walk3 = (dir) => {
36052
+ const walk4 = (dir) => {
35442
36053
  let entries;
35443
36054
  try {
35444
36055
  entries = readdirSync18(dir);
@@ -35462,15 +36073,15 @@ function testFiles2(root) {
35462
36073
  continue;
35463
36074
  }
35464
36075
  if (st.isDirectory()) {
35465
- if (!NOT_TESTS.has(name)) walk3(full);
36076
+ if (!NOT_TESTS.has(name)) walk4(full);
35466
36077
  continue;
35467
36078
  }
35468
36079
  const rel2 = relative17(root, full).split(sep9).join("/");
35469
36080
  if (!st.isFile() || !isTestFile(rel2)) continue;
35470
36081
  try {
35471
36082
  const text = readFileSync26(full, "utf8");
35472
- const kind = /x$/.test(rel2) ? ts5.ScriptKind.TSX : /\.[cm]?js$/.test(rel2) ? ts5.ScriptKind.JS : ts5.ScriptKind.TS;
35473
- files.push({ rel: rel2, sf: ts5.createSourceFile(rel2, text, ts5.ScriptTarget.Latest, true, kind) });
36083
+ const kind = /x$/.test(rel2) ? ts8.ScriptKind.TSX : /\.[cm]?js$/.test(rel2) ? ts8.ScriptKind.JS : ts8.ScriptKind.TS;
36084
+ files.push({ rel: rel2, sf: ts8.createSourceFile(rel2, text, ts8.ScriptTarget.Latest, true, kind) });
35474
36085
  } catch (e) {
35475
36086
  unread2.push({
35476
36087
  anchor: rel2,
@@ -35479,40 +36090,40 @@ function testFiles2(root) {
35479
36090
  }
35480
36091
  }
35481
36092
  };
35482
- walk3(root);
36093
+ walk4(root);
35483
36094
  return { files, unread: unread2 };
35484
36095
  }
35485
36096
  var up = (n) => {
35486
36097
  let x = n;
35487
- while (x.parent && (ts5.isParenthesizedExpression(x.parent) || ts5.isAsExpression(x.parent) || ts5.isNonNullExpression(x.parent) || ts5.isAwaitExpression(x.parent) || ts5.isSatisfiesExpression(x.parent)))
36098
+ while (x.parent && (ts8.isParenthesizedExpression(x.parent) || ts8.isAsExpression(x.parent) || ts8.isNonNullExpression(x.parent) || ts8.isAwaitExpression(x.parent) || ts8.isSatisfiesExpression(x.parent)))
35488
36099
  x = x.parent;
35489
36100
  return x;
35490
36101
  };
35491
36102
  var calleeName = (c) => {
35492
36103
  const e = c.expression;
35493
- if (ts5.isIdentifier(e)) return e.text;
35494
- if (ts5.isPropertyAccessExpression(e)) return e.name.text;
36104
+ if (ts8.isIdentifier(e)) return e.text;
36105
+ if (ts8.isPropertyAccessExpression(e)) return e.name.text;
35495
36106
  return void 0;
35496
36107
  };
35497
- var propName = (p) => p.name && (ts5.isIdentifier(p.name) || ts5.isStringLiteralLike(p.name)) ? p.name.text : void 0;
36108
+ var propName = (p) => p.name && (ts8.isIdentifier(p.name) || ts8.isStringLiteralLike(p.name)) ? p.name.text : void 0;
35498
36109
  function invoked(access) {
35499
36110
  const a = up(access);
35500
36111
  const p = a.parent;
35501
36112
  if (!p) return false;
35502
- if (ts5.isCallExpression(p) && p.expression === a) return true;
35503
- if (ts5.isPropertyAccessExpression(p) && p.expression === a && ["handler", "callback"].includes(p.name.text)) {
36113
+ if (ts8.isCallExpression(p) && p.expression === a) return true;
36114
+ if (ts8.isPropertyAccessExpression(p) && p.expression === a && ["handler", "callback"].includes(p.name.text)) {
35504
36115
  const q = up(p).parent;
35505
- return !!q && ts5.isCallExpression(q) && up(q.expression) === up(p);
36116
+ return !!q && ts8.isCallExpression(q) && up(q.expression) === up(p);
35506
36117
  }
35507
- if (ts5.isVariableDeclaration(p) && p.initializer && up(p.initializer) === a && ts5.isIdentifier(p.name)) {
36118
+ if (ts8.isVariableDeclaration(p) && p.initializer && up(p.initializer) === a && ts8.isIdentifier(p.name)) {
35508
36119
  const bound = p.name.text;
35509
36120
  let scope2 = p;
35510
- while (scope2.parent && !ts5.isBlock(scope2) && !ts5.isSourceFile(scope2)) scope2 = scope2.parent;
36121
+ while (scope2.parent && !ts8.isBlock(scope2) && !ts8.isSourceFile(scope2)) scope2 = scope2.parent;
35511
36122
  let called = false;
35512
36123
  const visit = (n) => {
35513
36124
  if (called) return;
35514
- if (ts5.isIdentifier(n) && n.text === bound && n !== p.name && invoked(n)) called = true;
35515
- else ts5.forEachChild(n, visit);
36125
+ if (ts8.isIdentifier(n) && n.text === bound && n !== p.name && invoked(n)) called = true;
36126
+ else ts8.forEachChild(n, visit);
35516
36127
  };
35517
36128
  visit(scope2);
35518
36129
  return called;
@@ -35523,27 +36134,27 @@ function callsAt(e, helpers) {
35523
36134
  const x = up(e);
35524
36135
  const p = x.parent;
35525
36136
  if (!p) return false;
35526
- if (ts5.isPropertyAssignment(p) && p.initializer === x && propName(p) === "name" || ts5.isShorthandPropertyAssignment(p) && p.name === x && p.name.text === "name") {
36137
+ if (ts8.isPropertyAssignment(p) && p.initializer === x && propName(p) === "name" || ts8.isShorthandPropertyAssignment(p) && p.name === x && p.name.text === "name") {
35527
36138
  const obj = p.parent;
35528
36139
  const holder = up(obj).parent;
35529
- if (holder && ts5.isCallExpression(holder) && holder.arguments.some((a) => up(a) === up(obj)) && calleeName(holder) === "callTool")
36140
+ if (holder && ts8.isCallExpression(holder) && holder.arguments.some((a) => up(a) === up(obj)) && calleeName(holder) === "callTool")
35530
36141
  return true;
35531
- if (holder && ts5.isPropertyAssignment(holder) && propName(holder) === "params") {
36142
+ if (holder && ts8.isPropertyAssignment(holder) && propName(holder) === "params") {
35532
36143
  const req = holder.parent;
35533
36144
  return req.properties.some(
35534
- (q) => ts5.isPropertyAssignment(q) && propName(q) === "method" && ts5.isStringLiteralLike(q.initializer) && q.initializer.text === "tools/call"
36145
+ (q) => ts8.isPropertyAssignment(q) && propName(q) === "method" && ts8.isStringLiteralLike(q.initializer) && q.initializer.text === "tools/call"
35535
36146
  );
35536
36147
  }
35537
36148
  return false;
35538
36149
  }
35539
- if (ts5.isCallExpression(p) && p.arguments.some((a) => up(a) === x)) {
36150
+ if (ts8.isCallExpression(p) && p.arguments.some((a) => up(a) === x)) {
35540
36151
  const i = p.arguments.findIndex((a) => up(a) === x);
35541
- if (calleeName(p) === "get" && i === 0 && ts5.isPropertyAccessExpression(p.expression))
36152
+ if (calleeName(p) === "get" && i === 0 && ts8.isPropertyAccessExpression(p.expression))
35542
36153
  return invoked(p);
35543
36154
  const name = calleeName(p);
35544
36155
  return !!name && (helpers.get(name)?.has(i) ?? false);
35545
36156
  }
35546
- if (ts5.isElementAccessExpression(p) && up(p.argumentExpression) === x) return invoked(p);
36157
+ if (ts8.isElementAccessExpression(p) && up(p.argumentExpression) === x) return invoked(p);
35547
36158
  return false;
35548
36159
  }
35549
36160
  function deriveHelpers(files) {
@@ -35551,10 +36162,10 @@ function deriveHelpers(files) {
35551
36162
  const fns = [];
35552
36163
  for (const { sf } of files) {
35553
36164
  const visit = (n) => {
35554
- if (ts5.isFunctionDeclaration(n) && n.name && n.body) fns.push({ name: n.name.text, fn: n });
35555
- else if (ts5.isVariableDeclaration(n) && ts5.isIdentifier(n.name) && n.initializer && (ts5.isArrowFunction(n.initializer) || ts5.isFunctionExpression(n.initializer)))
36165
+ if (ts8.isFunctionDeclaration(n) && n.name && n.body) fns.push({ name: n.name.text, fn: n });
36166
+ else if (ts8.isVariableDeclaration(n) && ts8.isIdentifier(n.name) && n.initializer && (ts8.isArrowFunction(n.initializer) || ts8.isFunctionExpression(n.initializer)))
35556
36167
  fns.push({ name: n.name.text, fn: n.initializer });
35557
- ts5.forEachChild(n, visit);
36168
+ ts8.forEachChild(n, visit);
35558
36169
  };
35559
36170
  visit(sf);
35560
36171
  }
@@ -35562,14 +36173,14 @@ function deriveHelpers(files) {
35562
36173
  let grew = false;
35563
36174
  for (const { name, fn } of fns) {
35564
36175
  fn.parameters.forEach((param, i) => {
35565
- if (!ts5.isIdentifier(param.name) || helpers.get(name)?.has(i)) return;
36176
+ if (!ts8.isIdentifier(param.name) || helpers.get(name)?.has(i)) return;
35566
36177
  const pname = param.name.text;
35567
36178
  let hit = false;
35568
36179
  const visit = (n) => {
35569
36180
  if (hit) return;
35570
- if (ts5.isIdentifier(n) && n.text === pname && n !== param.name && callsAt(n, helpers))
36181
+ if (ts8.isIdentifier(n) && n.text === pname && n !== param.name && callsAt(n, helpers))
35571
36182
  hit = true;
35572
- else ts5.forEachChild(n, visit);
36183
+ else ts8.forEachChild(n, visit);
35573
36184
  };
35574
36185
  if (fn.body) visit(fn.body);
35575
36186
  if (hit) {
@@ -35589,9 +36200,9 @@ function testCalls(files, tools) {
35589
36200
  const out = new Map(tools.map((t) => [t, []]));
35590
36201
  for (const { rel: rel2, sf } of files) {
35591
36202
  const visit = (n) => {
35592
- if ((ts5.isStringLiteral(n) || ts5.isNoSubstitutionTemplateLiteral(n)) && wanted.has(n.text) && callsAt(n, helpers))
36203
+ if ((ts8.isStringLiteral(n) || ts8.isNoSubstitutionTemplateLiteral(n)) && wanted.has(n.text) && callsAt(n, helpers))
35593
36204
  out.get(n.text)?.push(`${rel2}:${sf.getLineAndCharacterOfPosition(n.getStart(sf)).line + 1}`);
35594
- ts5.forEachChild(n, visit);
36205
+ ts8.forEachChild(n, visit);
35595
36206
  };
35596
36207
  visit(sf);
35597
36208
  }
@@ -35601,7 +36212,7 @@ function s54Controls() {
35601
36212
  const f = (code) => [
35602
36213
  {
35603
36214
  rel: "c.test.ts",
35604
- sf: ts5.createSourceFile("c.test.ts", code, ts5.ScriptTarget.Latest, true, ts5.ScriptKind.TS)
36215
+ sf: ts8.createSourceFile("c.test.ts", code, ts8.ScriptTarget.Latest, true, ts8.ScriptKind.TS)
35605
36216
  }
35606
36217
  ];
35607
36218
  const k = (code) => (testCalls(f(code), ["t"]).get("t") ?? []).length;
@@ -36576,10 +37187,10 @@ function v4ToBig(ip) {
36576
37187
  }
36577
37188
  function v6ToBig(ip) {
36578
37189
  let s = ip.toLowerCase();
36579
- const dotted = /(\d+\.\d+\.\d+\.\d+)$/.exec(s);
36580
- if (dotted) {
36581
- const v = v4ToBig(dotted[1]);
36582
- s = `${s.slice(0, -dotted[1].length)}${(v >> 16n).toString(16)}:${(v & 0xffffn).toString(16)}`;
37190
+ const dotted2 = /(\d+\.\d+\.\d+\.\d+)$/.exec(s);
37191
+ if (dotted2) {
37192
+ const v = v4ToBig(dotted2[1]);
37193
+ s = `${s.slice(0, -dotted2[1].length)}${(v >> 16n).toString(16)}:${(v & 0xffffn).toString(16)}`;
36583
37194
  }
36584
37195
  const [head, tail] = s.includes("::") ? s.split("::") : [s, void 0];
36585
37196
  const h = (head ?? "").split(":").filter((x) => x !== "");