@vantageos/mcp-doctor 0.11.2 → 0.13.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
@@ -649,7 +649,7 @@ function findDiskFiles(tree, pred) {
649
649
  const out = [];
650
650
  const refused = [];
651
651
  const base = baseOf(tree);
652
- const walk2 = (dir) => {
652
+ const walk3 = (dir) => {
653
653
  let entries;
654
654
  try {
655
655
  entries = readdirSync2(dir);
@@ -674,7 +674,7 @@ function findDiskFiles(tree, pred) {
674
674
  recordSkip(tree, full, base);
675
675
  continue;
676
676
  }
677
- walk2(full);
677
+ walk3(full);
678
678
  } else {
679
679
  const rel = relative2(base, full).split(sep2).join("/");
680
680
  if (!pred(name, rel)) continue;
@@ -696,7 +696,7 @@ function findDiskFiles(tree, pred) {
696
696
  }
697
697
  }
698
698
  };
699
- walk2(base);
699
+ walk3(base);
700
700
  return Object.assign(out, { refused });
701
701
  }
702
702
  function readText(path) {
@@ -767,7 +767,7 @@ function enclosingBlock(file, line, col, levels = 0) {
767
767
  }
768
768
 
769
769
  // src/detectors/standardPin.ts
770
- var STANDARD_PIN = "015053b7268125cf441d7555fecfe41f318a06ed";
770
+ var STANDARD_PIN = "c29f83d50781dcca5c99696dcbb5d19bb77ef33d";
771
771
 
772
772
  // src/detectors/dLocalIdentity.ts
773
773
  var CLOUD_IDENTITY_PACKAGE = "@vantageos/cloud-identity";
@@ -1827,9 +1827,9 @@ function resolveNameBindings(tree) {
1827
1827
  if (braceDepth <= 0) trackingObject = null;
1828
1828
  continue;
1829
1829
  }
1830
- const constString = raw.match(CONST_STRING_RE);
1831
- if (constString) {
1832
- bindings.set(constString[1], constString[2]);
1830
+ const constString2 = raw.match(CONST_STRING_RE);
1831
+ if (constString2) {
1832
+ bindings.set(constString2[1], constString2[2]);
1833
1833
  continue;
1834
1834
  }
1835
1835
  const objOpen = raw.match(CONST_OBJECT_OPEN_RE);
@@ -2808,15 +2808,15 @@ function failClosedOnUnscanned(d) {
2808
2808
  run(tree) {
2809
2809
  const r = d.run(tree);
2810
2810
  if (r.state !== "absent") return r;
2811
- const unread = (tree.unscannedSource ?? []).filter(
2811
+ const unread2 = (tree.unscannedSource ?? []).filter(
2812
2812
  (f) => isProductSource(f) && !/(^|\/)_?generated\//.test(f)
2813
2813
  );
2814
- if (unread.length === 0) return r;
2815
- const shown = unread.slice(0, 5).join(", ");
2816
- const reason = `${unread.length} JavaScript/module source file(s) are not scanned (${shown}${unread.length > 5 ? ", ..." : ""}): absence cannot be asserted from the TypeScript that was read (this run said: ${r.verdict})`;
2814
+ if (unread2.length === 0) return r;
2815
+ const shown = unread2.slice(0, 5).join(", ");
2816
+ const reason = `${unread2.length} JavaScript/module source file(s) are not scanned (${shown}${unread2.length > 5 ? ", ..." : ""}): absence cannot be asserted from the TypeScript that was read (this run said: ${r.verdict})`;
2817
2817
  return {
2818
2818
  id: r.id,
2819
- anchor: `${unread[0]}:1`,
2819
+ anchor: `${unread2[0]}:1`,
2820
2820
  state: "could-not-judge",
2821
2821
  verdict: `could not judge: ${reason}`,
2822
2822
  reason
@@ -3071,7 +3071,7 @@ function collect(base) {
3071
3071
  const out = [];
3072
3072
  const unmeasured = [];
3073
3073
  const relOf = (full) => relative3(base, full).split(sep3).join("/");
3074
- const walk2 = (dir, depth) => {
3074
+ const walk3 = (dir, depth) => {
3075
3075
  if (depth > 8) {
3076
3076
  unmeasured.push(`${relOf(dir)}/ (deeper than 8 levels, not walked)`);
3077
3077
  return;
@@ -3095,7 +3095,7 @@ function collect(base) {
3095
3095
  continue;
3096
3096
  }
3097
3097
  if (st.isDirectory()) {
3098
- if (!WALK_SKIP.has(name)) walk2(full, depth + 1);
3098
+ if (!WALK_SKIP.has(name)) walk3(full, depth + 1);
3099
3099
  } else if (candidate) {
3100
3100
  if (!st.isFile()) {
3101
3101
  unmeasured.push(`${rel} (not a regular file, not read)`);
@@ -3113,7 +3113,7 @@ function collect(base) {
3113
3113
  }
3114
3114
  }
3115
3115
  };
3116
- walk2(base, 0);
3116
+ walk3(base, 0);
3117
3117
  return { bundles: out, unmeasured };
3118
3118
  }
3119
3119
  var kb = (n) => `${(n / 1024).toFixed(1)} KB gz`;
@@ -3706,6 +3706,13 @@ function unwrapValue(file, line, col) {
3706
3706
  }
3707
3707
  return { kind: "ident", name: id[0], wrappers: [...wrappers, ...suffix.wrappers] };
3708
3708
  }
3709
+ function computedValueAt(file, line, col) {
3710
+ const rows = uncommentedLines(file);
3711
+ const end = afterClose(file, { line, col }, "[", "]");
3712
+ const c = end ? nextCode(file, end.line, end.col, 1) : null;
3713
+ if (!c || rows[c.line - 1][c.col] !== ":") return null;
3714
+ return { line: c.line, col: c.col + 1 };
3715
+ }
3709
3716
  function prevCodeText(file, line, col) {
3710
3717
  return textBefore(file, line, col, 200).trimEnd();
3711
3718
  }
@@ -3715,7 +3722,15 @@ function keyInBrace(file, line, col, name, form, out) {
3715
3722
  if (!enc || enc.ch !== "{") return;
3716
3723
  const ctx = braceContext(file, enc.line, enc.col);
3717
3724
  if (ctx.kind === "value") {
3718
- out.writes.push({ name, form, file, line, anchor, object: { line: enc.line, col: enc.col } });
3725
+ out.writes.push({
3726
+ name,
3727
+ form,
3728
+ file,
3729
+ line,
3730
+ col,
3731
+ anchor,
3732
+ object: { line: enc.line, col: enc.col }
3733
+ });
3719
3734
  } else if (ctx.kind === "unread") {
3720
3735
  out.unread.push({
3721
3736
  anchor,
@@ -3723,8 +3738,57 @@ function keyInBrace(file, line, col, name, form, out) {
3723
3738
  });
3724
3739
  }
3725
3740
  }
3741
+ function symbolConst(file, name) {
3742
+ const re = new RegExp(
3743
+ `\\bconst\\s+${name.replace(/[$]/g, "\\$&")}\\b[^=\\n]*=(?![=>])\\s*Symbol\\s*(?:\\.\\s*for\\s*)?\\(`
3744
+ );
3745
+ return uncommentedLines(file).some((row) => re.test(row));
3746
+ }
3747
+ function computedKeys(file, lineNo, names, out) {
3748
+ const raw = file.lines[lineNo - 1].raw;
3749
+ for (let col = raw.indexOf("["); col >= 0; col = raw.indexOf("[", col + 1)) {
3750
+ if (!isCodeAt(file, lineNo, col)) continue;
3751
+ if (!/[{,]$/.test(prevCodeText(file, lineNo, col))) continue;
3752
+ const b = balancedBlock(file, lineNo, col, "[", "]");
3753
+ const end = afterClose(file, { line: lineNo, col }, "[", "]");
3754
+ if (!b || !end) continue;
3755
+ const nx = nextCode(file, end.line, end.col, 1);
3756
+ const after = nx ? restOfLine(file, nx) : "";
3757
+ if (!after.startsWith(":") || after.startsWith("::")) continue;
3758
+ const expr = b.text.slice(1, -1).trim();
3759
+ const lit = expr.match(/^(["'`])((?:\\.|(?!\1)[^\\])*)\1$/);
3760
+ const anchor = `${file.rel}:${lineNo}`;
3761
+ if (lit && !(lit[1] === "`" && lit[2].includes("${"))) {
3762
+ if (names.includes(lit[2])) keyInBrace(file, lineNo, col, lit[2], "computed-key", out);
3763
+ continue;
3764
+ }
3765
+ if (/^[A-Za-z_$][\w$]*$/.test(expr) && symbolConst(file, expr)) continue;
3766
+ if (/^[A-Za-z_$][\w$]*$/.test(expr)) {
3767
+ const bound = constString(file, expr);
3768
+ if (bound.kind === "value") {
3769
+ if (bound.value !== null && names.includes(bound.value)) {
3770
+ keyInBrace(file, lineNo, col, bound.value, "computed-key", out);
3771
+ }
3772
+ continue;
3773
+ }
3774
+ }
3775
+ const enc = enclosingOpener(file, lineNo, col);
3776
+ if (!enc || enc.ch !== "{") continue;
3777
+ const ctx = braceContext(file, enc.line, enc.col);
3778
+ if (ctx.kind === "value" || ctx.kind === "unread") {
3779
+ out.computed.push({
3780
+ expr,
3781
+ file,
3782
+ line: lineNo,
3783
+ col,
3784
+ anchor,
3785
+ object: { line: enc.line, col: enc.col }
3786
+ });
3787
+ }
3788
+ }
3789
+ }
3726
3790
  function fieldWrites(tree, names) {
3727
- const out = { writes: [], unread: [] };
3791
+ const out = { writes: [], unread: [], computed: [] };
3728
3792
  const alt = names.map((n) => n.replace(/[$]/g, "\\$&")).join("|");
3729
3793
  const identRe = new RegExp(`(?<![\\w$])(${alt})(?![\\w$])`, "g");
3730
3794
  const quotedRe = new RegExp(`(["'])(${alt})\\1`, "g");
@@ -3746,6 +3810,7 @@ function fieldWrites(tree, names) {
3746
3810
  form: "member-assign",
3747
3811
  file,
3748
3812
  line: line.n,
3813
+ col,
3749
3814
  anchor: `${file.rel}:${line.n}`,
3750
3815
  base: base?.[1]
3751
3816
  });
@@ -3760,6 +3825,7 @@ function fieldWrites(tree, names) {
3760
3825
  keyInBrace(file, line.n, col, name, "shorthand", out);
3761
3826
  }
3762
3827
  }
3828
+ computedKeys(file, line.n, names, out);
3763
3829
  for (const m of line.raw.matchAll(quotedRe)) {
3764
3830
  const col = m.index ?? 0;
3765
3831
  if (!isCodeAt(file, line.n, col)) continue;
@@ -3774,6 +3840,7 @@ function fieldWrites(tree, names) {
3774
3840
  form: "bracket-assign",
3775
3841
  file,
3776
3842
  line: line.n,
3843
+ col,
3777
3844
  anchor: `${file.rel}:${line.n}`,
3778
3845
  base: base?.[1]
3779
3846
  });
@@ -3807,6 +3874,8 @@ function objectMembers(file, p) {
3807
3874
  }
3808
3875
  const k = s.match(/^(?:["'`]([^"'`]+)["'`]|([A-Za-z_$][\w$]*))\s*(?:\??:|\(|$)/);
3809
3876
  if (k) keys.add(k[1] ?? k[2]);
3877
+ const c = s.match(/^\[\s*(["'`])([^"'`$]+)\1\s*\]\s*:/);
3878
+ if (c) keys.add(c[2]);
3810
3879
  };
3811
3880
  for (let i = 0; i < text.length; i++) {
3812
3881
  const ch = text[i];
@@ -3833,6 +3902,107 @@ function objectMembers(file, p) {
3833
3902
  flush();
3834
3903
  return { keys, spreads };
3835
3904
  }
3905
+ function fieldValueAt(w) {
3906
+ if (w.form === "shorthand") return null;
3907
+ const rows = uncommentedLines(w.file);
3908
+ if (w.form === "computed-key") return computedValueAt(w.file, w.line, w.col);
3909
+ const delim = w.form === "key" || w.form === "quoted-key" ? ":" : "=";
3910
+ const skip = w.form === "bracket-assign" ? "]" : "";
3911
+ const start = w.form === "quoted-key" || w.form === "bracket-assign" ? 2 : 0;
3912
+ let p = nextCode(w.file, w.line, w.col + w.name.length + start, 1);
3913
+ if (p && skip && charAt(w.file, p) === skip) p = nextCode(w.file, p.line, p.col + 1, 1);
3914
+ if (!p || rows[p.line - 1][p.col] !== delim) return null;
3915
+ return { line: p.line, col: p.col + 1 };
3916
+ }
3917
+ function stringValueAt(file, line, col) {
3918
+ let p = nextCode(file, line, col);
3919
+ let parens = 0;
3920
+ while (p && charAt(file, p) === "(") {
3921
+ parens++;
3922
+ p = nextCode(file, p.line, p.col + 1);
3923
+ }
3924
+ if (!p) return { kind: "other", form: "no value" };
3925
+ const rest = restOfLine(file, p);
3926
+ if (/^(?:true|false|null|undefined)\b/.test(rest) || /^-?\d/.test(rest)) {
3927
+ return { kind: "not-string" };
3928
+ }
3929
+ const m = rest.match(/^(["'`])((?:\\.|(?!\1)[^\\])*)\1/);
3930
+ if (!m || m[1] === "`" && m[2].includes("${")) {
3931
+ return { kind: "other", form: `\`${exprText(file, p)}\`` };
3932
+ }
3933
+ const suffix = readSuffix(file, { line: p.line, col: p.col + m[0].length }, parens);
3934
+ if ("foreign" in suffix) {
3935
+ return { kind: "other", form: `the literal ${m[0]} followed by \`${suffix.foreign}\`` };
3936
+ }
3937
+ return { kind: "string", value: m[2] };
3938
+ }
3939
+ function identReturned(file, name) {
3940
+ const esc4 = name.replace(/[$]/g, "\\$&");
3941
+ const re = new RegExp(
3942
+ `(?:\\breturn|=>)\\s*(?:\\(\\s*)*${esc4}(?![\\w$])(?!\\s*(?:\\?\\.|\\.|\\(|\\[|=))`
3943
+ );
3944
+ return re.test(uncommentedLines(file).join("\n"));
3945
+ }
3946
+ function objectReturned(file, p, depth = 0) {
3947
+ if (depth > 16) return { kind: "unread", form: "an object nested deeper than 16 levels" };
3948
+ const before = textBefore(file, p.line, p.col).trimEnd();
3949
+ if (/\breturn$/.test(before)) return { kind: "returned", how: "return" };
3950
+ if (/=>$/.test(before)) return { kind: "returned", how: "arrow body" };
3951
+ if (/\bexport\s+default$/.test(before)) return { kind: "not-returned", how: "export default" };
3952
+ const decl = before.match(/\b(?:const|let|var)\s+([\w$]+)\s*(?::[^=;]*)?=$/);
3953
+ if (decl) {
3954
+ return identReturned(file, decl[1]) ? { kind: "returned", how: `\`${decl[1]}\` returned` } : { kind: "not-returned", how: `\`${decl[1]}\` never returned` };
3955
+ }
3956
+ if (/(?:^|[^=!<>])=$/.test(before)) return { kind: "not-returned", how: "assigned" };
3957
+ const outward = (why) => {
3958
+ const enc = enclosingOpener(file, p.line, p.col);
3959
+ if (!enc) return { kind: "unread", form: why };
3960
+ if (enc.ch === "(") {
3961
+ const head = textBefore(file, enc.line, enc.col).trimEnd();
3962
+ const isCall = /[\w$\])>]$/.test(head) && !/=>$/.test(head) && !/\b(?:return|yield|await|typeof|void|case|in|of|throw|default)$/.test(head);
3963
+ if (isCall) return { kind: "not-returned", how: "a call argument" };
3964
+ if (!before.endsWith("(")) return { kind: "unread", form: `${why} inside parentheses` };
3965
+ return objectReturned(file, enc, depth + 1);
3966
+ }
3967
+ if (enc.ch === "[") return objectReturned(file, enc, depth + 1);
3968
+ const ctx = braceContext(file, enc.line, enc.col);
3969
+ if (ctx.kind === "value") return objectReturned(file, enc, depth + 1);
3970
+ return { kind: "unread", form: why };
3971
+ };
3972
+ if (before.endsWith("(")) return outward("an object in parentheses");
3973
+ if (before.endsWith("...")) return outward("a spread");
3974
+ if (before.endsWith("[")) return outward("an array element");
3975
+ if (before.endsWith(",")) return outward("an element after a comma");
3976
+ if (before.endsWith(":")) {
3977
+ const colon = lastCodeChar(file, p);
3978
+ if (colon && colonIsTernary(file, colon.line, colon.col)) {
3979
+ return { kind: "unread", form: "a branch of a conditional" };
3980
+ }
3981
+ return outward("a key value");
3982
+ }
3983
+ return {
3984
+ kind: "unread",
3985
+ form: `an object after \`${before.slice(-30).trim()}\``
3986
+ };
3987
+ }
3988
+ function constString(file, name) {
3989
+ const one = { root: file.path, files: [file], packageJson: null, skippedDirs: [] };
3990
+ const re = new RegExp(`\\bconst\\s+${name.replace(/[$]/g, "\\$&")}\\b[^=\\n]*=(?![=>])\\s*`, "g");
3991
+ const site = codeSites(one, re)[0];
3992
+ if (!site) {
3993
+ return {
3994
+ kind: "unread",
3995
+ form: `the identifier \`${name}\`, bound by no same-file const`
3996
+ };
3997
+ }
3998
+ const v = stringValueAt(file, site.line.n, site.col + site.match[0].length);
3999
+ if (v.kind === "string") return { kind: "value", value: v.value };
4000
+ if (v.kind === "not-string") return { kind: "value", value: null };
4001
+ return {
4002
+ kind: "unread",
4003
+ form: `the identifier \`${name}\`, bound at ${site.anchor} to ${v.form}`
4004
+ };
4005
+ }
3836
4006
 
3837
4007
  // src/detectors/metaKeys.ts
3838
4008
  var KEY_IN_BLOCK_RE = /(["'`])([A-Za-z0-9_.-]+\/[^"'`\s]*)\1\s*:/g;
@@ -3995,6 +4165,18 @@ function collectNamespacedKeys(tree) {
3995
4165
  }
3996
4166
  if (tail.trimStart().startsWith("{") || tail.trim() === "") {
3997
4167
  readValue(tree, site.file, site.line.n, after, ctx, acc);
4168
+ continue;
4169
+ }
4170
+ const enc = enclosingOpener(site.file, site.line.n, site.col);
4171
+ if (!enc || enc.ch !== "{") continue;
4172
+ const kind = braceContext(site.file, enc.line, enc.col);
4173
+ if (kind.kind === "value") {
4174
+ readValue(tree, site.file, site.line.n, after, ctx, acc);
4175
+ } else if (kind.kind === "unread") {
4176
+ acc.unreadable.push({
4177
+ anchor: site.anchor,
4178
+ reason: `\`${ctx}\` at ${site.anchor} is a key of a brace whose kind (object value, type, pattern, block) is unread: ${kind.form} \u2014 its keys are unread`
4179
+ });
3998
4180
  }
3999
4181
  }
4000
4182
  for (const site of codeSites(tree, META_BRACKET_RE)) {
@@ -5815,7 +5997,7 @@ function untouchedParams(s, params, names, bStart, bEnd, fwdOpen, fwdClose) {
5815
5997
  }
5816
5998
  function toolRegistrations(tree) {
5817
5999
  const regs = [];
5818
- const unread = [];
6000
+ const unread2 = [];
5819
6001
  for (const c of callsMatching(
5820
6002
  tree,
5821
6003
  /^(?:[\w$]+\.)+(?:tool|registerTool|registerToolTask|setRequestHandler)$|^(?:registerTool|registerToolTask)$/
@@ -5830,7 +6012,7 @@ function toolRegistrations(tree) {
5830
6012
  if (/^(?:[\w$]+\.)*[\w$]*RequestSchema$/.test(schema) && !/CallToolRequestSchema$/.test(schema))
5831
6013
  continue;
5832
6014
  if (!/CallToolRequestSchema$/.test(schema)) {
5833
- unread.push({
6015
+ unread2.push({
5834
6016
  anchor: c.anchor,
5835
6017
  reason: `${c.anchor} setRequestHandler(${schema.slice(0, 30)}, ...) registers a handler for a request the scan cannot name: whether it dispatches tools/call is unread`
5836
6018
  });
@@ -5897,7 +6079,7 @@ function toolRegistrations(tree) {
5897
6079
  if (h.method !== void 0 && transparent.has(h.method)) continue;
5898
6080
  const anchor = anchorAt(s, h.at);
5899
6081
  const reason = h.method === void 0 ? "" : why.get(h.method);
5900
- unread.push({
6082
+ unread2.push({
5901
6083
  anchor,
5902
6084
  reason: `${anchor} \`${s.code.slice(h.at, h.at + h.len + 12).replace(/\s+/g, "").slice(
5903
6085
  0,
@@ -5907,7 +6089,7 @@ function toolRegistrations(tree) {
5907
6089
  }
5908
6090
  }
5909
6091
  }
5910
- return { regs, unread };
6092
+ return { regs, unread: unread2 };
5911
6093
  }
5912
6094
  function unreadSource(tree) {
5913
6095
  return tree.skippedDirs.filter((d) => /— not read$/.test(d.reason) && isProductSource(d.path)).map((d) => ({
@@ -6798,7 +6980,13 @@ var c10MechanismDeclared = {
6798
6980
 
6799
6981
  // src/detectors/c11-pagination.ts
6800
6982
  var PIN2 = STANDARD_PIN;
6801
- var PAGINABLE_RE = LIST_READ_RE;
6983
+ var PAGINABLE_VERBS = /* @__PURE__ */ new Set(["list", "search"]);
6984
+ var PAGINABLE_NAME_RE = /^(list|search)/i;
6985
+ function paginability(t) {
6986
+ if (t.verb === void 0) return PAGINABLE_NAME_RE.test(t.name) ? "paginable" : "not-paginable";
6987
+ if (!VERB_SET.has(t.verb)) return { unknownVerb: t.verb };
6988
+ return PAGINABLE_VERBS.has(t.verb) ? "paginable" : "not-paginable";
6989
+ }
6802
6990
  function c11PositiveControls() {
6803
6991
  const field = toolAnnotationFieldControls().pagination;
6804
6992
  return { fieldMatcher: field };
@@ -6825,30 +7013,47 @@ var c11Pagination = {
6825
7013
  verdict: `could not judge: ${reason}`
6826
7014
  };
6827
7015
  }
6828
- const tools = findToolAnnotations(tree).filter((t) => PAGINABLE_RE.test(t.name));
7016
+ const located = findToolAnnotations(tree);
7017
+ const undecidable = located.flatMap((t) => {
7018
+ const p = paginability(t);
7019
+ return typeof p === "object" ? [`${t.name} (verb "${p.unknownVerb}" at ${t.anchor})`] : [];
7020
+ });
7021
+ if (undecidable.length > 0) {
7022
+ const reason = `declared verb outside the closed set (C-9) on ${undecidable.length} tool(s): ${undecidable.join(", ")} \u2014 paginability undecidable (C-11)`;
7023
+ return {
7024
+ id: this.id,
7025
+ anchor: located.find((t) => typeof paginability(t) === "object")?.anchor ?? "-",
7026
+ state: "could-not-judge",
7027
+ reason,
7028
+ verdict: `could not judge: ${reason}`
7029
+ };
7030
+ }
7031
+ const tools = located.filter((t) => paginability(t) === "paginable");
6829
7032
  if (tools.length === 0) {
6830
7033
  return {
6831
7034
  id: this.id,
6832
7035
  anchor: "-",
6833
7036
  state: "absent",
6834
- verdict: "no list/read/get/search tool registrations found; pagination declaration check n/a"
7037
+ verdict: "no list or search tool registrations found (declared verb, or name prefix without one); pagination declaration check n/a"
6835
7038
  };
6836
7039
  }
6837
7040
  const opaque = opaqueAnnotationsAbstain(this.id, "C-11", tools);
6838
7041
  if (opaque) return opaque;
6839
- for (const t of tools) {
7042
+ const failing = tools.flatMap((t) => {
6840
7043
  const missing = [];
6841
7044
  if (!t.paginationCursorDeclared) missing.push("paginationCursor");
6842
7045
  if (t.paginationDefault === void 0) missing.push("paginationDefault");
6843
7046
  if (t.paginationMax === void 0) missing.push("paginationMax (finite)");
6844
- if (missing.length > 0) {
6845
- return {
6846
- id: this.id,
6847
- anchor: t.anchor,
6848
- state: "non-conforming",
6849
- verdict: `tool "${t.name}" is missing pagination declaration(s): ${missing.join(", ")} (positive-control OK) -> declare annotations.paginationCursor/paginationDefault/paginationMax with a FINITE max \u2014 an unbounded max never publishes (C-11)`
6850
- };
6851
- }
7047
+ return missing.length > 0 ? [{ t, missing }] : [];
7048
+ });
7049
+ if (failing.length > 0) {
7050
+ const sites = failing.map(({ t, missing }) => `"${t.name}" at ${t.anchor} (missing ${missing.join(", ")})`).join("; ");
7051
+ return {
7052
+ id: this.id,
7053
+ anchor: failing[0]?.t.anchor ?? "-",
7054
+ state: "non-conforming",
7055
+ verdict: `${failing.length} of ${tools.length} paginable tool(s) miss pagination declaration(s): ${sites} (positive-control OK) -> declare annotations.paginationCursor/paginationDefault/paginationMax with a FINITE max \u2014 an unbounded max never publishes (C-11)`
7056
+ };
6852
7057
  }
6853
7058
  return {
6854
7059
  id: this.id,
@@ -6874,13 +7079,15 @@ var c11Pagination = {
6874
7079
  verdict: `could not judge: ${reason}`
6875
7080
  };
6876
7081
  }
6877
- const paginable = runtime.tools.filter((t) => PAGINABLE_RE.test(t.name) || t.cursorArgument);
7082
+ const paginable = runtime.tools.filter(
7083
+ (t) => PAGINABLE_NAME_RE.test(t.name) || t.cursorArgument
7084
+ );
6878
7085
  if (paginable.length === 0) {
6879
7086
  return {
6880
7087
  id: this.id,
6881
7088
  anchor: `${runtime.root} (runtime tools/list)`,
6882
7089
  state: "absent",
6883
- verdict: "server advertises no list/read/get/search tool and no tool taking a cursor at runtime; pagination check n/a"
7090
+ verdict: "server advertises no list/search tool and no tool taking a cursor at runtime; pagination check n/a"
6884
7091
  };
6885
7092
  }
6886
7093
  const anchor = `${runtime.root} (runtime invalid-cursor probes)`;
@@ -6896,12 +7103,12 @@ var c11Pagination = {
6896
7103
  };
6897
7104
  }
6898
7105
  const red = [];
6899
- const unread = [];
7106
+ const unread2 = [];
6900
7107
  const ok = [];
6901
7108
  for (const p of probes) {
6902
7109
  const j = judgeCursorProbe(p);
6903
7110
  if (j.kind === "red") red.push(j.text);
6904
- else if (j.kind === "unread") unread.push(j.text);
7111
+ else if (j.kind === "unread") unread2.push(j.text);
6905
7112
  else ok.push(j.text);
6906
7113
  }
6907
7114
  if (red.length > 0) {
@@ -6912,8 +7119,8 @@ var c11Pagination = {
6912
7119
  verdict: `${red.join("; ")} -> an invalid cursor on a protocol list method is -32602; passed as a tool argument it is a tool result with isError: true and structuredContent.error.code "invalid_cursor" (SEP-1303) (C-11)`
6913
7120
  };
6914
7121
  }
6915
- if (unread.length > 0) {
6916
- const reason = `${unread.join("; ")} (C-11)`;
7122
+ if (unread2.length > 0) {
7123
+ const reason = `${unread2.join("; ")} (C-11)`;
6917
7124
  return {
6918
7125
  id: this.id,
6919
7126
  anchor,
@@ -8070,12 +8277,12 @@ var c18StructureManifestInner = {
8070
8277
  let manifestName = kind === "extension" ? "extension.json" : "mcp.json";
8071
8278
  if (kind === "server") {
8072
8279
  const cands = rootCandidates(tree.root);
8073
- const unread = cands.find((c) => c.readError !== void 0);
8074
- if (unread) {
8280
+ const unread2 = cands.find((c) => c.readError !== void 0);
8281
+ if (unread2) {
8075
8282
  return couldNotJudge(
8076
8283
  this.id,
8077
- unread.path,
8078
- `${unread.name} is present but ${unread.readError} \u2014 the server manifest cannot be judged (C-18)`
8284
+ unread2.path,
8285
+ `${unread2.name} is present but ${unread2.readError} \u2014 the server manifest cannot be judged (C-18)`
8079
8286
  );
8080
8287
  }
8081
8288
  const bad = cands.find((c) => c.role === "unparseable");
@@ -9556,12 +9763,12 @@ var c26SubpackageLockfile = {
9556
9763
  const verdicts = scope.sites.map(gateSite);
9557
9764
  const inventory = renderCoverage(scope.sites, verdicts);
9558
9765
  const analysed = verdicts.filter((v) => v.status === "analysed");
9559
- const unread = verdicts.filter((v) => v.status === "unreadable");
9560
- if (unread.length > 0 && !analysed.some((v) => v.ok === false)) {
9561
- const reason = `${unread.length} deployable site(s) could not be read \u2014 ${unread.map((v) => v.reason).join("; ")}. Coverage: ${inventory}`;
9766
+ const unread2 = verdicts.filter((v) => v.status === "unreadable");
9767
+ if (unread2.length > 0 && !analysed.some((v) => v.ok === false)) {
9768
+ const reason = `${unread2.length} deployable site(s) could not be read \u2014 ${unread2.map((v) => v.reason).join("; ")}. Coverage: ${inventory}`;
9562
9769
  return {
9563
9770
  id: this.id,
9564
- anchor: unread[0].site.dir,
9771
+ anchor: unread2[0].site.dir,
9565
9772
  state: "could-not-judge",
9566
9773
  reason,
9567
9774
  verdict: `could not judge: ${reason}`
@@ -11211,6 +11418,7 @@ var RESULT_PAYLOAD_KEYS = [
11211
11418
  "completion",
11212
11419
  "nextCursor"
11213
11420
  ];
11421
+ var RESULT_ANCHOR_KEYS = ["content", "structuredContent", "resultType"];
11214
11422
  function baseIsResult(file, base, tree) {
11215
11423
  if (!base) return false;
11216
11424
  const esc4 = base.replace(/[$]/g, "\\$&");
@@ -11227,14 +11435,33 @@ function baseIsResult(file, base, tree) {
11227
11435
  }
11228
11436
  function handRolledBuilder(tree) {
11229
11437
  const scan = fieldWrites(tree, HANDROLLED_FIELDS);
11230
- const unread = [...scan.unread];
11438
+ const unread2 = [...scan.unread];
11439
+ for (const k of scan.computed) {
11440
+ if (objectReturned(k.file, k.object).kind !== "returned") continue;
11441
+ const m = objectMembers(k.file, k.object);
11442
+ const member = RESULT_ANCHOR_KEYS.find((key) => m.keys.has(key));
11443
+ if (!member) continue;
11444
+ unread2.push({
11445
+ anchor: k.anchor,
11446
+ reason: `the computed key \`[${k.expr.slice(0, 40)}]\` at ${k.anchor} sits in a returned result object (it carries \`${member}\`) and may write resultType / ttlMs / cacheScope: which field it writes is unread (D7)`
11447
+ });
11448
+ }
11231
11449
  for (const w of scan.writes) {
11450
+ const bind = w.object ? objectReturned(w.file, w.object) : w.base && identReturned(w.file, w.base) ? { kind: "returned", how: `\`${w.base}\` returned` } : { kind: "not-returned", how: w.base ? `\`${w.base}\` never returned` : "no base" };
11451
+ if (bind.kind === "not-returned") continue;
11452
+ if (bind.kind === "unread") {
11453
+ unread2.push({
11454
+ anchor: w.anchor,
11455
+ reason: `\`${w.name}\` is written at ${w.anchor} into an object in ${bind.form}: whether a handler returns it is unread (D7)`
11456
+ });
11457
+ continue;
11458
+ }
11232
11459
  let result = w.name === "resultType";
11233
11460
  if (!result && w.object) {
11234
11461
  const m = objectMembers(w.file, w.object);
11235
11462
  result = RESULT_PAYLOAD_KEYS.some((k) => m.keys.has(k));
11236
11463
  if (!result && m.spreads.length > 0) {
11237
- unread.push({
11464
+ unread2.push({
11238
11465
  anchor: w.anchor,
11239
11466
  reason: `\`${w.name}\` is written at ${w.anchor} into an object whose other members come from \`...${m.spreads[0]}\`: whether that object is a protocol result is unread (D7)`
11240
11467
  });
@@ -11244,10 +11471,10 @@ function handRolledBuilder(tree) {
11244
11471
  result = baseIsResult(w.file, w.base, tree);
11245
11472
  }
11246
11473
  if (result) {
11247
- return { hand: { file: w.file.rel, line: w.line, field: w.name, form: w.form }, unread };
11474
+ return { hand: { file: w.file.rel, line: w.line, field: w.name, form: w.form }, unread: unread2 };
11248
11475
  }
11249
11476
  }
11250
- return { hand: null, unread };
11477
+ return { hand: null, unread: unread2 };
11251
11478
  }
11252
11479
  function controlTree2(text) {
11253
11480
  const file = {
@@ -11261,7 +11488,9 @@ var d7Inner = {
11261
11488
  id: "D7 protocol-kit",
11262
11489
  run(tree) {
11263
11490
  const v2 = (r) => sdkV2Dependency({ dependencies: { [SDK_V2_PKG]: r } }).kind;
11264
- if (v2("^2.3.1") !== "v2" || v2(">=2 <3") !== "v2" || v2("^1.12.0") !== "below-v2" || v2("latest") !== "unreadable" || handRolledBuilder(controlTree2("export const r = () => ({ content: [], ttlMs: 0 });")).hand === null || handRolledBuilder(controlTree2("export const u = (ok: boolean) => (ok ? ttlMs : 0);")).hand !== null) {
11491
+ if (v2("^2.3.1") !== "v2" || v2(">=2 <3") !== "v2" || v2("^1.12.0") !== "below-v2" || v2("latest") !== "unreadable" || handRolledBuilder(controlTree2("export const r = () => ({ content: [], ttlMs: 0 });")).hand === null || handRolledBuilder(controlTree2("export const u = (ok: boolean) => (ok ? ttlMs : 0);")).hand !== null || handRolledBuilder(
11492
+ controlTree2('export const v = () => { const r = { resultType: "x" }; return r; };')
11493
+ ).hand === null || handRolledBuilder(controlTree2('export const w = (log: any) => log({ resultType: "x" });')).hand !== null) {
11265
11494
  throw new Error(
11266
11495
  "D7 control FAILED: SDK v2 range reader / hand-rolled matcher broken \u2014 verdict untrustworthy"
11267
11496
  );
@@ -11307,7 +11536,7 @@ var d7Inner = {
11307
11536
  };
11308
11537
  }
11309
11538
  if (sdk.kind === "v2") {
11310
- const { hand, unread } = handRolledBuilder(tree);
11539
+ const { hand, unread: unread2 } = handRolledBuilder(tree);
11311
11540
  if (hand) {
11312
11541
  return {
11313
11542
  id: this.id,
@@ -11316,11 +11545,11 @@ var d7Inner = {
11316
11545
  verdict: `hand-rolled result builder (\`${hand.field}\` written by hand as a ${hand.form} into a result object at ${hand.file}:${hand.line}) and @vantageos/mcp-protocol-kit not a dependency -> let the SDK emit resultType/ttlMs/cacheScope (cacheHints) or adopt the kit (D7)`
11317
11546
  };
11318
11547
  }
11319
- if (unread.length > 0) {
11320
- const reason = `${unread.length} protocol-field write(s) could not be judged \u2014 ${unread[0].reason}`;
11548
+ if (unread2.length > 0) {
11549
+ const reason = `${unread2.length} protocol-field write(s) could not be judged \u2014 ${unread2[0].reason}`;
11321
11550
  return {
11322
11551
  id: this.id,
11323
- anchor: unread[0].anchor,
11552
+ anchor: unread2[0].anchor,
11324
11553
  state: "could-not-judge",
11325
11554
  reason,
11326
11555
  verdict: `could not judge: ${reason}`
@@ -12709,7 +12938,7 @@ function findExtensionManifests(tree) {
12709
12938
  } catch {
12710
12939
  return out;
12711
12940
  }
12712
- const walk2 = (dir) => {
12941
+ const walk3 = (dir) => {
12713
12942
  let entries;
12714
12943
  try {
12715
12944
  entries = readdirSync9(dir);
@@ -12731,7 +12960,7 @@ function findExtensionManifests(tree) {
12731
12960
  recordSkip(tree, full, base);
12732
12961
  continue;
12733
12962
  }
12734
- walk2(full);
12963
+ walk3(full);
12735
12964
  } else if (name === "extension.json") {
12736
12965
  if (!st.isFile()) {
12737
12966
  recordSkip(tree, full, base, "not a regular file (FIFO, socket or device) \u2014 not read");
@@ -12741,7 +12970,7 @@ function findExtensionManifests(tree) {
12741
12970
  }
12742
12971
  }
12743
12972
  };
12744
- walk2(base);
12973
+ walk3(base);
12745
12974
  return out;
12746
12975
  }
12747
12976
 
@@ -13390,7 +13619,7 @@ function findHooksDirs(tree, unreadable, gaps) {
13390
13619
  unreadable.push({ anchor, reason });
13391
13620
  }
13392
13621
  };
13393
- const walk2 = (dir) => {
13622
+ const walk3 = (dir) => {
13394
13623
  let entries;
13395
13624
  try {
13396
13625
  entries = readdirSync10(dir);
@@ -13430,10 +13659,10 @@ function findHooksDirs(tree, unreadable, gaps) {
13430
13659
  }
13431
13660
  out.push({ anchor: `${name}/`, tokens });
13432
13661
  }
13433
- walk2(full);
13662
+ walk3(full);
13434
13663
  }
13435
13664
  };
13436
- walk2(base);
13665
+ walk3(base);
13437
13666
  return out;
13438
13667
  }
13439
13668
  var LIFECYCLE_OBJ_RE = /\blifecycle\s*:\s*\{/;
@@ -13949,7 +14178,7 @@ function collectHooksDirSources(tree, unreadable, gaps) {
13949
14178
  unreadable.push({ anchor, reason });
13950
14179
  }
13951
14180
  };
13952
- const walk2 = (dir) => {
14181
+ const walk3 = (dir) => {
13953
14182
  let entries;
13954
14183
  try {
13955
14184
  entries = readdirSync11(dir);
@@ -14004,10 +14233,10 @@ function collectHooksDirSources(tree, unreadable, gaps) {
14004
14233
  });
14005
14234
  }
14006
14235
  }
14007
- walk2(full);
14236
+ walk3(full);
14008
14237
  }
14009
14238
  };
14010
- walk2(base);
14239
+ walk3(base);
14011
14240
  return out;
14012
14241
  }
14013
14242
  var LIFECYCLE_OBJ_RE2 = /\blifecycle\s*:\s*\{/;
@@ -15895,7 +16124,7 @@ function readInstalledAs(tree) {
15895
16124
  continue;
15896
16125
  }
15897
16126
  const files = [];
15898
- const walk2 = (d) => {
16127
+ const walk3 = (d) => {
15899
16128
  let names;
15900
16129
  try {
15901
16130
  names = readdirSync12(d).sort();
@@ -15916,11 +16145,11 @@ function readInstalledAs(tree) {
15916
16145
  out.unread.push(`${full.slice(nm.length + 1)} (not stat'ed: ${e.message})`);
15917
16146
  continue;
15918
16147
  }
15919
- if (st.isDirectory()) walk2(full);
16148
+ if (st.isDirectory()) walk3(full);
15920
16149
  else if (st.isFile() && SOURCE_EXT.test(n) && !n.endsWith(".d.ts")) files.push(full);
15921
16150
  }
15922
16151
  };
15923
- walk2(dir);
16152
+ walk3(dir);
15924
16153
  if (files.length >= MAX_FILES_PER_PACKAGE) {
15925
16154
  out.unread.push(`${dep} (more than ${MAX_FILES_PER_PACKAGE} files: the rest were not read)`);
15926
16155
  }
@@ -16003,7 +16232,7 @@ function delegatedAsElements(tree, fallbackAnchor) {
16003
16232
  const owed = (what) => [
16004
16233
  { status: "owed", text: what, anchor: fallbackAnchor }
16005
16234
  ];
16006
- const unread = inst.unread.length > 0 ? ` (not read: ${inst.unread.slice(0, 3).join("; ")})` : "";
16235
+ const unread2 = inst.unread.length > 0 ? ` (not read: ${inst.unread.slice(0, 3).join("; ")})` : "";
16007
16236
  if (!inst.installed) {
16008
16237
  const r = owed(
16009
16238
  "the AS metadata document is written by a dependency, not by this tree, and node_modules is absent: install with the lockfile's manager and re-run, or read the served metadata (--url)"
@@ -16012,7 +16241,7 @@ function delegatedAsElements(tree, fallbackAnchor) {
16012
16241
  }
16013
16242
  if (inst.publishers.length === 0) {
16014
16243
  const r = owed(
16015
- `the AS metadata document is not written by this tree and no installed declared dependency serves ${"`/.well-known/oauth-authorization-server`"}${inst.missing.length > 0 ? ` (declared but not installed: ${inst.missing.slice(0, 5).join(", ")})` : ""}${unread}: read the served metadata (--url)`
16244
+ `the AS metadata document is not written by this tree and no installed declared dependency serves ${"`/.well-known/oauth-authorization-server`"}${inst.missing.length > 0 ? ` (declared but not installed: ${inst.missing.slice(0, 5).join(", ")})` : ""}${unread2}: read the served metadata (--url)`
16016
16245
  );
16017
16246
  return { g: r, l: r };
16018
16247
  }
@@ -16024,7 +16253,7 @@ function delegatedAsElements(tree, fallbackAnchor) {
16024
16253
  anchor: inst.cimd.anchor
16025
16254
  }
16026
16255
  ] : owed(
16027
- `the installed ${pk} serves the AS metadata but its code does not state ${[inst.cimd ? "" : "client_id_metadata_document_supported: true", inst.none ? "" : '"none" in token_endpoint_auth_methods_supported'].filter(Boolean).join(" nor ")}${unread}: an installed library can prove an element, never its absence; read the served metadata (--url)`
16256
+ `the installed ${pk} serves the AS metadata but its code does not state ${[inst.cimd ? "" : "client_id_metadata_document_supported: true", inst.none ? "" : '"none" in token_endpoint_auth_methods_supported'].filter(Boolean).join(" nor ")}${unread2}: an installed library can prove an element, never its absence; read the served metadata (--url)`
16028
16257
  );
16029
16258
  const l = inst.iss ? [
16030
16259
  {
@@ -16033,7 +16262,7 @@ function delegatedAsElements(tree, fallbackAnchor) {
16033
16262
  anchor: inst.iss.anchor
16034
16263
  }
16035
16264
  ] : owed(
16036
- `the installed ${pk} serves the AS metadata but its code does not state authorization_response_iss_parameter_supported: true${unread}: read the served metadata (--url)`
16265
+ `the installed ${pk} serves the AS metadata but its code does not state authorization_response_iss_parameter_supported: true${unread2}: read the served metadata (--url)`
16037
16266
  );
16038
16267
  return { g, l };
16039
16268
  }
@@ -16611,29 +16840,29 @@ var s9ConfusedDeputy = {
16611
16840
  `${reds.join("; ")} (S-9, positive-control OK)`
16612
16841
  );
16613
16842
  }
16614
- const unread = [];
16843
+ const unread2 = [];
16615
16844
  for (const { file, rows } of proxies) {
16616
16845
  if (!rows.some((r) => CONSENT_CHECK_RE.test(r))) {
16617
- unread.push(`${file.rel}: no consent registry lookup (the word consent alone is not one)`);
16846
+ unread2.push(`${file.rel}: no consent registry lookup (the word consent alone is not one)`);
16618
16847
  }
16619
16848
  if (!rows.some((r) => EXACT_RE.test(r))) {
16620
- unread.push(
16849
+ unread2.push(
16621
16850
  `${file.rel}: no equality or membership test of redirect_uri against registered values`
16622
16851
  );
16623
16852
  }
16624
16853
  const stateRows = rows.flatMap((r, i) => STATE_CREATE_RE.test(r) ? [i] : []);
16625
16854
  if (!stateRows.some((i) => RANDOM_RE.test(`${rows[i]}
16626
16855
  ${rows[i + 1] ?? ""}`))) {
16627
- unread.push(
16856
+ unread2.push(
16628
16857
  `${file.rel}: the state is not shown to come from a random source (randomUUID, randomBytes, nanoid ...)`
16629
16858
  );
16630
16859
  }
16631
16860
  }
16632
- if (unread.length > 0) {
16861
+ if (unread2.length > 0) {
16633
16862
  return couldNotJudge(
16634
16863
  this.id,
16635
16864
  `${proxies[0].file.rel}:1`,
16636
- `no S-9 element is contradicted, but the tree does not show: ${unread.join("; ")} (S-9)`
16865
+ `no S-9 element is contradicted, but the tree does not show: ${unread2.join("; ")} (S-9)`
16637
16866
  );
16638
16867
  }
16639
16868
  return presentResult(
@@ -16991,14 +17220,14 @@ var s12ListPagination = {
16991
17220
  const anchor = `${runtime.root} (served list responses)`;
16992
17221
  const methods = declaredListMethods(served.capabilities);
16993
17222
  const red = [];
16994
- const unread = [];
17223
+ const unread2 = [];
16995
17224
  const ok = [];
16996
17225
  for (const m of methods) {
16997
17226
  const l = served.lists.find((x) => x.method === m);
16998
17227
  if (!l) {
16999
- unread.push(`${m}: no record of it in this run`);
17228
+ unread2.push(`${m}: no record of it in this run`);
17000
17229
  } else if (l.outcome !== "answered") {
17001
- unread.push(
17230
+ unread2.push(
17002
17231
  `${m}: ${l.outcome === "refused" ? "refused" : "no answer"} (${l.detail ?? "no detail"})`
17003
17232
  );
17004
17233
  } else if (l.nextCursor === void 0) {
@@ -17010,7 +17239,7 @@ var s12ListPagination = {
17010
17239
  `${m} serves a nextCursor that is not a non-empty string (${JSON.stringify(l.nextCursor)})`
17011
17240
  );
17012
17241
  } else if (!l.followUp || l.followUp.outcome === "no-answer") {
17013
- unread.push(
17242
+ unread2.push(
17014
17243
  `${m}: the served cursor was not presented back (${l.followUp?.detail ?? "no follow-up recorded"})`
17015
17244
  );
17016
17245
  } else if (l.followUp.outcome === "refused") {
@@ -17030,11 +17259,11 @@ var s12ListPagination = {
17030
17259
  };
17031
17260
  }
17032
17261
  const note = undeclaredProbeNote(served.capabilities);
17033
- if (unread.length > 0 || note) {
17262
+ if (unread2.length > 0 || note) {
17034
17263
  return couldNotJudge(
17035
17264
  this.id,
17036
17265
  anchor,
17037
- `served pagination read on ${ok.length > 0 ? ok.join("; ") : "no list method"}; unread: ${[...unread, ...note ? [note] : []].join("; ")} (S-12)`
17266
+ `served pagination read on ${ok.length > 0 ? ok.join("; ") : "no list method"}; unread: ${[...unread2, ...note ? [note] : []].join("; ")} (S-12)`
17038
17267
  );
17039
17268
  }
17040
17269
  return {
@@ -17604,7 +17833,7 @@ var s15CompletionSecurity = {
17604
17833
  );
17605
17834
  }
17606
17835
  const reds = [];
17607
- const unread = [];
17836
+ const unread2 = [];
17608
17837
  let read = 0;
17609
17838
  for (const h of handlers) {
17610
17839
  let text = "";
@@ -17621,7 +17850,7 @@ var s15CompletionSecurity = {
17621
17850
  text = b ? b.text : "";
17622
17851
  }
17623
17852
  if (text === "") {
17624
- unread.push(h.anchor);
17853
+ unread2.push(h.anchor);
17625
17854
  continue;
17626
17855
  }
17627
17856
  read++;
@@ -17646,7 +17875,7 @@ var s15CompletionSecurity = {
17646
17875
  return couldNotJudge(
17647
17876
  this.id,
17648
17877
  where,
17649
- `the completions surface is present (${where}); handlers read: ${read}${read > 0 ? ", each with input validation and a rate limit" : ""}; sites not read (no body to read): ${unread.length > 0 ? unread.join(", ") : "none"}; owed (dynamic): no disclosure \u2014 a completion never suggests a value the caller is not authorized to see (S-15)`
17878
+ `the completions surface is present (${where}); handlers read: ${read}${read > 0 ? ", each with input validation and a rate limit" : ""}; sites not read (no body to read): ${unread2.length > 0 ? unread2.join(", ") : "none"}; owed (dynamic): no disclosure \u2014 a completion never suggests a value the caller is not authorized to see (S-15)`
17650
17879
  );
17651
17880
  }
17652
17881
  };
@@ -17765,8 +17994,8 @@ function documentsFootprint(manifestText) {
17765
17994
  } catch {
17766
17995
  return false;
17767
17996
  }
17768
- const walk2 = (v) => {
17769
- if (Array.isArray(v)) return v.some(walk2);
17997
+ const walk3 = (v) => {
17998
+ if (Array.isArray(v)) return v.some(walk3);
17770
17999
  if (v === null || typeof v !== "object") return false;
17771
18000
  for (const [k, val] of Object.entries(v)) {
17772
18001
  if (k === "footprint") {
@@ -17774,11 +18003,11 @@ function documentsFootprint(manifestText) {
17774
18003
  if (Array.isArray(val) && val.length > 0) return true;
17775
18004
  if (val !== null && typeof val === "object" && Object.keys(val).length > 0) return true;
17776
18005
  }
17777
- if (walk2(val)) return true;
18006
+ if (walk3(val)) return true;
17778
18007
  }
17779
18008
  return false;
17780
18009
  };
17781
- return walk2(json);
18010
+ return walk3(json);
17782
18011
  }
17783
18012
 
17784
18013
  // src/detectors/s17-forward-auth.ts
@@ -18261,14 +18490,14 @@ var s22OriginValidation = {
18261
18490
  `${flag[0].anchor} turns the DNS rebinding protection on and sets no allowedOrigins: the SDK validates no Origin without a list of origins -> name the expected origins (S-22)`
18262
18491
  );
18263
18492
  }
18264
- if (origins.sites > 0 && origins.unresolved.length > 0) {
18493
+ if (origins.unresolved.length > 0) {
18265
18494
  return couldNotJudge(
18266
18495
  this.id,
18267
18496
  origins.unresolved[0].anchor,
18268
- `allowedOrigins is given by ${origins.unresolved.map((u) => `\`${u.name}\` (${u.anchor})`).join(", ")}, which this tree does not define as a literal list: whether it names concrete origins is unread (S-22)`
18497
+ `${unresolvedText(origins.unresolved)}: whether it names concrete origins is unread (S-22)`
18269
18498
  );
18270
18499
  }
18271
- if (origins.sites > 0 && flag.length === 0) {
18500
+ if (origins.ok.length > 0 && flag.length === 0) {
18272
18501
  return couldNotJudge(
18273
18502
  this.id,
18274
18503
  origins.first,
@@ -18289,31 +18518,141 @@ var s22OriginValidation = {
18289
18518
  const rows = uncommentedLines(file);
18290
18519
  rows.forEach((row, i) => {
18291
18520
  if (!ORIGIN_READ_RE.test(row)) return;
18292
- const window = rows.slice(i, i + 7).join("\n");
18521
+ const readCol = ORIGIN_READ_RE.exec(row)?.index ?? 0;
18522
+ const window = rows.slice(i, refusalWindowEnd(file, rows, i, readCol)).join("\n");
18293
18523
  (REFUSE_RE.test(window) ? refused : ignored).push(`${file.rel}:${i + 1}`);
18294
18524
  });
18295
18525
  }
18526
+ const declaredNote = origins.declared.length > 0 ? `; ${origins.declared.map((d) => d.text).join("; ")}` : "";
18296
18527
  if (refused.length > 0) {
18297
18528
  return presentResult(
18298
18529
  this.id,
18299
18530
  refused[0],
18300
- `the Origin header is read and an unlisted origin is refused with 403 (${refused.join(", ")}) (positive-control OK)${wideNote} (S-22)`
18531
+ `the Origin header is read and an unlisted origin is refused with 403 (${refused.join(", ")})${declaredNote} (positive-control OK)${wideNote} (S-22)`
18532
+ );
18533
+ }
18534
+ if (origins.declared.length > 0 && flag.length > 0) {
18535
+ const emptyDefault = origins.declared.find((d) => d.refusesAllByDefault);
18536
+ if (emptyDefault) {
18537
+ return couldNotJudge(
18538
+ this.id,
18539
+ emptyDefault.anchor,
18540
+ `the SDK protection is on (${flag[0].anchor}) and allowedOrigins is ${emptyDefault.text}: the SDK checks no Origin when its list is empty, so with the default the protection validates nothing; whether the deployment sets the variable is unread (S-22)`
18541
+ );
18542
+ }
18543
+ return presentResult(
18544
+ this.id,
18545
+ origins.declared[0].anchor,
18546
+ `the transport's Origin protection is on (${flag[0].anchor})${declaredNote} (positive-control OK)${wideNote} (S-22)`
18301
18547
  );
18302
18548
  }
18303
18549
  if (ignored.length > 0) {
18304
18550
  return redResult(
18305
18551
  this.id,
18306
18552
  ignored[0],
18307
- `the Origin header is read (${ignored.join(", ")}) and never refused with 403 within six lines: an unlisted origin must be rejected with 403 before the dispatch (S-22)`
18553
+ `the Origin header is read (${ignored.join(", ")}) and never refused with 403 within six lines (or the statement that starts there): an unlisted origin must be rejected with 403 before the dispatch (S-22)`
18308
18554
  );
18309
18555
  }
18310
18556
  return redResult(
18311
18557
  this.id,
18312
18558
  transport[0].anchor,
18313
- `a Streamable HTTP transport is served (${transport[0].anchor}) and nothing validates the Origin header (no allowlist, no 403, no SDK protection): DNS rebinding reaches the server${wideNote} -> validate Origin against an allowlist and answer 403 (S-22)`
18559
+ `a Streamable HTTP transport is served (${transport[0].anchor}) and nothing validates the Origin header (no allowlist, no 403, no SDK protection)${declaredNote ? `${declaredNote}, and nothing enforces it` : ""}: DNS rebinding reaches the server${wideNote} -> validate Origin against an allowlist and answer 403 (S-22)`
18314
18560
  );
18315
18561
  }
18316
18562
  };
18563
+ function refusalWindowEnd(file, rows, i, readCol) {
18564
+ const open = [];
18565
+ for (let r = i; r < rows.length && r < i + 40; r++) {
18566
+ const raw = rows[r];
18567
+ for (let c = r === i ? readCol : 0; c < raw.length; c++) {
18568
+ if (!isCodeAt(file, r + 1, c)) continue;
18569
+ if ("([{".includes(raw[c])) open.push(raw[c]);
18570
+ else if (")]}".includes(raw[c])) open.pop();
18571
+ }
18572
+ if (r >= i + 6 && (open.length === 0 || open[0] === "{")) return r + 1;
18573
+ }
18574
+ return Math.min(rows.length, i + 40);
18575
+ }
18576
+ function unresolvedText(list) {
18577
+ const plain = list.filter((u) => u.said === void 0);
18578
+ const parts = plain.length ? [
18579
+ `allowedOrigins is given by ${plain.map((u) => `\`${u.name}\` (${u.anchor})`).join(", ")}, which this tree does not define as a literal list`
18580
+ ] : [];
18581
+ for (const u of list) if (u.said !== void 0) parts.push(u.said);
18582
+ return parts.join("; ");
18583
+ }
18584
+ var DECLARED_TYPES = ["string", "integer", "boolean", "url", "originList", "enum", "json"];
18585
+ var ENV_READ_RE = /^process\.env(?:\.([A-Za-z_$][\w$]*)|\[\s*(["'`])([^"'`]+)\2\s*\])/;
18586
+ var MEMBER_READ_RE = /^[A-Za-z_$][\w$]*(?:\??\.[A-Za-z_$][\w$]*)+/;
18587
+ function declaredEntryAt(file, line, col) {
18588
+ const spec = enclosingOpener(file, line, col);
18589
+ if (!spec || spec.ch !== "{") return null;
18590
+ const call = enclosingOpener(file, spec.line, spec.col);
18591
+ if (!call || call.ch !== "(") return null;
18592
+ const before = uncommentedLines(file)[call.line - 1].slice(0, call.col);
18593
+ if (!/\bdefineVariables\s*(?:<[^>]*>)?\s*$/.test(before)) return null;
18594
+ const b = balancedBlock(file, line, col, "{", "}");
18595
+ return b ? b.text : null;
18596
+ }
18597
+ function declarationsOf(tree, key) {
18598
+ const out = [];
18599
+ const re = new RegExp(
18600
+ `(?:\\b${key.replace(/[$]/g, "\\$&")}\\b|["'\`]${key.replace(/[$]/g, "\\$&")}["'\`])\\s*:\\s*\\{`,
18601
+ "g"
18602
+ );
18603
+ for (const site of codeSites(tree, re)) {
18604
+ if (!isProductSource(site.file.rel)) continue;
18605
+ const brace = site.col + site.match[0].length - 1;
18606
+ const text = declaredEntryAt(site.file, site.line.n, brace);
18607
+ if (text !== null) out.push({ anchor: site.anchor, file: site.file, text });
18608
+ }
18609
+ return out;
18610
+ }
18611
+ function judgeDeclared(tree, key, anchor, file, entry) {
18612
+ const members3 = /* @__PURE__ */ new Map();
18613
+ for (const m of splitTopLevel(entry.slice(1, -1))) {
18614
+ const kv = m.match(/^(["'`]?)([A-Za-z_$][\w$]*)\1\s*:\s*([\s\S]*)$/);
18615
+ if (kv) members3.set(kv[2], kv[3].trim());
18616
+ }
18617
+ const envRaw = members3.get("env") ?? "";
18618
+ const env = (envRaw.match(/^(["'`])([^"'`]*)\1$/) ?? [])[2] ?? `env ${envRaw || "absent"}`;
18619
+ const who = `the declared variable \`${key}\` (${env}, ${anchor})`;
18620
+ const typeRaw = members3.get("type");
18621
+ const def = members3.get("default");
18622
+ const defLeaves = def === void 0 ? null : leavesOf(tree, def, file, 0);
18623
+ const wild = defLeaves?.strings.find((x) => x.slice(1, -1).includes("*"));
18624
+ if (wild) return { kind: "wildcard", text: `${who} defaults to a wildcard (${def})` };
18625
+ if (typeRaw === void 0)
18626
+ return { kind: "unresolved", said: `allowedOrigins is ${who}, which declares no type` };
18627
+ const type = (typeRaw.match(/^(["'`])([^"'`]*)\1$/) ?? [])[2];
18628
+ if (type === void 0)
18629
+ return {
18630
+ kind: "unresolved",
18631
+ said: `allowedOrigins is ${who}, whose type \`${typeRaw}\` is not a literal`
18632
+ };
18633
+ if (!DECLARED_TYPES.includes(type))
18634
+ return {
18635
+ kind: "unresolved",
18636
+ said: `allowedOrigins is ${who}, of type \`${typeRaw}\` this reader does not know`
18637
+ };
18638
+ if (type !== "originList")
18639
+ return {
18640
+ kind: "unresolved",
18641
+ said: `allowedOrigins is ${who}, of type \`${typeRaw}\`, which does not validate an origin list at start-up`
18642
+ };
18643
+ if (defLeaves?.unresolved)
18644
+ return {
18645
+ kind: "unresolved",
18646
+ said: `allowedOrigins is ${who}, whose default \`${defLeaves.unresolved}\` is not a literal`
18647
+ };
18648
+ const empty = defLeaves !== null && defLeaves.strings.length === 0;
18649
+ const dflt = defLeaves === null ? "no default (the value is the environment's)" : empty ? "default [] (refuses every browser origin)" : `default ${def}`;
18650
+ return {
18651
+ kind: "ok",
18652
+ text: `allowedOrigins is ${who}, type originList (a "*" or a path refused at start-up), ${dflt}`,
18653
+ refusesAllByDefault: empty
18654
+ };
18655
+ }
18317
18656
  function resolveConstLiteral(tree, name, file) {
18318
18657
  const re = new RegExp(
18319
18658
  `\\b(?:const|let|var)\\s+${name.replace(/[$]/g, "\\$&")}\\b[^=\\n]*=\\s*`,
@@ -18334,14 +18673,55 @@ function resolveConstLiteral(tree, name, file) {
18334
18673
  return null;
18335
18674
  }
18336
18675
  function classifyAllowedOrigins(tree) {
18337
- const out = { sites: 0, first: "", ok: [], reds: [], unresolved: [] };
18676
+ const out = { sites: 0, first: "", ok: [], reds: [], unresolved: [], declared: [] };
18677
+ const judged = /* @__PURE__ */ new Set();
18678
+ const takeDeclared = (key, decl) => {
18679
+ if (judged.has(decl.anchor)) return;
18680
+ judged.add(decl.anchor);
18681
+ const v = judgeDeclared(tree, key, decl.anchor, decl.file, decl.text);
18682
+ if (v.kind === "wildcard")
18683
+ out.reds.push({ anchor: decl.anchor, text: `${v.text}: a wildcard validates no Origin` });
18684
+ else if (v.kind === "unresolved")
18685
+ out.unresolved.push({ anchor: decl.anchor, name: key, said: v.said });
18686
+ else
18687
+ out.declared.push({
18688
+ anchor: decl.anchor,
18689
+ text: v.text,
18690
+ refusesAllByDefault: v.refusesAllByDefault
18691
+ });
18692
+ };
18338
18693
  for (const site of codeSites(tree, ALLOWED_ORIGINS_RE)) {
18339
18694
  if (!isProductSource(site.file.rel)) continue;
18340
18695
  const after = site.col + site.match[0].length;
18341
18696
  const rest = site.line.raw.slice(after);
18342
18697
  if (TYPE_ANNOTATION_RE.test(rest)) continue;
18698
+ if (rest.startsWith("{")) {
18699
+ const entry = declaredEntryAt(site.file, site.line.n, after);
18700
+ if (entry !== null) {
18701
+ takeDeclared("allowedOrigins", { anchor: site.anchor, file: site.file, text: entry });
18702
+ continue;
18703
+ }
18704
+ }
18343
18705
  out.sites++;
18344
18706
  out.first ||= site.anchor;
18707
+ const env = rest.match(ENV_READ_RE);
18708
+ if (env) {
18709
+ out.unresolved.push({
18710
+ anchor: site.anchor,
18711
+ name: env[0],
18712
+ said: `allowedOrigins is read straight from the environment (\`${env[0]}\`, ${site.anchor}) with no declaration (variable ${env[1] ?? env[3]})`
18713
+ });
18714
+ continue;
18715
+ }
18716
+ const member = rest.match(MEMBER_READ_RE);
18717
+ if (member) {
18718
+ const key = member[0].split(".").pop() ?? "";
18719
+ const decls = declarationsOf(tree, key);
18720
+ if (decls.length > 0) {
18721
+ for (const d of decls) takeDeclared(key, d);
18722
+ continue;
18723
+ }
18724
+ }
18345
18725
  let value;
18346
18726
  if (rest.startsWith("[")) {
18347
18727
  const b = balancedBlock(site.file, site.line.n, after, "[", "]");
@@ -18746,14 +19126,73 @@ var s26ListChangedParity = {
18746
19126
 
18747
19127
  // src/detectors/s27-elicitation-floor.ts
18748
19128
  var ELICIT_RE = /\belicitInput\s*\(|["'`]elicitation\/create["'`]|\brequestedSchema\b/;
18749
- var MRTR_RE = /resultType\s*:\s*["'`]input_required["'`]/;
19129
+ var MRTR_VALUE = "input_required";
18750
19130
  var FALLBACK_RE = /\belicitInput\s*\(|["'`]elicitation\/create["'`]/;
18751
19131
  var DECL_RE2 = /\b(?:midCallInput|elicitation|inputRequired)AtFloor["']?\s*:\s*(?:false|["'](?:unsupported|none)["'])/i;
18752
19132
  var SENSITIVE_KEY_RE = /^(?:password|passwd|pwd|secret\w*|\w*token|api[_-]?key|apikey|private[_-]?key|credential\w*|ssn|social[_-]?security\w*|credit[_-]?card\w*|card[_-]?number|cc[_-]?number|cvv|cvc|iban|account[_-]?number|passport\w*|health\w*|medical\w*|diagnos\w*|salary|income)$/i;
19133
+ function resultTypeValue(w) {
19134
+ if (w.form === "shorthand") return constString(w.file, w.name);
19135
+ const at = fieldValueAt(w);
19136
+ if (!at) return { kind: "unread", form: "a value whose position cannot be read" };
19137
+ const s = stringValueAt(w.file, at.line, at.col);
19138
+ if (s.kind === "string") return { kind: "value", value: s.value };
19139
+ if (s.kind === "not-string") return { kind: "value", value: null };
19140
+ const core = unwrapValue(w.file, at.line, at.col);
19141
+ if (core.kind === "ident") return constString(w.file, core.name);
19142
+ return { kind: "unread", form: core.kind === "other" ? core.form : s.form };
19143
+ }
19144
+ function mrtrRounds(tree) {
19145
+ const scan = fieldWrites(tree, ["resultType"]);
19146
+ const rounds = [];
19147
+ const unread2 = [...scan.unread];
19148
+ for (const k of scan.computed) {
19149
+ const at = computedValueAt(k.file, k.line, k.col);
19150
+ if (!at) continue;
19151
+ const s = stringValueAt(k.file, at.line, at.col);
19152
+ let value = s.kind === "string" ? s.value : null;
19153
+ if (s.kind === "other") {
19154
+ const core = unwrapValue(k.file, at.line, at.col);
19155
+ if (core.kind === "ident") {
19156
+ const bound = constString(k.file, core.name);
19157
+ if (bound.kind === "value") value = bound.value;
19158
+ }
19159
+ }
19160
+ if (value !== MRTR_VALUE) continue;
19161
+ unread2.push({
19162
+ anchor: k.anchor,
19163
+ reason: `the computed key \`[${k.expr.slice(0, 40)}]\` at ${k.anchor} is written "${MRTR_VALUE}": whether that key is \`resultType\` (an MRTR input round) is unread (S-27)`
19164
+ });
19165
+ }
19166
+ for (const w of scan.writes) {
19167
+ const v = resultTypeValue(w);
19168
+ if (v.kind === "unread") {
19169
+ unread2.push({
19170
+ anchor: w.anchor,
19171
+ reason: `\`resultType\` at ${w.anchor} is written as ${v.form}: whether it is "${MRTR_VALUE}" (an MRTR input round) is unread (S-27)`
19172
+ });
19173
+ } else if (v.value === MRTR_VALUE) rounds.push(w.anchor);
19174
+ }
19175
+ return { rounds, unread: unread2 };
19176
+ }
19177
+ function controlTree3(text) {
19178
+ const file = {
19179
+ path: "<s27-control>.ts",
19180
+ rel: "<s27-control>",
19181
+ lines: text.split("\n").map((raw, i) => ({ n: i + 1, raw, comment: false }))
19182
+ };
19183
+ return { root: "<s27-control>", files: [file], packageJson: null, skippedDirs: [] };
19184
+ }
18753
19185
  function s27Controls() {
19186
+ const lit = mrtrRounds(controlTree3('export const a = () => ({ resultType: "input_required" });'));
19187
+ const cond = mrtrRounds(
19188
+ controlTree3(
19189
+ 'export const b = (c: boolean) => ({ resultType: c ? "input_required" : "complete" });'
19190
+ )
19191
+ );
19192
+ const other = mrtrRounds(controlTree3('export const d = () => ({ resultType: "complete" });'));
18754
19193
  return {
18755
- sees: SENSITIVE_KEY_RE.test("apiKey") && SENSITIVE_KEY_RE.test("card_number") && SENSITIVE_KEY_RE.test("medicalHistory") && MRTR_RE.test('{ resultType: "input_required" }') && DECL_RE2.test("midCallInputAtFloor: false"),
18756
- spares: !SENSITIVE_KEY_RE.test("city") && !SENSITIVE_KEY_RE.test("type") && !SENSITIVE_KEY_RE.test("properties")
19194
+ sees: SENSITIVE_KEY_RE.test("apiKey") && SENSITIVE_KEY_RE.test("card_number") && SENSITIVE_KEY_RE.test("medicalHistory") && lit.rounds.length === 1 && cond.unread.length === 1 && DECL_RE2.test("midCallInputAtFloor: false"),
19195
+ spares: !SENSITIVE_KEY_RE.test("city") && !SENSITIVE_KEY_RE.test("type") && !SENSITIVE_KEY_RE.test("properties") && other.rounds.length === 0 && other.unread.length === 0
18757
19196
  };
18758
19197
  }
18759
19198
  var s27ElicitationFloor = {
@@ -18773,6 +19212,10 @@ var s27ElicitationFloor = {
18773
19212
  let declared = false;
18774
19213
  let first = "";
18775
19214
  const reds = [];
19215
+ const product = { ...tree, files: tree.files.filter((f) => isProductSource(f.rel)) };
19216
+ const mrtrScan = mrtrRounds(product);
19217
+ const unread2 = mrtrScan.unread;
19218
+ mrtr = mrtrScan.rounds.length;
18776
19219
  for (const file of tree.files) {
18777
19220
  if (!isProductSource(file.rel)) continue;
18778
19221
  const rows = uncommentedLines(file);
@@ -18784,10 +19227,6 @@ var s27ElicitationFloor = {
18784
19227
  elicitation++;
18785
19228
  first ||= `${file.rel}:${i + 1}`;
18786
19229
  }
18787
- if (MRTR_RE.test(row)) {
18788
- mrtr++;
18789
- first ||= `${file.rel}:${i + 1}`;
18790
- }
18791
19230
  const at = row.indexOf("requestedSchema");
18792
19231
  if (at >= 0) {
18793
19232
  const op = nextOpener(file, i + 1, at, "{", 2);
@@ -18804,7 +19243,8 @@ var s27ElicitationFloor = {
18804
19243
  }
18805
19244
  });
18806
19245
  }
18807
- if (elicitation + mrtr === 0) {
19246
+ first = mrtrScan.rounds[0] ?? first;
19247
+ if (elicitation + mrtr === 0 && unread2.length === 0) {
18808
19248
  return absentResult(
18809
19249
  this.id,
18810
19250
  "-",
@@ -18823,6 +19263,13 @@ var s27ElicitationFloor = {
18823
19263
  `${reds.join("; ")} (S-27, positive-control OK)`
18824
19264
  );
18825
19265
  }
19266
+ if (unread2.length > 0) {
19267
+ return couldNotJudge(
19268
+ this.id,
19269
+ unread2[0].anchor,
19270
+ `${unread2.length} resultType value(s) could not be read \u2014 ${unread2.map((u) => u.reason).join("; ")}. ${elicitation} elicitation site(s) and ${mrtr} MRTR round(s) read, no sensitive field requested (S-27)`
19271
+ );
19272
+ }
18826
19273
  return couldNotJudge(
18827
19274
  this.id,
18828
19275
  first,
@@ -18891,12 +19338,12 @@ function splitTop2(m, from, to) {
18891
19338
  if (start < to && m.slice(start, to).trim() !== "") parts.push([start, to]);
18892
19339
  return parts;
18893
19340
  }
18894
- function listTs(dir, unread, out = []) {
19341
+ function listTs(dir, unread2, out = []) {
18895
19342
  let names;
18896
19343
  try {
18897
19344
  names = readdirSync13(dir);
18898
19345
  } catch (err) {
18899
- unread.push(`${dir} could not be listed (${fsErrorCode(err)})`);
19346
+ unread2.push(`${dir} could not be listed (${fsErrorCode(err)})`);
18900
19347
  return out;
18901
19348
  }
18902
19349
  for (const n of names) {
@@ -18906,12 +19353,12 @@ function listTs(dir, unread, out = []) {
18906
19353
  try {
18907
19354
  st = statSync20(p);
18908
19355
  } catch (err) {
18909
- unread.push(`${p} could not be read (${fsErrorCode(err)})`);
19356
+ unread2.push(`${p} could not be read (${fsErrorCode(err)})`);
18910
19357
  continue;
18911
19358
  }
18912
- if (st.isDirectory()) listTs(p, unread, out);
19359
+ if (st.isDirectory()) listTs(p, unread2, out);
18913
19360
  else if (n.endsWith(".ts") && !n.endsWith(".test.ts") && !n.endsWith(".d.ts")) {
18914
- if (!st.isFile()) unread.push(`${p} is not a regular file \u2014 not read`);
19361
+ if (!st.isFile()) unread2.push(`${p} is not a regular file \u2014 not read`);
18915
19362
  else out.push(p);
18916
19363
  }
18917
19364
  }
@@ -18933,14 +19380,14 @@ function discoverBackend(root) {
18933
19380
  }
18934
19381
  return void 0;
18935
19382
  }
18936
- function readDoors(backendRoot, unread) {
19383
+ function readDoors(backendRoot, unread2) {
18937
19384
  const doors = /* @__PURE__ */ new Map();
18938
- for (const path of listTs(backendRoot, unread)) {
19385
+ for (const path of listTs(backendRoot, unread2)) {
18939
19386
  let text;
18940
19387
  try {
18941
19388
  text = readFileSync14(path, "utf8");
18942
19389
  } catch (err) {
18943
- unread.push(`${path} could not be read (${fsErrorCode(err)})`);
19390
+ unread2.push(`${path} could not be read (${fsErrorCode(err)})`);
18944
19391
  continue;
18945
19392
  }
18946
19393
  const file = {
@@ -19062,9 +19509,9 @@ function scanS28(tree) {
19062
19509
  const scan = { violate: [], conform: [], cnj: [], calls: 0, backend: void 0 };
19063
19510
  const backendRoot = tree.backendRoot ?? discoverBackend(tree.root);
19064
19511
  scan.backend = backendRoot;
19065
- const unread = [];
19066
- const doors = backendRoot ? readDoors(backendRoot, unread) : void 0;
19067
- const unreadNote = unread.length > 0 ? `; backend source NOT read: ${unread.join("; ")}` : "";
19512
+ const unread2 = [];
19513
+ const doors = backendRoot ? readDoors(backendRoot, unread2) : void 0;
19514
+ const unreadNote = unread2.length > 0 ? `; backend source NOT read: ${unread2.join("; ")}` : "";
19068
19515
  const files = tree.files.map((f) => ({ f, text: rawText(f), m: masked(f) }));
19069
19516
  const actorDoors = /* @__PURE__ */ new Set();
19070
19517
  for (const { text } of files) {
@@ -22062,6 +22509,1703 @@ var s41LakeReader = {
22062
22509
  }
22063
22510
  };
22064
22511
 
22512
+ // src/detectors/s43-union-input.ts
22513
+ var ID = "S43 union-input";
22514
+ var RULE = "S-43";
22515
+ var MARKER_RE = /\/\/\s*allow-union-input:\s*(.*)$/;
22516
+ var MIN_REASON = 6;
22517
+ var FILE_SPAN = 1e9;
22518
+ var nextBase = 0;
22519
+ var fileByBase = /* @__PURE__ */ new Map();
22520
+ function locate(off) {
22521
+ const base = Math.floor(off / FILE_SPAN) * FILE_SPAN;
22522
+ const file = fileByBase.get(base);
22523
+ if (!file) return null;
22524
+ const lx = lex(file);
22525
+ return { file, line: lineOfOffset(lx.lineStarts, off - base) };
22526
+ }
22527
+ var PUNCT3 = ["===", "!==", "**=", "...", "<<=", ">>=", ">>>", "&&=", "||=", "??="];
22528
+ var PUNCT2 = [
22529
+ "=>",
22530
+ "==",
22531
+ "!=",
22532
+ "<=",
22533
+ ">=",
22534
+ "&&",
22535
+ "||",
22536
+ "??",
22537
+ "?.",
22538
+ "++",
22539
+ "--",
22540
+ "+=",
22541
+ "-=",
22542
+ "*=",
22543
+ "/=",
22544
+ "%=",
22545
+ "&=",
22546
+ "|=",
22547
+ "^=",
22548
+ "<<",
22549
+ ">>",
22550
+ "**"
22551
+ ];
22552
+ var REGEX_AFTER_WORDS = /* @__PURE__ */ new Set([
22553
+ "return",
22554
+ "typeof",
22555
+ "case",
22556
+ "do",
22557
+ "else",
22558
+ "in",
22559
+ "of",
22560
+ "new",
22561
+ "delete",
22562
+ "void",
22563
+ "throw",
22564
+ "instanceof",
22565
+ "yield",
22566
+ "await"
22567
+ ]);
22568
+ var lexCache = /* @__PURE__ */ new WeakMap();
22569
+ function lex(file) {
22570
+ const cached = lexCache.get(file);
22571
+ if (cached) return cached;
22572
+ const text = file.lines.map((l) => l.raw).join("\n");
22573
+ const lineStarts = [0];
22574
+ for (let i2 = 0; i2 < text.length; i2++) if (text[i2] === "\n") lineStarts.push(i2 + 1);
22575
+ const lineAt4 = (off) => lineOfOffset(lineStarts, off);
22576
+ const toks = [];
22577
+ const comments = /* @__PURE__ */ new Map();
22578
+ const addComment = (from, to) => {
22579
+ let a = from;
22580
+ while (a < to) {
22581
+ const nl = text.indexOf("\n", a);
22582
+ const end = nl < 0 || nl > to ? to : nl;
22583
+ const ln = lineAt4(a);
22584
+ comments.set(ln, (comments.get(ln) ?? "") + text.slice(a, end));
22585
+ a = end + 1;
22586
+ }
22587
+ };
22588
+ const regexAllowed = () => {
22589
+ const prev = toks[toks.length - 1];
22590
+ if (!prev) return true;
22591
+ if (prev.t === "id") return REGEX_AFTER_WORDS.has(prev.v);
22592
+ if (prev.t !== "p") return false;
22593
+ return !(prev.v === ")" || prev.v === "]" || prev.v === "}");
22594
+ };
22595
+ let i = 0;
22596
+ while (i < text.length) {
22597
+ const c = text[i];
22598
+ if (c === " " || c === " " || c === "\n" || c === "\r") {
22599
+ i++;
22600
+ continue;
22601
+ }
22602
+ if (c === "/" && text[i + 1] === "/") {
22603
+ const nl = text.indexOf("\n", i);
22604
+ const end = nl < 0 ? text.length : nl;
22605
+ addComment(i, end);
22606
+ i = end;
22607
+ continue;
22608
+ }
22609
+ if (c === "/" && text[i + 1] === "*") {
22610
+ const e = text.indexOf("*/", i + 2);
22611
+ const end = e < 0 ? text.length : e + 2;
22612
+ addComment(i, end);
22613
+ i = end;
22614
+ continue;
22615
+ }
22616
+ if (c === '"' || c === "'") {
22617
+ let j = i + 1;
22618
+ let v = "";
22619
+ while (j < text.length && text[j] !== c && text[j] !== "\n") {
22620
+ if (text[j] === "\\") {
22621
+ v += text[j + 1] ?? "";
22622
+ j += 2;
22623
+ continue;
22624
+ }
22625
+ v += text[j];
22626
+ j++;
22627
+ }
22628
+ toks.push({ t: "str", v, s: i });
22629
+ i = j + 1;
22630
+ continue;
22631
+ }
22632
+ if (c === "`") {
22633
+ let j = i + 1;
22634
+ let v = "";
22635
+ let interp = false;
22636
+ while (j < text.length && text[j] !== "`") {
22637
+ if (text[j] === "\\") {
22638
+ v += text[j + 1] ?? "";
22639
+ j += 2;
22640
+ continue;
22641
+ }
22642
+ if (text[j] === "$" && text[j + 1] === "{") {
22643
+ interp = true;
22644
+ let depth = 1;
22645
+ j += 2;
22646
+ while (j < text.length && depth > 0) {
22647
+ if (text[j] === "{") depth++;
22648
+ else if (text[j] === "}") depth--;
22649
+ else if (text[j] === "`") {
22650
+ j++;
22651
+ while (j < text.length && text[j] !== "`") j += text[j] === "\\" ? 2 : 1;
22652
+ }
22653
+ j++;
22654
+ }
22655
+ continue;
22656
+ }
22657
+ v += text[j];
22658
+ j++;
22659
+ }
22660
+ toks.push(interp ? { t: "tpl", v: "", s: i } : { t: "str", v, s: i });
22661
+ i = j + 1;
22662
+ continue;
22663
+ }
22664
+ if (c === "/" && regexAllowed()) {
22665
+ let j = i + 1;
22666
+ let inClass = false;
22667
+ while (j < text.length && text[j] !== "\n") {
22668
+ if (text[j] === "\\") {
22669
+ j += 2;
22670
+ continue;
22671
+ }
22672
+ if (text[j] === "[") inClass = true;
22673
+ else if (text[j] === "]") inClass = false;
22674
+ else if (text[j] === "/" && !inClass) break;
22675
+ j++;
22676
+ }
22677
+ j++;
22678
+ while (j < text.length && /[a-z]/i.test(text[j])) j++;
22679
+ toks.push({ t: "re", v: text.slice(i, j), s: i });
22680
+ i = j;
22681
+ continue;
22682
+ }
22683
+ if (/[A-Za-z_$]/.test(c)) {
22684
+ let j = i + 1;
22685
+ while (j < text.length && /[\w$]/.test(text[j])) j++;
22686
+ toks.push({ t: "id", v: text.slice(i, j), s: i });
22687
+ i = j;
22688
+ continue;
22689
+ }
22690
+ if (/[0-9]/.test(c) || c === "." && /[0-9]/.test(text[i + 1] ?? "")) {
22691
+ let j = i + 1;
22692
+ while (j < text.length && /[\w.]/.test(text[j])) j++;
22693
+ toks.push({ t: "num", v: text.slice(i, j), s: i });
22694
+ i = j;
22695
+ continue;
22696
+ }
22697
+ const three = text.slice(i, i + 3);
22698
+ const two = text.slice(i, i + 2);
22699
+ const p = PUNCT3.includes(three) ? three : PUNCT2.includes(two) ? two : c;
22700
+ toks.push({ t: "p", v: p, s: i });
22701
+ i += p.length;
22702
+ }
22703
+ nextBase += FILE_SPAN;
22704
+ const base = nextBase;
22705
+ for (const t of toks) t.s += base;
22706
+ fileByBase.set(base, file);
22707
+ const out = { text, toks, comments, lineStarts, base };
22708
+ lexCache.set(file, out);
22709
+ return out;
22710
+ }
22711
+ function lineOfOffset(lineStarts, off) {
22712
+ let lo = 0;
22713
+ let hi = lineStarts.length - 1;
22714
+ while (lo < hi) {
22715
+ const mid = lo + hi + 1 >> 1;
22716
+ if (lineStarts[mid] <= off) lo = mid;
22717
+ else hi = mid - 1;
22718
+ }
22719
+ return lo + 1;
22720
+ }
22721
+ var OPEN2 = { "(": ")", "[": "]", "{": "}" };
22722
+ var STOP = /* @__PURE__ */ new Set([",", ")", "]", "}", ";"]);
22723
+ var Parser = class _Parser {
22724
+ constructor(lx, i) {
22725
+ this.lx = lx;
22726
+ this.i = i;
22727
+ }
22728
+ lx;
22729
+ i;
22730
+ get toks() {
22731
+ return this.lx.toks;
22732
+ }
22733
+ peek(o = 0) {
22734
+ return this.toks[this.i + o];
22735
+ }
22736
+ isP(v, o = 0) {
22737
+ const t = this.peek(o);
22738
+ return t !== void 0 && t.t === "p" && t.v === v;
22739
+ }
22740
+ /** Index just past the bracket group opening at `i`. */
22741
+ skipGroup(i) {
22742
+ const open = this.toks[i];
22743
+ if (!open || open.t !== "p" || !OPEN2[open.v]) return i + 1;
22744
+ let depth = 0;
22745
+ for (let j = i; j < this.toks.length; j++) {
22746
+ const t = this.toks[j];
22747
+ if (t.t !== "p") continue;
22748
+ if (OPEN2[t.v]) depth++;
22749
+ else if (t.v === ")" || t.v === "]" || t.v === "}") {
22750
+ depth--;
22751
+ if (depth === 0) return j + 1;
22752
+ }
22753
+ }
22754
+ return this.toks.length;
22755
+ }
22756
+ /** Skip to the next top-level stop token (exclusive); returns whether every token was a string or `+`. */
22757
+ skipToStop() {
22758
+ let onlyStr = true;
22759
+ while (this.i < this.toks.length) {
22760
+ const t = this.toks[this.i];
22761
+ if (t.t === "p" && STOP.has(t.v)) break;
22762
+ if (t.t === "p" && OPEN2[t.v]) {
22763
+ onlyStr = false;
22764
+ this.i = this.skipGroup(this.i);
22765
+ continue;
22766
+ }
22767
+ if (!(t.t === "str" || t.t === "p" && t.v === "+")) onlyStr = false;
22768
+ this.i++;
22769
+ }
22770
+ return onlyStr;
22771
+ }
22772
+ /** Skip a type annotation (`as T`, `satisfies T`, `: T`): angle brackets nest. */
22773
+ skipType() {
22774
+ let angle = 0;
22775
+ while (this.i < this.toks.length) {
22776
+ const t = this.toks[this.i];
22777
+ if (t.t === "p") {
22778
+ if (t.v === "<") angle++;
22779
+ else if (t.v === ">" && angle > 0) angle--;
22780
+ else if (t.v === ">>" && angle > 0) angle = Math.max(0, angle - 2);
22781
+ else if (angle === 0 && (STOP.has(t.v) || t.v === "=" || t.v === "=>")) return;
22782
+ else if (OPEN2[t.v]) {
22783
+ this.i = this.skipGroup(this.i);
22784
+ continue;
22785
+ }
22786
+ }
22787
+ this.i++;
22788
+ }
22789
+ }
22790
+ /** Skip a type-parameter list `<T extends X<Y>, U = Z>` starting at the current `<`. */
22791
+ skipTypeParams() {
22792
+ let angle = 0;
22793
+ while (this.i < this.toks.length) {
22794
+ const t = this.toks[this.i];
22795
+ this.i++;
22796
+ if (t.t !== "p") continue;
22797
+ if (t.v === "<") angle++;
22798
+ else if (t.v === ">") angle--;
22799
+ else if (t.v === ">>") angle -= 2;
22800
+ if (angle <= 0) return;
22801
+ }
22802
+ }
22803
+ parseExpr() {
22804
+ const start = this.i;
22805
+ const s = this.peek()?.s ?? 0;
22806
+ const fn = this.tryArrow();
22807
+ if (fn) return fn;
22808
+ const node = this.parsePostfix();
22809
+ for (; ; ) {
22810
+ const t = this.peek();
22811
+ if (!t) return node;
22812
+ if (t.t === "id" && (t.v === "as" || t.v === "satisfies")) {
22813
+ this.i++;
22814
+ this.skipType();
22815
+ continue;
22816
+ }
22817
+ if (t.t === "p" && t.v === "!" && !this.isP("=", 1)) {
22818
+ this.i++;
22819
+ continue;
22820
+ }
22821
+ if (t.t === "p" && STOP.has(t.v)) return node;
22822
+ if (t.t === "p" && t.v === ":") return node;
22823
+ this.i = start;
22824
+ const onlyStr = this.skipToStop();
22825
+ return { k: "other", form: this.sliceText(start), strConcat: onlyStr, s };
22826
+ }
22827
+ }
22828
+ sliceText(fromTok) {
22829
+ const a = this.toks[fromTok]?.s ?? 0;
22830
+ const lastTok = this.toks[this.i - 1];
22831
+ const b = lastTok ? lastTok.s + Math.max(lastTok.v.length, 1) : a;
22832
+ const raw = this.lx.text.slice(a - this.lx.base, b - this.lx.base).replace(/\s+/g, " ").trim();
22833
+ return raw.length > 60 ? `${raw.slice(0, 57)}...` : raw;
22834
+ }
22835
+ tryArrow() {
22836
+ const start = this.i;
22837
+ const s = this.peek()?.s ?? 0;
22838
+ if (this.peek()?.t === "id" && this.peek()?.v === "async") this.i++;
22839
+ let params = null;
22840
+ if (this.isP("<")) this.skipTypeParams();
22841
+ const t = this.peek();
22842
+ if (t?.t === "id" && this.isP("=>", 1)) {
22843
+ params = [t.v];
22844
+ this.i += 1;
22845
+ } else if (t?.t === "p" && t.v === "(") {
22846
+ const end = this.skipGroup(this.i);
22847
+ let j = end;
22848
+ if (this.toks[j]?.t === "p" && this.toks[j]?.v === ":") {
22849
+ const save = this.i;
22850
+ this.i = j + 1;
22851
+ this.skipType();
22852
+ j = this.i;
22853
+ this.i = save;
22854
+ }
22855
+ if (this.toks[j]?.t === "p" && this.toks[j]?.v === "=>") {
22856
+ params = this.paramNames(this.i + 1, end - 1);
22857
+ this.i = j;
22858
+ }
22859
+ } else if (t?.t === "id" && t.v === "function") {
22860
+ this.i++;
22861
+ if (this.peek()?.t === "id") this.i++;
22862
+ if (this.isP("<")) this.skipTypeParams();
22863
+ if (!this.isP("(")) {
22864
+ this.i = start;
22865
+ return null;
22866
+ }
22867
+ const end = this.skipGroup(this.i);
22868
+ const ps = this.paramNames(this.i + 1, end - 1);
22869
+ this.i = end;
22870
+ if (this.isP(":")) {
22871
+ this.i++;
22872
+ this.skipType();
22873
+ }
22874
+ return { k: "fn", params: ps, body: this.isP("{") ? this.blockReturn() : null, s };
22875
+ }
22876
+ if (params === null) {
22877
+ this.i = start;
22878
+ return null;
22879
+ }
22880
+ this.i++;
22881
+ if (this.isP("{")) return { k: "fn", params, body: this.blockReturn(), s };
22882
+ return { k: "fn", params, body: this.parseExpr(), s };
22883
+ }
22884
+ /** The expression of the single top-level `return` of a block at `{`, or null; consumes the block. */
22885
+ blockReturn() {
22886
+ const open = this.i;
22887
+ const end = this.skipGroup(open);
22888
+ const returns = [];
22889
+ let depth = 0;
22890
+ for (let j = open; j < end; j++) {
22891
+ const t = this.toks[j];
22892
+ if (t.t === "p" && OPEN2[t.v]) depth++;
22893
+ else if (t.t === "p" && (t.v === ")" || t.v === "]" || t.v === "}")) depth--;
22894
+ else if (t.t === "id" && t.v === "return" && depth === 1) returns.push(j);
22895
+ }
22896
+ this.i = end;
22897
+ if (returns.length !== 1) return null;
22898
+ const sub = new _Parser(this.lx, returns[0] + 1);
22899
+ return sub.parseExpr();
22900
+ }
22901
+ paramNames(from, to) {
22902
+ const names = [];
22903
+ let depth = 0;
22904
+ let expectName = true;
22905
+ for (let j = from; j < to; j++) {
22906
+ const t = this.toks[j];
22907
+ if (t.t === "p" && OPEN2[t.v]) depth++;
22908
+ else if (t.t === "p" && (t.v === ")" || t.v === "]" || t.v === "}")) depth--;
22909
+ if (depth === 0 && t.t === "p" && t.v === ",") {
22910
+ expectName = true;
22911
+ continue;
22912
+ }
22913
+ if (depth === 0 && expectName && t.t === "id") {
22914
+ names.push(t.v);
22915
+ expectName = false;
22916
+ }
22917
+ }
22918
+ return names;
22919
+ }
22920
+ parsePostfix() {
22921
+ let node = this.parsePrimary();
22922
+ for (; ; ) {
22923
+ if (this.isP(".") || this.isP("?.")) {
22924
+ const nt = this.peek(1);
22925
+ if (nt?.t === "id") {
22926
+ this.i += 2;
22927
+ node = { k: "member", obj: node, prop: nt.v, s: node.s };
22928
+ continue;
22929
+ }
22930
+ if (this.isP("?.") && (this.isP("(", 1) || this.isP("[", 1))) {
22931
+ this.i++;
22932
+ continue;
22933
+ }
22934
+ return node;
22935
+ }
22936
+ if (this.isP("(")) {
22937
+ node = { k: "call", callee: node, args: this.parseList(")"), s: node.s };
22938
+ continue;
22939
+ }
22940
+ if (this.isP("[")) {
22941
+ const end = this.skipGroup(this.i);
22942
+ this.i = end;
22943
+ node = { k: "member", obj: node, prop: "[computed]", s: node.s };
22944
+ continue;
22945
+ }
22946
+ if (this.isP("<") && node.k === "member") {
22947
+ const save = this.i;
22948
+ this.i++;
22949
+ this.skipType();
22950
+ if (this.isP(">")) {
22951
+ this.i++;
22952
+ if (this.isP("(")) continue;
22953
+ }
22954
+ this.i = save;
22955
+ return node;
22956
+ }
22957
+ return node;
22958
+ }
22959
+ }
22960
+ /** Comma-separated expressions inside the group opening at the current token. */
22961
+ parseList(close) {
22962
+ const end = this.skipGroup(this.i);
22963
+ this.i++;
22964
+ const out = [];
22965
+ while (this.i < end - 1) {
22966
+ if (this.isP(",")) {
22967
+ this.i++;
22968
+ continue;
22969
+ }
22970
+ if (this.isP(close)) break;
22971
+ if (this.isP("...")) {
22972
+ const s = this.peek()?.s ?? 0;
22973
+ this.i++;
22974
+ const inner = this.parseExpr();
22975
+ out.push({ k: "other", form: `...${describeNode(inner)}`, strConcat: false, s });
22976
+ } else {
22977
+ const before = this.i;
22978
+ out.push(this.parseExpr());
22979
+ if (this.i === before) this.i++;
22980
+ }
22981
+ while (this.i < end - 1 && !this.isP(",")) this.i++;
22982
+ }
22983
+ this.i = end;
22984
+ return out;
22985
+ }
22986
+ parsePrimary() {
22987
+ const t = this.peek();
22988
+ if (!t) return { k: "other", form: "end of file", strConcat: false, s: 0 };
22989
+ const s = t.s;
22990
+ if (t.t === "str") {
22991
+ this.i++;
22992
+ return { k: "lit", v: t.v, s };
22993
+ }
22994
+ if (t.t === "num") {
22995
+ this.i++;
22996
+ return { k: "lit", v: Number(t.v), s };
22997
+ }
22998
+ if (t.t === "tpl") {
22999
+ this.i++;
23000
+ return { k: "other", form: "template literal with interpolation", strConcat: false, s };
23001
+ }
23002
+ if (t.t === "re") {
23003
+ this.i++;
23004
+ return { k: "other", form: "regular expression", strConcat: false, s };
23005
+ }
23006
+ if (t.t === "id") {
23007
+ this.i++;
23008
+ if (t.v === "true" || t.v === "false") return { k: "lit", v: t.v === "true", s };
23009
+ if (t.v === "null" || t.v === "undefined") return { k: "lit", v: null, s };
23010
+ if (t.v === "new") {
23011
+ this.parsePostfix();
23012
+ return { k: "other", form: "new expression", strConcat: false, s };
23013
+ }
23014
+ return { k: "id", name: t.v, s };
23015
+ }
23016
+ if (t.v === "(") {
23017
+ const end = this.skipGroup(this.i);
23018
+ this.i++;
23019
+ const inner = this.parseExpr();
23020
+ this.i = end;
23021
+ return inner;
23022
+ }
23023
+ if (t.v === "[") {
23024
+ return { k: "arr", items: this.parseList("]"), s };
23025
+ }
23026
+ if (t.v === "{") return this.parseObject();
23027
+ if (t.v === "-" && this.peek(1)?.t === "num") {
23028
+ this.i += 2;
23029
+ return { k: "lit", v: -Number(this.toks[this.i - 1].v), s };
23030
+ }
23031
+ this.i++;
23032
+ return { k: "other", form: `token ${t.v}`, strConcat: false, s };
23033
+ }
23034
+ parseObject() {
23035
+ const s = this.peek()?.s ?? 0;
23036
+ const end = this.skipGroup(this.i);
23037
+ this.i++;
23038
+ const entries = [];
23039
+ while (this.i < end - 1) {
23040
+ const t = this.peek();
23041
+ if (!t) break;
23042
+ if (t.t === "p" && t.v === ",") {
23043
+ this.i++;
23044
+ continue;
23045
+ }
23046
+ if (t.t === "p" && t.v === "...") {
23047
+ this.i++;
23048
+ entries.push({ kind: "spread", value: this.parseExpr(), s: t.s });
23049
+ } else if (t.t === "p" && t.v === "[") {
23050
+ this.i = this.skipGroup(this.i);
23051
+ entries.push({ kind: "unread", form: "computed key", s: t.s });
23052
+ if (this.isP(":")) {
23053
+ this.i++;
23054
+ this.parseExpr();
23055
+ }
23056
+ } else if (t.t === "id" || t.t === "str" || t.t === "num") {
23057
+ let key = t.v;
23058
+ let at = this.i;
23059
+ if (t.t === "id" && (t.v === "get" || t.v === "set" || t.v === "async") && (this.peek(1)?.t === "id" || this.peek(1)?.t === "str")) {
23060
+ at = this.i + 1;
23061
+ key = this.toks[at].v;
23062
+ }
23063
+ this.i = at + 1;
23064
+ if (this.isP("?")) this.i++;
23065
+ if (this.isP(":")) {
23066
+ this.i++;
23067
+ entries.push({ kind: "prop", key, value: this.parseExpr(), s: t.s });
23068
+ } else if (this.isP("(")) {
23069
+ this.i = this.skipGroup(this.i);
23070
+ if (this.isP(":")) {
23071
+ this.i++;
23072
+ this.skipType();
23073
+ }
23074
+ if (this.isP("{")) this.i = this.skipGroup(this.i);
23075
+ entries.push({
23076
+ kind: "prop",
23077
+ key,
23078
+ value: { k: "fn", params: [], body: null, s: t.s },
23079
+ s: t.s
23080
+ });
23081
+ } else {
23082
+ entries.push({ kind: "prop", key, value: { k: "id", name: key, s: t.s }, s: t.s });
23083
+ }
23084
+ } else {
23085
+ this.i++;
23086
+ }
23087
+ while (this.i < end - 1 && !this.isP(",")) this.i++;
23088
+ }
23089
+ this.i = end;
23090
+ return { k: "obj", entries, s };
23091
+ }
23092
+ };
23093
+ function describeNode(n) {
23094
+ switch (n.k) {
23095
+ case "id":
23096
+ return n.name;
23097
+ case "lit":
23098
+ return JSON.stringify(n.v);
23099
+ case "member":
23100
+ return `${describeNode(n.obj)}.${n.prop}`;
23101
+ case "call":
23102
+ return `${describeNode(n.callee)}(...)`;
23103
+ case "obj":
23104
+ return "{...}";
23105
+ case "arr":
23106
+ return "[...]";
23107
+ case "fn":
23108
+ return "function";
23109
+ case "other":
23110
+ return n.form;
23111
+ }
23112
+ }
23113
+ var bindingCache = /* @__PURE__ */ new WeakMap();
23114
+ function bracePairs(toks, open) {
23115
+ const pairs = [];
23116
+ let j = open + 1;
23117
+ while (j < toks.length && toks[j].v !== "}") {
23118
+ const tk = toks[j];
23119
+ if (tk.t === "id" && tk.v === "type" && toks[j + 1]?.t === "id" && toks[j + 1].v !== "as") {
23120
+ j++;
23121
+ continue;
23122
+ }
23123
+ if (tk.t === "id" || tk.t === "str") {
23124
+ if (toks[j + 1]?.v === "as" && toks[j + 2]) {
23125
+ pairs.push([tk.v, toks[j + 2].v]);
23126
+ j += 3;
23127
+ continue;
23128
+ }
23129
+ pairs.push([tk.v, tk.v]);
23130
+ }
23131
+ j++;
23132
+ }
23133
+ return { pairs, end: j };
23134
+ }
23135
+ function bindingsOf(file) {
23136
+ const cached = bindingCache.get(file);
23137
+ if (cached) return cached;
23138
+ const lx = lex(file);
23139
+ const toks = lx.toks;
23140
+ const decls = /* @__PURE__ */ new Map();
23141
+ const imports = /* @__PURE__ */ new Map();
23142
+ const reexports = [];
23143
+ const zod = /* @__PURE__ */ new Set();
23144
+ const add = (name, node) => decls.set(name, [...decls.get(name) ?? [], node]);
23145
+ const fromAfter = (j) => toks[j]?.t === "id" && toks[j].v === "from" && toks[j + 1]?.t === "str" ? toks[j + 1].v : null;
23146
+ for (let i = 0; i < toks.length; i++) {
23147
+ const t = toks[i];
23148
+ if (t.t !== "id") continue;
23149
+ const memberAccess = i > 0 && (toks[i - 1].v === "." || toks[i - 1].v === "?.");
23150
+ if (t.v === "import" && !memberAccess && toks[i + 1]?.v !== "(") {
23151
+ let j = i + 1;
23152
+ if (toks[j]?.v === "type") j++;
23153
+ const local = [];
23154
+ if (toks[j]?.t === "id" && toks[j].v !== "from") {
23155
+ local.push(["default", toks[j].v]);
23156
+ j++;
23157
+ if (toks[j]?.v === ",") j++;
23158
+ }
23159
+ if (toks[j]?.v === "{") {
23160
+ const bp = bracePairs(toks, j);
23161
+ local.push(...bp.pairs);
23162
+ j = bp.end + 1;
23163
+ } else if (toks[j]?.v === "*" && toks[j + 1]?.v === "as" && toks[j + 2]?.t === "id") {
23164
+ local.push(["*", toks[j + 2].v]);
23165
+ j += 3;
23166
+ }
23167
+ const mod = fromAfter(j);
23168
+ if (mod !== null) {
23169
+ for (const [orig, name] of local) {
23170
+ imports.set(name, { mod, orig });
23171
+ if (/^zod(\/|$)/.test(mod)) zod.add(name);
23172
+ }
23173
+ }
23174
+ continue;
23175
+ }
23176
+ if (t.v === "export" && !memberAccess) {
23177
+ let j = i + 1;
23178
+ if (toks[j]?.v === "type") j++;
23179
+ if (toks[j]?.v === "{") {
23180
+ const bp = bracePairs(toks, j);
23181
+ const mod = fromAfter(bp.end + 1);
23182
+ if (mod !== null)
23183
+ for (const [orig, exported] of bp.pairs) reexports.push({ mod, exported, orig });
23184
+ } else if (toks[j]?.v === "*" && toks[j + 1]?.v !== "as") {
23185
+ const mod = fromAfter(j + 1);
23186
+ if (mod !== null) reexports.push({ mod, exported: null, orig: null });
23187
+ }
23188
+ continue;
23189
+ }
23190
+ if ((t.v === "const" || t.v === "let" || t.v === "var") && toks[i + 1]?.t === "id") {
23191
+ const name = toks[i + 1].v;
23192
+ const p = new Parser(lx, i + 2);
23193
+ if (p.isP(":")) {
23194
+ p.i++;
23195
+ p.skipType();
23196
+ }
23197
+ if (p.isP("=")) {
23198
+ p.i++;
23199
+ add(name, p.parseExpr());
23200
+ }
23201
+ continue;
23202
+ }
23203
+ if (t.v === "function" && toks[i + 1]?.t === "id" && !memberAccess) {
23204
+ const name = toks[i + 1].v;
23205
+ const p = new Parser(lx, i);
23206
+ add(name, p.parseExpr());
23207
+ }
23208
+ }
23209
+ const out = { decls, imports, reexports, zod };
23210
+ bindingCache.set(file, out);
23211
+ return out;
23212
+ }
23213
+ var unread = (form, at) => ({
23214
+ k: "unread",
23215
+ form,
23216
+ at
23217
+ });
23218
+ var SCALAR = { k: "scalar", name: "scalar" };
23219
+ var SCALAR_FACTORIES = /* @__PURE__ */ new Set([
23220
+ "string",
23221
+ "number",
23222
+ "boolean",
23223
+ "bigint",
23224
+ "date",
23225
+ "literal",
23226
+ "enum",
23227
+ "nativeEnum",
23228
+ "int",
23229
+ "int32",
23230
+ "int64",
23231
+ "uint32",
23232
+ "uint64",
23233
+ "float32",
23234
+ "float64",
23235
+ "email",
23236
+ "url",
23237
+ "httpUrl",
23238
+ "uuid",
23239
+ "uuidv4",
23240
+ "uuidv6",
23241
+ "uuidv7",
23242
+ "guid",
23243
+ "cuid",
23244
+ "cuid2",
23245
+ "ulid",
23246
+ "nanoid",
23247
+ "emoji",
23248
+ "base64",
23249
+ "base64url",
23250
+ "jwt",
23251
+ "ipv4",
23252
+ "ipv6",
23253
+ "cidrv4",
23254
+ "cidrv6",
23255
+ "e164",
23256
+ "hostname",
23257
+ "hex",
23258
+ "hash",
23259
+ "stringbool",
23260
+ "templateLiteral",
23261
+ "symbol",
23262
+ "nan",
23263
+ "file",
23264
+ "keyof"
23265
+ ]);
23266
+ var ANY_FACTORIES = /* @__PURE__ */ new Set(["any", "unknown", "custom", "instanceof", "json"]);
23267
+ var NULL_FACTORIES = /* @__PURE__ */ new Set(["null", "undefined", "void", "never"]);
23268
+ var IDENTITY_METHODS = /* @__PURE__ */ new Set([
23269
+ "optional",
23270
+ "exactOptional",
23271
+ "nonoptional",
23272
+ "describe",
23273
+ "default",
23274
+ "prefault",
23275
+ "catch",
23276
+ "min",
23277
+ "max",
23278
+ "length",
23279
+ "size",
23280
+ "nonempty",
23281
+ "regex",
23282
+ "int",
23283
+ "positive",
23284
+ "negative",
23285
+ "nonnegative",
23286
+ "nonpositive",
23287
+ "finite",
23288
+ "safe",
23289
+ "multipleOf",
23290
+ "step",
23291
+ "gt",
23292
+ "gte",
23293
+ "lt",
23294
+ "lte",
23295
+ "email",
23296
+ "url",
23297
+ "uuid",
23298
+ "cuid",
23299
+ "cuid2",
23300
+ "ulid",
23301
+ "nanoid",
23302
+ "emoji",
23303
+ "base64",
23304
+ "jwt",
23305
+ "ip",
23306
+ "cidr",
23307
+ "trim",
23308
+ "toLowerCase",
23309
+ "toUpperCase",
23310
+ "lowercase",
23311
+ "uppercase",
23312
+ "normalize",
23313
+ "startsWith",
23314
+ "endsWith",
23315
+ "includes",
23316
+ "datetime",
23317
+ "date",
23318
+ "time",
23319
+ "duration",
23320
+ "refine",
23321
+ "superRefine",
23322
+ "check",
23323
+ "transform",
23324
+ "overwrite",
23325
+ "brand",
23326
+ "readonly",
23327
+ "meta",
23328
+ "register",
23329
+ "strict",
23330
+ "strictObject",
23331
+ "passthrough",
23332
+ "loose",
23333
+ "strip",
23334
+ "nonstrict",
23335
+ "catchall",
23336
+ "partial",
23337
+ "required",
23338
+ "deepPartial",
23339
+ "pipe"
23340
+ ]);
23341
+ function moduleCtx(file, tree, from) {
23342
+ return {
23343
+ file,
23344
+ b: bindingsOf(file),
23345
+ tree,
23346
+ params: /* @__PURE__ */ new Map(),
23347
+ depth: from ? from.depth + 1 : 0,
23348
+ resolving: from ? from.resolving : /* @__PURE__ */ new Set()
23349
+ };
23350
+ }
23351
+ function flatten(branches) {
23352
+ const out = [];
23353
+ for (const b of branches) {
23354
+ if (b.k === "union") out.push(...flatten(b.branches));
23355
+ else out.push(b);
23356
+ }
23357
+ return out;
23358
+ }
23359
+ function nullable(s, at) {
23360
+ return { k: "union", branches: [s, { k: "null" }], at };
23361
+ }
23362
+ var isUnread = (r) => "k" in r && r.k === "unread";
23363
+ function resolveModule(tree, from, spec) {
23364
+ const dir = from.path.slice(0, from.path.lastIndexOf("/"));
23365
+ const parts = `${dir}/${spec}`.split("/");
23366
+ const out = [];
23367
+ for (const p of parts) {
23368
+ if (p === "..") out.pop();
23369
+ else if (p !== ".") out.push(p);
23370
+ }
23371
+ const base = out.join("/");
23372
+ const stem = base.replace(/\.(?:m|c)?js$/, "").replace(/\.jsx$/, "");
23373
+ const candidates = [
23374
+ base,
23375
+ `${stem}.ts`,
23376
+ `${stem}.tsx`,
23377
+ `${stem}.mts`,
23378
+ `${stem}.cts`,
23379
+ `${stem}/index.ts`,
23380
+ `${stem}/index.tsx`
23381
+ ];
23382
+ for (const c of candidates) {
23383
+ const f = tree.files.find((x) => x.path === c);
23384
+ if (f) return f;
23385
+ }
23386
+ return null;
23387
+ }
23388
+ function resolveExport(file, name, at, ctx, chain) {
23389
+ const key = `${file.path}#${name}`;
23390
+ if (chain.includes(key))
23391
+ return unread(
23392
+ `import cycle: ${[...chain, key].map((k) => k.slice(k.lastIndexOf("/") + 1)).join(" -> ")}`,
23393
+ at
23394
+ );
23395
+ const b = bindingsOf(file);
23396
+ const decls = b.decls.get(name);
23397
+ if (decls && decls.length === 1) return { node: decls[0], ctx: moduleCtx(file, ctx.tree, ctx) };
23398
+ if (decls && decls.length > 1)
23399
+ return unread(`identifier ${name} declared ${decls.length} times in ${file.rel}`, at);
23400
+ const imp = b.imports.get(name);
23401
+ const viaChain = [...chain, key];
23402
+ if (imp) return followImport(file, name, imp, at, ctx, viaChain);
23403
+ const named = b.reexports.find((r) => r.exported === name);
23404
+ if (named)
23405
+ return followImport(
23406
+ file,
23407
+ name,
23408
+ { mod: named.mod, orig: named.orig ?? name },
23409
+ at,
23410
+ ctx,
23411
+ viaChain
23412
+ );
23413
+ for (const star of b.reexports.filter((r) => r.exported === null)) {
23414
+ const r = followImport(file, name, { mod: star.mod, orig: name }, at, ctx, viaChain);
23415
+ if (!isUnread(r) || /cycle/.test(r.form)) return r;
23416
+ }
23417
+ return unread(`identifier ${name} not exported by ${file.rel}`, at);
23418
+ }
23419
+ function followImport(file, name, imp, at, ctx, chain) {
23420
+ if (!imp.mod.startsWith("."))
23421
+ return unread(`identifier ${name} imported from package "${imp.mod}"`, at);
23422
+ if (imp.orig === "*")
23423
+ return unread(`namespace import ${name} from "${imp.mod}" (not followed)`, at);
23424
+ if (imp.orig === "default")
23425
+ return unread(`default import ${name} from "${imp.mod}" (not followed)`, at);
23426
+ const target = ctx.tree ? resolveModule(ctx.tree, file, imp.mod) : null;
23427
+ if (!target)
23428
+ return unread(
23429
+ `identifier ${name} imported from "${imp.mod}": the module is not in the scanned tree`,
23430
+ at
23431
+ );
23432
+ return resolveExport(target, imp.orig, at, ctx, chain);
23433
+ }
23434
+ function resolveRef(name, at, ctx) {
23435
+ if (ctx.params.has(name)) {
23436
+ const bound = ctx.params.get(name);
23437
+ if (!bound) return unread(`parameter ${name} (no argument at the call site)`, at);
23438
+ return {
23439
+ node: bound.node,
23440
+ ctx: { ...bound.ctx, depth: ctx.depth + 1, resolving: ctx.resolving }
23441
+ };
23442
+ }
23443
+ return resolveExport(ctx.file, name, at, ctx, []);
23444
+ }
23445
+ function isZodRoot(n, ctx) {
23446
+ return n.k === "id" && ctx.b.zod.has(n.name) && !ctx.params.has(n.name) && !ctx.b.decls.has(n.name);
23447
+ }
23448
+ function evalZod(n, ctx) {
23449
+ if (ctx.depth > 40) return unread("schema nested deeper than 40 resolutions", n.s);
23450
+ const sub = { ...ctx, depth: ctx.depth + 1 };
23451
+ switch (n.k) {
23452
+ case "obj":
23453
+ return evalShape(n, sub);
23454
+ case "id": {
23455
+ const r = resolveRef(n.name, n.s, ctx);
23456
+ if (isUnread(r)) return r;
23457
+ const key = `${r.ctx.file.path}#${describeNode(r.node)}@${r.node.s}`;
23458
+ if (ctx.resolving.has(key)) return unread(`identifier cycle through ${n.name}`, n.s);
23459
+ return evalZod(r.node, {
23460
+ ...r.ctx,
23461
+ depth: ctx.depth + 1,
23462
+ resolving: /* @__PURE__ */ new Set([...ctx.resolving, key])
23463
+ });
23464
+ }
23465
+ case "member": {
23466
+ if (n.prop === "shape") {
23467
+ const base = evalZod(n.obj, sub);
23468
+ return base.k === "object" || base.k === "unread" ? base : unread(`${describeNode(n)}`, n.s);
23469
+ }
23470
+ if (n.prop === "element") {
23471
+ const base = evalZod(n.obj, sub);
23472
+ if (base.k === "array") return base.items ?? { k: "any" };
23473
+ return base.k === "unread" ? base : unread(describeNode(n), n.s);
23474
+ }
23475
+ return unread(`member ${describeNode(n)}`, n.s);
23476
+ }
23477
+ case "call":
23478
+ return evalCall(n, sub);
23479
+ case "fn":
23480
+ return unread("function value", n.s);
23481
+ case "lit":
23482
+ return unread(`literal ${JSON.stringify(n.v)}`, n.s);
23483
+ case "arr":
23484
+ return unread("array literal", n.s);
23485
+ case "other":
23486
+ return unread(n.form, n.s);
23487
+ }
23488
+ }
23489
+ function evalShape(n, ctx) {
23490
+ const props = [];
23491
+ for (const e of n.entries) {
23492
+ if (e.kind === "prop") {
23493
+ props.push({ label: e.key, schema: evalZod(e.value, ctx), at: e.s });
23494
+ } else if (e.kind === "spread") {
23495
+ const spread = evalZod(e.value, ctx);
23496
+ if (spread.k === "object") props.push(...spread.props);
23497
+ else
23498
+ props.push({
23499
+ label: "...",
23500
+ schema: unread(
23501
+ `spread ...${describeNode(e.value)}${spread.k === "unread" ? ` (${spread.form})` : ""}`,
23502
+ e.s
23503
+ ),
23504
+ at: e.s
23505
+ });
23506
+ } else {
23507
+ props.push({ label: "[computed]", schema: unread(e.form, e.s), at: e.s });
23508
+ }
23509
+ }
23510
+ return { k: "object", props, at: n.s };
23511
+ }
23512
+ function unionArgs(arg, ctx, at) {
23513
+ let a = arg;
23514
+ let actx = ctx;
23515
+ if (a?.k === "id") {
23516
+ const r = resolveRef(a.name, a.s, ctx);
23517
+ if (isUnread(r)) return r;
23518
+ a = r.node;
23519
+ actx = r.ctx;
23520
+ }
23521
+ if (!a || a.k !== "arr") return unread(`union options ${a ? describeNode(a) : "missing"}`, at);
23522
+ return { k: "union", branches: a.items.map((x) => evalZod(x, actx)), at };
23523
+ }
23524
+ function evalCall(n, ctx) {
23525
+ const callee = n.callee;
23526
+ if (callee.k === "member") {
23527
+ const m = callee.prop;
23528
+ if (isZodRoot(callee.obj, ctx)) return zodFactory(m, n, ctx);
23529
+ if (callee.obj.k === "member" && callee.obj.prop === "coerce" && isZodRoot(callee.obj.obj, ctx))
23530
+ return SCALAR;
23531
+ const base = evalZod(callee.obj, ctx);
23532
+ return zodMethod(base, m, n, ctx);
23533
+ }
23534
+ if (callee.k === "id") {
23535
+ const r = resolveRef(callee.name, callee.s, ctx);
23536
+ if (isUnread(r)) return { ...r, form: `call ${callee.name}(...): ${r.form}` };
23537
+ const fn = r.node;
23538
+ if (fn.k !== "fn" || fn.body === null)
23539
+ return unread(`call ${callee.name}(...): its body is not a single returned expression`, n.s);
23540
+ const key = `${r.ctx.file.path}#call@${fn.s}`;
23541
+ if (ctx.resolving.has(key)) return unread(`recursive call ${callee.name}(...)`, n.s);
23542
+ const params = /* @__PURE__ */ new Map();
23543
+ fn.params.forEach((p, i) => params.set(p, n.args[i] ? { node: n.args[i], ctx } : null));
23544
+ return evalZod(fn.body, {
23545
+ ...r.ctx,
23546
+ params,
23547
+ depth: ctx.depth + 1,
23548
+ resolving: /* @__PURE__ */ new Set([...ctx.resolving, key])
23549
+ });
23550
+ }
23551
+ return unread(`call ${describeNode(callee)}(...)`, n.s);
23552
+ }
23553
+ function zodFactory(m, n, ctx) {
23554
+ const a = n.args;
23555
+ if (SCALAR_FACTORIES.has(m)) return SCALAR;
23556
+ if (ANY_FACTORIES.has(m)) return { k: "any" };
23557
+ if (NULL_FACTORIES.has(m)) return { k: "null" };
23558
+ switch (m) {
23559
+ case "array":
23560
+ case "set":
23561
+ return { k: "array", items: a[0] ? evalZod(a[0], ctx) : { k: "any" }, prefix: [], at: n.s };
23562
+ case "tuple": {
23563
+ const items = a[0]?.k === "arr" ? a[0].items.map((x) => evalZod(x, ctx)) : [];
23564
+ return { k: "array", items: null, prefix: items, at: n.s };
23565
+ }
23566
+ case "object":
23567
+ case "strictObject":
23568
+ case "looseObject":
23569
+ case "interface":
23570
+ return a[0] ? evalZod(a[0], ctx) : { k: "object", props: [], at: n.s };
23571
+ case "record":
23572
+ case "partialRecord":
23573
+ case "map": {
23574
+ const v = a[a.length - 1];
23575
+ return {
23576
+ k: "object",
23577
+ props: [{ label: "*", schema: v ? evalZod(v, ctx) : { k: "any" }, at: n.s }],
23578
+ at: n.s
23579
+ };
23580
+ }
23581
+ case "union":
23582
+ case "xor":
23583
+ return unionArgs(a[0], ctx, n.s);
23584
+ case "discriminatedUnion":
23585
+ return unionArgs(a[1] ?? a[0], ctx, n.s);
23586
+ case "optional":
23587
+ case "nonoptional":
23588
+ case "readonly":
23589
+ return a[0] ? evalZod(a[0], ctx) : unread(`z.${m}() with no argument`, n.s);
23590
+ case "nullable":
23591
+ case "nullish":
23592
+ return a[0] ? nullable(evalZod(a[0], ctx), n.s) : unread(`z.${m}() with no argument`, n.s);
23593
+ case "intersection":
23594
+ return { k: "all", parts: a.map((x) => evalZod(x, ctx)) };
23595
+ case "preprocess":
23596
+ return a[1] ? evalZod(a[1], ctx) : unread("z.preprocess() with no schema", n.s);
23597
+ case "pipe":
23598
+ return a[0] ? evalZod(a[0], ctx) : unread("z.pipe() with no schema", n.s);
23599
+ case "lazy": {
23600
+ const f = a[0];
23601
+ if (f?.k === "fn" && f.body) return evalZod(f.body, ctx);
23602
+ return unread("z.lazy() whose body is not a single returned expression", n.s);
23603
+ }
23604
+ default:
23605
+ return unread(`z.${m}()`, n.s);
23606
+ }
23607
+ }
23608
+ function zodMethod(base, m, n, ctx) {
23609
+ if (base.k === "unread") return base;
23610
+ if (IDENTITY_METHODS.has(m)) return base;
23611
+ const a = n.args;
23612
+ switch (m) {
23613
+ case "nullable":
23614
+ case "nullish":
23615
+ return nullable(base, n.s);
23616
+ case "or":
23617
+ return {
23618
+ k: "union",
23619
+ branches: [base, a[0] ? evalZod(a[0], ctx) : unread(".or() with no argument", n.s)],
23620
+ at: n.s
23621
+ };
23622
+ case "and":
23623
+ return {
23624
+ k: "all",
23625
+ parts: [base, a[0] ? evalZod(a[0], ctx) : unread(".and() with no argument", n.s)]
23626
+ };
23627
+ case "array":
23628
+ return { k: "array", items: base, prefix: [], at: n.s };
23629
+ case "unwrap":
23630
+ return base.k === "union" ? { ...base, branches: base.branches.filter((b) => b.k !== "null") } : base;
23631
+ case "extend":
23632
+ case "merge":
23633
+ case "safeExtend": {
23634
+ if (base.k !== "object") return unread(`.${m}() on a non-object schema`, n.s);
23635
+ const more = a[0] ? evalZod(a[0], ctx) : unread(`.${m}() with no argument`, n.s);
23636
+ if (more.k === "object") return { ...base, props: [...base.props, ...more.props] };
23637
+ return { ...base, props: [...base.props, { label: "...", schema: more, at: n.s }] };
23638
+ }
23639
+ case "pick":
23640
+ case "omit": {
23641
+ if (base.k !== "object" || a[0]?.k !== "obj")
23642
+ return unread(`.${m}() with a mask the reader cannot read`, n.s);
23643
+ const keys = new Set(
23644
+ a[0].entries.filter((e) => e.kind === "prop").map((e) => e.key)
23645
+ );
23646
+ return {
23647
+ ...base,
23648
+ props: base.props.filter((p) => m === "pick" ? keys.has(p.label) : !keys.has(p.label))
23649
+ };
23650
+ }
23651
+ case "keyof":
23652
+ return SCALAR;
23653
+ default:
23654
+ return unread(`method .${m}()`, n.s);
23655
+ }
23656
+ }
23657
+ var UNREAD_KEY = "__s43_unread__";
23658
+ var jsonOffsets = /* @__PURE__ */ new WeakMap();
23659
+ var jsonKeyOffsets = /* @__PURE__ */ new WeakMap();
23660
+ function literalValue(n, ctx, depth = 0) {
23661
+ if (depth > 30) return { [UNREAD_KEY]: "literal nested deeper than 30" };
23662
+ switch (n.k) {
23663
+ case "lit":
23664
+ return n.v;
23665
+ case "arr": {
23666
+ const out = n.items.map((x) => literalValue(x, ctx, depth + 1));
23667
+ jsonOffsets.set(out, n.s);
23668
+ return out;
23669
+ }
23670
+ case "obj": {
23671
+ const out = {};
23672
+ const keys = /* @__PURE__ */ new Map();
23673
+ for (const e of n.entries) {
23674
+ if (e.kind === "prop") {
23675
+ out[e.key] = literalValue(e.value, ctx, depth + 1);
23676
+ keys.set(e.key, e.s);
23677
+ } else if (e.kind === "spread") {
23678
+ const v = literalValue(e.value, ctx, depth + 1);
23679
+ if (v && typeof v === "object" && !Array.isArray(v) && !(UNREAD_KEY in v))
23680
+ Object.assign(out, v);
23681
+ else out[UNREAD_KEY] = `spread ...${describeNode(e.value)}`;
23682
+ } else out[UNREAD_KEY] = e.form;
23683
+ }
23684
+ jsonOffsets.set(out, n.s);
23685
+ jsonKeyOffsets.set(out, keys);
23686
+ return out;
23687
+ }
23688
+ case "id": {
23689
+ const r = resolveRef(n.name, n.s, ctx);
23690
+ if (isUnread(r)) return { [UNREAD_KEY]: r.form };
23691
+ return literalValue(r.node, r.ctx, depth + 1);
23692
+ }
23693
+ default:
23694
+ return { [UNREAD_KEY]: describeNode(n) };
23695
+ }
23696
+ }
23697
+ function isObj(v) {
23698
+ return typeof v === "object" && v !== null && !Array.isArray(v);
23699
+ }
23700
+ function jsonToS(v, root, seen, depth = 0) {
23701
+ if (depth > 40) return unread("JSON schema nested deeper than 40");
23702
+ if (typeof v === "boolean") return { k: "any" };
23703
+ if (!isObj(v)) return unread(`JSON schema value ${Array.isArray(v) ? "array" : typeof v}`);
23704
+ const at = jsonOffsets.get(v);
23705
+ if (UNREAD_KEY in v) return unread(String(v[UNREAD_KEY]), at);
23706
+ const parts = [];
23707
+ const ref = v.$ref;
23708
+ if (ref !== void 0) {
23709
+ if (typeof ref !== "string") return unread("$ref that is not a string", at);
23710
+ const m = ref.match(/^#\/(\$defs|definitions)\/(.+)$/);
23711
+ if (!m) return unread(`$ref ${ref} (not a local #/$defs or #/definitions reference)`, at);
23712
+ if (seen.has(ref)) return { k: "any" };
23713
+ const defs = isObj(root.root) ? root.root[m[1]] : void 0;
23714
+ const target = isObj(defs) ? defs[m[2].replace(/~1/g, "/").replace(/~0/g, "~")] : void 0;
23715
+ if (target === void 0) return unread(`$ref ${ref} unresolvable`, at);
23716
+ parts.push(jsonToS(target, root, /* @__PURE__ */ new Set([...seen, ref]), depth + 1));
23717
+ }
23718
+ const sub = (x) => jsonToS(x, root, seen, depth + 1);
23719
+ for (const kw of ["anyOf", "oneOf"]) {
23720
+ const opts = v[kw];
23721
+ if (opts === void 0) continue;
23722
+ if (!Array.isArray(opts)) parts.push(unread(`${kw} that is not an array`, at));
23723
+ else parts.push({ k: "union", branches: opts.map(sub), at });
23724
+ }
23725
+ if (v.allOf !== void 0) {
23726
+ if (!Array.isArray(v.allOf)) parts.push(unread("allOf that is not an array", at));
23727
+ else parts.push({ k: "all", parts: v.allOf.map(sub) });
23728
+ }
23729
+ const typed = (t) => {
23730
+ if (t === "array") {
23731
+ const items = v.items;
23732
+ const prefix = v.prefixItems;
23733
+ return {
23734
+ k: "array",
23735
+ items: Array.isArray(items) ? null : items === void 0 ? null : sub(items),
23736
+ prefix: Array.isArray(prefix) ? prefix.map(sub) : Array.isArray(items) ? items.map(sub) : [],
23737
+ at
23738
+ };
23739
+ }
23740
+ if (t === "object") return objectOf();
23741
+ if (t === "null") return { k: "null" };
23742
+ return { k: "scalar", name: t };
23743
+ };
23744
+ const objectOf = () => {
23745
+ const props = [];
23746
+ const keyAt = jsonKeyOffsets.get(isObj(v.properties) ? v.properties : {}) ?? /* @__PURE__ */ new Map();
23747
+ if (isObj(v.properties))
23748
+ for (const [k, s] of Object.entries(v.properties))
23749
+ props.push({ label: k, schema: sub(s), at: keyAt.get(k) });
23750
+ else if (v.properties !== void 0)
23751
+ props.push({ label: "properties", schema: unread("properties that is not an object", at) });
23752
+ if (isObj(v.additionalProperties))
23753
+ props.push({ label: "*", schema: sub(v.additionalProperties), at });
23754
+ if (isObj(v.patternProperties))
23755
+ for (const s of Object.values(v.patternProperties))
23756
+ props.push({ label: "*", schema: sub(s), at });
23757
+ return { k: "object", props, at };
23758
+ };
23759
+ const type = v.type;
23760
+ if (Array.isArray(type)) {
23761
+ parts.push({
23762
+ k: "union",
23763
+ branches: type.map(
23764
+ (t) => typeof t === "string" ? typed(t) : unread("type entry that is not a string", at)
23765
+ ),
23766
+ at
23767
+ });
23768
+ } else if (typeof type === "string") {
23769
+ parts.push(typed(type));
23770
+ } else if (type !== void 0) {
23771
+ parts.push(unread("type that is neither a string nor an array", at));
23772
+ } else if (v.properties !== void 0 || v.additionalProperties !== void 0 || v.patternProperties !== void 0) {
23773
+ parts.push(objectOf());
23774
+ } else if (v.items !== void 0 || v.prefixItems !== void 0) {
23775
+ parts.push(typed("array"));
23776
+ }
23777
+ if (parts.length === 0)
23778
+ return v.enum !== void 0 || v.const !== void 0 ? SCALAR : { k: "any" };
23779
+ return parts.length === 1 ? parts[0] : { k: "all", parts };
23780
+ }
23781
+ function walk2(s, path, useAt, out, loc) {
23782
+ const offsetsFor = (...offs) => offs.filter((o) => o !== void 0);
23783
+ switch (s.k) {
23784
+ case "union": {
23785
+ const branches = flatten(s.branches);
23786
+ const arrays = branches.filter((b) => b.k === "array").length;
23787
+ const others = branches.filter(
23788
+ (b) => b.k !== "array" && b.k !== "null" && b.k !== "unread"
23789
+ ).length;
23790
+ const unreadB = branches.filter((b) => b.k === "unread");
23791
+ if (arrays > 0 && others > 0) {
23792
+ const use = loc(useAt ?? s.at);
23793
+ const origin = loc(s.at ?? useAt);
23794
+ out.push({
23795
+ path,
23796
+ kind: "violation",
23797
+ offsets: offsetsFor(useAt, s.at),
23798
+ anchor: use.anchor,
23799
+ ...origin.anchor !== use.anchor ? { origin: origin.anchor } : {}
23800
+ });
23801
+ } else if (unreadB.length > 0) {
23802
+ out.push({
23803
+ path,
23804
+ kind: "unread",
23805
+ form: `union branch ${unreadB.map((b) => b.form).join(", ")}`,
23806
+ offsets: [],
23807
+ anchor: loc(unreadB[0].at ?? s.at ?? useAt).anchor
23808
+ });
23809
+ }
23810
+ for (const b of branches) if (b.k !== "unread") walk2(b, path, useAt, out, loc);
23811
+ return;
23812
+ }
23813
+ case "array":
23814
+ if (s.items) walk2(s.items, `${path}[]`, useAt, out, loc);
23815
+ s.prefix.forEach((p, i) => walk2(p, `${path}[${i}]`, useAt, out, loc));
23816
+ return;
23817
+ case "object":
23818
+ for (const p of s.props) walk2(p.schema, `${path}.${p.label}`, p.at ?? useAt, out, loc);
23819
+ return;
23820
+ case "all":
23821
+ for (const p of s.parts) walk2(p, path, useAt, out, loc);
23822
+ return;
23823
+ case "unread":
23824
+ out.push({
23825
+ path,
23826
+ kind: "unread",
23827
+ form: s.form,
23828
+ offsets: [],
23829
+ anchor: loc(s.at ?? useAt).anchor
23830
+ });
23831
+ return;
23832
+ default:
23833
+ return;
23834
+ }
23835
+ }
23836
+ var ANNOTATION_KEYS = /* @__PURE__ */ new Set([
23837
+ "title",
23838
+ "readOnlyHint",
23839
+ "destructiveHint",
23840
+ "idempotentHint",
23841
+ "openWorldHint"
23842
+ ]);
23843
+ function isJsonLiteral(n) {
23844
+ if (n.k !== "obj") return false;
23845
+ for (const e of n.entries) {
23846
+ if (e.kind !== "prop") continue;
23847
+ if (e.key === "type" && e.value.k === "lit" && typeof e.value.v === "string") return true;
23848
+ if ((e.key === "anyOf" || e.key === "oneOf" || e.key === "allOf") && e.value.k === "arr")
23849
+ return true;
23850
+ if ((e.key === "properties" || e.key === "$defs") && e.value.k === "obj") return true;
23851
+ }
23852
+ return false;
23853
+ }
23854
+ function schemaValue(n) {
23855
+ return isJsonLiteral(n) ? { kind: "json", node: n } : { kind: "zod", node: n };
23856
+ }
23857
+ function fromConfig(obj, ctx) {
23858
+ const props = obj.entries.filter((e) => e.kind === "prop");
23859
+ const input = props.find((e) => e.key === "inputSchema");
23860
+ if (input) return schemaValue(input.value);
23861
+ const literalValued = (e) => isStringish(e.value, ctx) || e.value.k === "lit" && typeof e.value.v !== "string";
23862
+ if (props.some((e) => (e.key === "description" || e.key === "title") && isStringish(e.value, ctx)))
23863
+ return { kind: "none" };
23864
+ if (props.some((e) => e.key === "outputSchema" || e.key === "annotations" || e.key === "_meta"))
23865
+ return { kind: "none" };
23866
+ if (props.length > 0 && props.every((e) => ANNOTATION_KEYS.has(e.key) && literalValued(e)))
23867
+ return { kind: "none" };
23868
+ return null;
23869
+ }
23870
+ function isStringish(n, ctx) {
23871
+ if (n.k === "lit" && typeof n.v === "string") return true;
23872
+ if (n.k === "other") return n.strConcat || n.form.startsWith("template");
23873
+ if (n.k === "id") {
23874
+ const d = ctx.b.decls.get(n.name);
23875
+ if (d && d.length === 1) return isStringish(d[0], ctx);
23876
+ }
23877
+ return false;
23878
+ }
23879
+ function locateSchema(file, toolName, anchorLine) {
23880
+ const lx = lex(file);
23881
+ const ctx = moduleCtx(file, null);
23882
+ const lineStart = lx.base + (lx.lineStarts[anchorLine - 1] ?? 0);
23883
+ const toks = lx.toks;
23884
+ const isName = (t) => {
23885
+ if (t.t === "str") return t.v === toolName;
23886
+ if (t.t !== "id") return false;
23887
+ const d = ctx.b.decls.get(t.v);
23888
+ return d !== void 0 && d.length === 1 && d[0].k === "lit" && d[0].v === toolName;
23889
+ };
23890
+ let nameIdx = -1;
23891
+ const anchorEnd = lx.base + (lx.lineStarts[anchorLine] ?? lx.text.length);
23892
+ for (let i = 0; i < toks.length && nameIdx < 0; i++) {
23893
+ const t = toks[i];
23894
+ if (t.s < lineStart) continue;
23895
+ if (t.s >= anchorEnd) break;
23896
+ if (t.t !== "p" || t.v !== "(" || toks[i - 1]?.t !== "id") continue;
23897
+ const end = new Parser(lx, i).skipGroup(i);
23898
+ let depth2 = 0;
23899
+ for (let j = i; j < end; j++) {
23900
+ const tj = toks[j];
23901
+ if (tj.t === "p" && OPEN2[tj.v]) depth2++;
23902
+ else if (tj.t === "p" && (tj.v === ")" || tj.v === "]" || tj.v === "}")) depth2--;
23903
+ else if (depth2 === 1 && isName(tj) && (toks[j - 1].v === "(" || toks[j - 1].v === ",")) {
23904
+ nameIdx = j;
23905
+ break;
23906
+ }
23907
+ }
23908
+ }
23909
+ for (let i = 0; i < toks.length && nameIdx < 0; i++) {
23910
+ const t = toks[i];
23911
+ if (t.s < lineStart) continue;
23912
+ if (t.s >= anchorEnd) break;
23913
+ if (isName(t)) nameIdx = i;
23914
+ }
23915
+ if (nameIdx < 0)
23916
+ return {
23917
+ kind: "unread",
23918
+ form: `registration of ${toolName}: the name argument was not found`,
23919
+ at: lineStart
23920
+ };
23921
+ let depth = 0;
23922
+ let openIdx = -1;
23923
+ for (let j = nameIdx - 1; j >= 0; j--) {
23924
+ const t = toks[j];
23925
+ if (t.t !== "p") continue;
23926
+ if (t.v === ")" || t.v === "]" || t.v === "}") depth++;
23927
+ else if (t.v === "(" || t.v === "[" || t.v === "{") {
23928
+ if (depth === 0) {
23929
+ openIdx = j;
23930
+ break;
23931
+ }
23932
+ depth--;
23933
+ }
23934
+ }
23935
+ if (openIdx < 0)
23936
+ return {
23937
+ kind: "unread",
23938
+ form: `registration of ${toolName}: no enclosing call or object`,
23939
+ at: toks[nameIdx].s
23940
+ };
23941
+ const open = toks[openIdx];
23942
+ if (open.v === "{") {
23943
+ const obj = new Parser(lx, openIdx).parseExpr();
23944
+ if (obj.k !== "obj") return { kind: "unread", form: `descriptor of ${toolName}`, at: open.s };
23945
+ const input = obj.entries.find((e) => e.kind === "prop" && e.key === "inputSchema");
23946
+ return input && input.kind === "prop" ? schemaValue(input.value) : { kind: "none" };
23947
+ }
23948
+ if (open.v !== "(")
23949
+ return { kind: "unread", form: `registration of ${toolName} inside ${open.v}`, at: open.s };
23950
+ const args = readArgs(lx, openIdx);
23951
+ const k = args.findIndex((a) => a.s === toks[nameIdx].s);
23952
+ if (k < 0)
23953
+ return {
23954
+ kind: "unread",
23955
+ form: `registration of ${toolName}: name argument not at top level`,
23956
+ at: open.s
23957
+ };
23958
+ for (const a of args.slice(k + 1)) {
23959
+ if (a.k === "fn") return { kind: "none" };
23960
+ if (isStringish(a, ctx)) continue;
23961
+ let node = a;
23962
+ if (node.k === "id") {
23963
+ const d = ctx.b.decls.get(node.name);
23964
+ if (d && d.length === 1 && d[0].k === "obj") node = d[0];
23965
+ else if (d && d.length === 1 && d[0].k === "fn") return { kind: "none" };
23966
+ }
23967
+ if (node.k === "obj") {
23968
+ const cfg = fromConfig(node, ctx);
23969
+ if (cfg) return cfg;
23970
+ return schemaValue(node);
23971
+ }
23972
+ return { kind: "zod", node: a };
23973
+ }
23974
+ return { kind: "none" };
23975
+ }
23976
+ function readArgs(lx, openIdx) {
23977
+ const p = new Parser(lx, openIdx);
23978
+ const end = p.skipGroup(openIdx);
23979
+ const out = [];
23980
+ p.i = openIdx + 1;
23981
+ while (p.i < end - 1) {
23982
+ if (p.isP(",")) {
23983
+ p.i++;
23984
+ continue;
23985
+ }
23986
+ const before = p.i;
23987
+ out.push(p.parseExpr());
23988
+ if (p.i === before) p.i++;
23989
+ while (p.i < end - 1 && !p.isP(",")) p.i++;
23990
+ }
23991
+ return out;
23992
+ }
23993
+ function exemption(offsets) {
23994
+ for (const off of offsets) {
23995
+ const at = locate(off);
23996
+ if (!at) continue;
23997
+ const lx = lex(at.file);
23998
+ for (const ln of [at.line, at.line - 1]) {
23999
+ const c = lx.comments.get(ln);
24000
+ const m = c?.match(MARKER_RE);
24001
+ if (m && m[1].trim().length >= MIN_REASON) return m[1].trim();
24002
+ }
24003
+ }
24004
+ return null;
24005
+ }
24006
+ function verdictOf(j, scope, anchorFallback) {
24007
+ const ex = j.exempt.length > 0 ? ` Exempted (${j.exempt.length}): ${j.exempt.map((e) => `${e.path} (${e.anchor}) \u2014 "${e.reason}"`).join("; ")}.` : "";
24008
+ let decided;
24009
+ if (j.violations.length > 0) {
24010
+ decided = {
24011
+ id: ID,
24012
+ anchor: j.violations[0].anchor,
24013
+ state: "non-conforming",
24014
+ verdict: `${j.violations.length} of ${j.argumentCount} tool input site(s) declare a union mixing an array and a non-array value, which clients send in different shapes (${RULE}): ${j.violations.map((v) => `${v.path} (${v.anchor}${v.origin ? `, union at ${v.origin}` : ""})`).join(", ")}.${ex}`
24015
+ };
24016
+ } else {
24017
+ decided = {
24018
+ id: ID,
24019
+ anchor: anchorFallback,
24020
+ state: "present",
24021
+ verdict: `${j.toolCount} tool(s) read (${scope}), ${j.argumentCount} input site(s): no input argument mixes an array and a non-array value (${RULE}).${ex}`
24022
+ };
24023
+ }
24024
+ return settle(ID, decided, j.unread);
24025
+ }
24026
+ function judgeSites(sites, served, j) {
24027
+ for (const s of sites) {
24028
+ if (s.kind === "unread") {
24029
+ j.unread.push({
24030
+ anchor: s.anchor,
24031
+ reason: `${s.path}: ${s.form ?? "unread form"} (${RULE})`
24032
+ });
24033
+ continue;
24034
+ }
24035
+ const reason = served ? null : exemption(s.offsets);
24036
+ if (reason) j.exempt.push({ ...s, reason });
24037
+ else j.violations.push(s);
24038
+ }
24039
+ }
24040
+ function countArgs(s) {
24041
+ if (s.k === "object") return s.props.length;
24042
+ if (s.k === "all") return s.parts.reduce((n, p) => n + countArgs(p), 0);
24043
+ return 1;
24044
+ }
24045
+ function dedupe(sites) {
24046
+ const seen = /* @__PURE__ */ new Set();
24047
+ return sites.filter((s) => {
24048
+ const k = `${s.kind}|${s.path}|${s.form ?? ""}`;
24049
+ if (seen.has(k)) return false;
24050
+ seen.add(k);
24051
+ return true;
24052
+ });
24053
+ }
24054
+ function runStatic(tree) {
24055
+ const controls = s43Controls();
24056
+ if (!controls.sees || !controls.spares) {
24057
+ throw new Error(
24058
+ `S43 positive control FAILED: sees=${controls.sees} spares=${controls.spares} \u2014 reader broken, verdict untrustworthy`
24059
+ );
24060
+ }
24061
+ const tools = findRegisteredTools(tree).filter(
24062
+ (t) => isProductSource(t.anchor.slice(0, t.anchor.lastIndexOf(":")))
24063
+ );
24064
+ const unresolvedTools = findUnresolvedToolSites(tree).filter(
24065
+ (a) => isProductSource(a.slice(0, a.lastIndexOf(":")))
24066
+ );
24067
+ if (tools.length === 0) {
24068
+ const surface = toolSurfaceAnchor(tree);
24069
+ if (surface || unresolvedTools.length > 0) {
24070
+ const reason = noToolsLocatedReason(tree, `no input schema could be read (${RULE})`);
24071
+ return couldNotJudge(
24072
+ ID,
24073
+ surface ?? unresolvedTools[0],
24074
+ unresolvedTools.length > 0 ? `${reason}; unresolved registration site(s): ${unresolvedTools.join(", ")}` : reason
24075
+ );
24076
+ }
24077
+ return {
24078
+ id: ID,
24079
+ anchor: tree.root,
24080
+ state: "absent",
24081
+ verdict: `no MCP tool registered in product source \u2014 ${RULE} n/a`
24082
+ };
24083
+ }
24084
+ const byRel = new Map(tree.files.map((f) => [f.rel, f]));
24085
+ const j = {
24086
+ violations: [],
24087
+ exempt: [],
24088
+ unread: [],
24089
+ argumentCount: 0,
24090
+ toolCount: tools.length
24091
+ };
24092
+ for (const a of unresolvedTools)
24093
+ j.unread.push({
24094
+ anchor: a,
24095
+ reason: `a tool registered here has a name the scan cannot resolve, so its input schema is unread (${RULE})`
24096
+ });
24097
+ for (const tool of tools) {
24098
+ const cut = tool.anchor.lastIndexOf(":");
24099
+ const file = byRel.get(tool.anchor.slice(0, cut));
24100
+ const line = Number(tool.anchor.slice(cut + 1));
24101
+ if (!file) {
24102
+ j.unread.push({
24103
+ anchor: tool.anchor,
24104
+ reason: `${tool.name}: registration file not in the scanned tree (${RULE})`
24105
+ });
24106
+ continue;
24107
+ }
24108
+ const loc = (off) => {
24109
+ const at = off === void 0 ? null : locate(off);
24110
+ return at ? { line: at.line, anchor: `${at.file.rel}:${at.line}` } : { anchor: tool.anchor };
24111
+ };
24112
+ const located = locateSchema(file, tool.name, line);
24113
+ if (located.kind === "none") continue;
24114
+ if (located.kind === "unread") {
24115
+ j.unread.push({
24116
+ anchor: loc(located.at).anchor,
24117
+ reason: `${tool.name}: ${located.form} (${RULE})`
24118
+ });
24119
+ continue;
24120
+ }
24121
+ const ctx = moduleCtx(file, tree);
24122
+ const finalSchema = located.kind === "json" ? jsonSchemaOf(located.node, ctx) : evalZod(located.node, ctx);
24123
+ j.argumentCount += countArgs(finalSchema);
24124
+ const sites = [];
24125
+ walk2(finalSchema, tool.name, void 0, sites, loc);
24126
+ judgeSites(dedupe(sites), false, j);
24127
+ }
24128
+ return verdictOf(j, "static, from source", tools[0].anchor);
24129
+ }
24130
+ function jsonSchemaOf(n, ctx) {
24131
+ const v = literalValue(n, ctx);
24132
+ return jsonToS(v, { root: v }, /* @__PURE__ */ new Set());
24133
+ }
24134
+ function runServedHalf(runtime) {
24135
+ const anchor = `${runtime.root} (served)`;
24136
+ if (runtime.launchError)
24137
+ return couldNotJudge(
24138
+ ID,
24139
+ anchor,
24140
+ `the server could not be started/introspected, so no served inputSchema was read: ${runtime.launchError} (${RULE})`
24141
+ );
24142
+ const tools = runtime.tools;
24143
+ if (tools.length === 0)
24144
+ return {
24145
+ id: ID,
24146
+ anchor,
24147
+ state: "absent",
24148
+ verdict: `the running server serves no tool \u2014 ${RULE} n/a`
24149
+ };
24150
+ const j = {
24151
+ violations: [],
24152
+ exempt: [],
24153
+ unread: [],
24154
+ argumentCount: 0,
24155
+ toolCount: tools.length
24156
+ };
24157
+ for (const t of tools) {
24158
+ if (t.inputSchema === void 0) {
24159
+ j.unread.push({
24160
+ anchor: `${anchor} ${t.name}`,
24161
+ reason: `${t.name}: the introspection recorded no inputSchema for this served tool (tools/list inputSchema unread) (${RULE})`
24162
+ });
24163
+ continue;
24164
+ }
24165
+ const schema = jsonToS(t.inputSchema, { root: t.inputSchema }, /* @__PURE__ */ new Set());
24166
+ j.argumentCount += countArgs(schema);
24167
+ const sites = [];
24168
+ walk2(schema, t.name, void 0, sites, () => ({ anchor: `${anchor} tools/list ${t.name}` }));
24169
+ judgeSites(dedupe(sites), true, j);
24170
+ }
24171
+ return verdictOf(j, "served tools/list inputSchema", anchor);
24172
+ }
24173
+ function controlFile(text) {
24174
+ return {
24175
+ path: "<s43-control>.ts",
24176
+ rel: "<s43-control>",
24177
+ lines: text.split("\n").map((raw, i) => ({ n: i + 1, raw, comment: false }))
24178
+ };
24179
+ }
24180
+ function controlSites(text) {
24181
+ const file = controlFile(text);
24182
+ const located = locateSchema(file, "c", 3);
24183
+ if (located.kind !== "zod") return [];
24184
+ const ctx = moduleCtx(file, null);
24185
+ const sites = [];
24186
+ walk2(evalZod(located.node, ctx), "c", void 0, sites, () => ({ anchor: "<s43-control>" }));
24187
+ return sites;
24188
+ }
24189
+ function s43Controls() {
24190
+ const head = 'import { z } from "zod";\nexport function r(server: any) {\n server.registerTool("c", { description: "d", inputSchema: ';
24191
+ const tail = " }, async () => ({ content: [] }));\n}\n";
24192
+ const red = controlSites(`${head}{ ids: z.union([z.array(z.string()), z.string()]) }${tail}`);
24193
+ const green = controlSites(
24194
+ `${head}{ ids: z.union([z.string(), z.number()]), o: z.array(z.string()).nullable() }${tail}`
24195
+ );
24196
+ return {
24197
+ sees: red.length === 1 && red[0].kind === "violation" && red[0].path === "c.ids",
24198
+ spares: green.length === 0
24199
+ };
24200
+ }
24201
+ var s43UnionInput = {
24202
+ id: ID,
24203
+ rule: RULE,
24204
+ pin: STANDARD_PIN,
24205
+ run: runStatic,
24206
+ runServed: (runtime) => runServedHalf(runtime)
24207
+ };
24208
+
22065
24209
  // src/detectors/index.ts
22066
24210
  var registered = [
22067
24211
  d2,
@@ -22167,6 +24311,7 @@ var registered = [
22167
24311
  s39UpstreamError,
22168
24312
  s40UpstreamRowsNarrowed,
22169
24313
  s41LakeReader,
24314
+ s43UnionInput,
22170
24315
  e5ExtensionIsolation,
22171
24316
  a3SandboxRespected,
22172
24317
  a4WcagGate,
@@ -22200,6 +24345,7 @@ var READS_CODE = /* @__PURE__ */ new Set([
22200
24345
  "S-39",
22201
24346
  "S-40",
22202
24347
  "S-41",
24348
+ "S-43",
22203
24349
  "E-5",
22204
24350
  "A-3"
22205
24351
  ]);
@@ -22570,7 +24716,7 @@ const onMessage = (msg) => {
22570
24716
  const props = schemaOf(t).properties;
22571
24717
  return Boolean(props && typeof props === "object" && Object.prototype.hasOwnProperty.call(props, "cursor"));
22572
24718
  };
22573
- tools = served.map((t) => ({ name: String(t && t.name), description: t && typeof t.description === "string" ? t.description : undefined, cursorArgument: takesCursor(t) }));
24719
+ tools = served.map((t) => ({ name: String(t && t.name), description: t && typeof t.description === "string" ? t.description : undefined, cursorArgument: takesCursor(t), inputSchema: t && t.inputSchema && typeof t.inputSchema === "object" && !Array.isArray(t.inputSchema) ? t.inputSchema : undefined }));
22574
24720
  const methods = ["tools/list"];
22575
24721
  if (capabilities.resources) methods.push("resources/list", "resources/templates/list");
22576
24722
  if (capabilities.prompts) methods.push("prompts/list");
@@ -22636,17 +24782,17 @@ const onMessage = (msg) => {
22636
24782
  transport = plan.kind === "http" ? makeHttpTransport() : makeStdioTransport();
22637
24783
  send({ jsonrpc: "2.0", id: 1, method: "initialize", params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "mcp-doctor", version: "0" } } });
22638
24784
  `;
22639
- var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
24785
+ var isObj2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
22640
24786
  var outcomeOf = (v) => v === "answered" || v === "refused" ? v : "no-answer";
22641
24787
  function readServed(raw) {
22642
- if (!isObj(raw)) return void 0;
24788
+ if (!isObj2(raw)) return void 0;
22643
24789
  const readList = (l) => {
22644
- const r = isObj(l) ? l : {};
24790
+ const r = isObj2(l) ? l : {};
22645
24791
  const method = typeof r.method === "string" ? r.method : "<unnamed list>";
22646
- const fu = isObj(r.followUp) ? r.followUp : void 0;
24792
+ const fu = isObj2(r.followUp) ? r.followUp : void 0;
22647
24793
  return {
22648
24794
  method,
22649
- outcome: isObj(l) ? outcomeOf(r.outcome) : "no-answer",
24795
+ outcome: isObj2(l) ? outcomeOf(r.outcome) : "no-answer",
22650
24796
  ...typeof r.detail === "string" ? { detail: r.detail } : {},
22651
24797
  ...Array.isArray(r.resultKeys) ? { resultKeys: r.resultKeys.map(String) } : {},
22652
24798
  ...r.resultType !== void 0 ? { resultType: r.resultType } : {},
@@ -22665,26 +24811,26 @@ function readServed(raw) {
22665
24811
  };
22666
24812
  const lists = (Array.isArray(raw.lists) ? raw.lists : []).map(readList);
22667
24813
  const vp = raw.versionProbe;
22668
- const versionProbe = isObj(vp) && vp.kind === "statuses" && typeof vp.supportedVersion === "string" && typeof vp.supported === "number" && typeof vp.unsupported === "number" ? {
24814
+ const versionProbe = isObj2(vp) && vp.kind === "statuses" && typeof vp.supportedVersion === "string" && typeof vp.supported === "number" && typeof vp.unsupported === "number" ? {
22669
24815
  kind: "statuses",
22670
24816
  supportedVersion: vp.supportedVersion,
22671
24817
  supported: vp.supported,
22672
24818
  unsupported: vp.unsupported
22673
24819
  } : {
22674
24820
  kind: "not-run",
22675
- reason: isObj(vp) && vp.kind === "not-run" && typeof vp.reason === "string" ? vp.reason : "unreadable version-probe record"
24821
+ reason: isObj2(vp) && vp.kind === "not-run" && typeof vp.reason === "string" ? vp.reason : "unreadable version-probe record"
22676
24822
  };
22677
24823
  const as = raw.authServer;
22678
- const authServer = isObj(as) && as.kind === "document" && typeof as.url === "string" && typeof as.status === "number" && isObj(as.document) ? { kind: "document", url: as.url, status: as.status, document: as.document } : isObj(as) && as.kind === "unavailable" && typeof as.url === "string" ? {
24824
+ const authServer = isObj2(as) && as.kind === "document" && typeof as.url === "string" && typeof as.status === "number" && isObj2(as.document) ? { kind: "document", url: as.url, status: as.status, document: as.document } : isObj2(as) && as.kind === "unavailable" && typeof as.url === "string" ? {
22679
24825
  kind: "unavailable",
22680
24826
  url: as.url,
22681
24827
  reason: typeof as.reason === "string" ? as.reason : "no reason given"
22682
24828
  } : {
22683
24829
  kind: "not-run",
22684
- reason: isObj(as) && as.kind === "not-run" && typeof as.reason === "string" ? as.reason : "unreadable authorization-server record"
24830
+ reason: isObj2(as) && as.kind === "not-run" && typeof as.reason === "string" ? as.reason : "unreadable authorization-server record"
22685
24831
  };
22686
24832
  return {
22687
- capabilities: isObj(raw.capabilities) ? raw.capabilities : {},
24833
+ capabilities: isObj2(raw.capabilities) ? raw.capabilities : {},
22688
24834
  ...typeof raw.protocolVersion === "string" ? { protocolVersion: raw.protocolVersion } : {},
22689
24835
  lists,
22690
24836
  calls: (Array.isArray(raw.calls) ? raw.calls : []).map(readList),
@@ -22875,7 +25021,8 @@ function introspect(plan, root, evalSource, expectedCommit, evalsNote, secrets)
22875
25021
  const count = evals.counts.get(name);
22876
25022
  const base = t.description ? { name, description: t.description } : { name };
22877
25023
  const withCursor = t.cursorArgument === true ? { ...base, cursorArgument: true } : base;
22878
- return count === void 0 ? withCursor : { ...withCursor, evalCaseCount: count };
25024
+ const withSchema = t.inputSchema ? { ...withCursor, inputSchema: t.inputSchema } : withCursor;
25025
+ return count === void 0 ? withSchema : { ...withSchema, evalCaseCount: count };
22879
25026
  });
22880
25027
  return {
22881
25028
  root,