@vantageos/mcp-doctor 0.12.0 → 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";
@@ -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`;
@@ -5997,7 +5997,7 @@ function untouchedParams(s, params, names, bStart, bEnd, fwdOpen, fwdClose) {
5997
5997
  }
5998
5998
  function toolRegistrations(tree) {
5999
5999
  const regs = [];
6000
- const unread = [];
6000
+ const unread2 = [];
6001
6001
  for (const c of callsMatching(
6002
6002
  tree,
6003
6003
  /^(?:[\w$]+\.)+(?:tool|registerTool|registerToolTask|setRequestHandler)$|^(?:registerTool|registerToolTask)$/
@@ -6012,7 +6012,7 @@ function toolRegistrations(tree) {
6012
6012
  if (/^(?:[\w$]+\.)*[\w$]*RequestSchema$/.test(schema) && !/CallToolRequestSchema$/.test(schema))
6013
6013
  continue;
6014
6014
  if (!/CallToolRequestSchema$/.test(schema)) {
6015
- unread.push({
6015
+ unread2.push({
6016
6016
  anchor: c.anchor,
6017
6017
  reason: `${c.anchor} setRequestHandler(${schema.slice(0, 30)}, ...) registers a handler for a request the scan cannot name: whether it dispatches tools/call is unread`
6018
6018
  });
@@ -6079,7 +6079,7 @@ function toolRegistrations(tree) {
6079
6079
  if (h.method !== void 0 && transparent.has(h.method)) continue;
6080
6080
  const anchor = anchorAt(s, h.at);
6081
6081
  const reason = h.method === void 0 ? "" : why.get(h.method);
6082
- unread.push({
6082
+ unread2.push({
6083
6083
  anchor,
6084
6084
  reason: `${anchor} \`${s.code.slice(h.at, h.at + h.len + 12).replace(/\s+/g, "").slice(
6085
6085
  0,
@@ -6089,7 +6089,7 @@ function toolRegistrations(tree) {
6089
6089
  }
6090
6090
  }
6091
6091
  }
6092
- return { regs, unread };
6092
+ return { regs, unread: unread2 };
6093
6093
  }
6094
6094
  function unreadSource(tree) {
6095
6095
  return tree.skippedDirs.filter((d) => /— not read$/.test(d.reason) && isProductSource(d.path)).map((d) => ({
@@ -7103,12 +7103,12 @@ var c11Pagination = {
7103
7103
  };
7104
7104
  }
7105
7105
  const red = [];
7106
- const unread = [];
7106
+ const unread2 = [];
7107
7107
  const ok = [];
7108
7108
  for (const p of probes) {
7109
7109
  const j = judgeCursorProbe(p);
7110
7110
  if (j.kind === "red") red.push(j.text);
7111
- else if (j.kind === "unread") unread.push(j.text);
7111
+ else if (j.kind === "unread") unread2.push(j.text);
7112
7112
  else ok.push(j.text);
7113
7113
  }
7114
7114
  if (red.length > 0) {
@@ -7119,8 +7119,8 @@ var c11Pagination = {
7119
7119
  verdict: `${red.join("; ")} -> an invalid cursor on a protocol list method is -32602; passed as a tool argument it is a tool result with isError: true and structuredContent.error.code "invalid_cursor" (SEP-1303) (C-11)`
7120
7120
  };
7121
7121
  }
7122
- if (unread.length > 0) {
7123
- const reason = `${unread.join("; ")} (C-11)`;
7122
+ if (unread2.length > 0) {
7123
+ const reason = `${unread2.join("; ")} (C-11)`;
7124
7124
  return {
7125
7125
  id: this.id,
7126
7126
  anchor,
@@ -8277,12 +8277,12 @@ var c18StructureManifestInner = {
8277
8277
  let manifestName = kind === "extension" ? "extension.json" : "mcp.json";
8278
8278
  if (kind === "server") {
8279
8279
  const cands = rootCandidates(tree.root);
8280
- const unread = cands.find((c) => c.readError !== void 0);
8281
- if (unread) {
8280
+ const unread2 = cands.find((c) => c.readError !== void 0);
8281
+ if (unread2) {
8282
8282
  return couldNotJudge(
8283
8283
  this.id,
8284
- unread.path,
8285
- `${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)`
8286
8286
  );
8287
8287
  }
8288
8288
  const bad = cands.find((c) => c.role === "unparseable");
@@ -9763,12 +9763,12 @@ var c26SubpackageLockfile = {
9763
9763
  const verdicts = scope.sites.map(gateSite);
9764
9764
  const inventory = renderCoverage(scope.sites, verdicts);
9765
9765
  const analysed = verdicts.filter((v) => v.status === "analysed");
9766
- const unread = verdicts.filter((v) => v.status === "unreadable");
9767
- if (unread.length > 0 && !analysed.some((v) => v.ok === false)) {
9768
- 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}`;
9769
9769
  return {
9770
9770
  id: this.id,
9771
- anchor: unread[0].site.dir,
9771
+ anchor: unread2[0].site.dir,
9772
9772
  state: "could-not-judge",
9773
9773
  reason,
9774
9774
  verdict: `could not judge: ${reason}`
@@ -11435,13 +11435,13 @@ function baseIsResult(file, base, tree) {
11435
11435
  }
11436
11436
  function handRolledBuilder(tree) {
11437
11437
  const scan = fieldWrites(tree, HANDROLLED_FIELDS);
11438
- const unread = [...scan.unread];
11438
+ const unread2 = [...scan.unread];
11439
11439
  for (const k of scan.computed) {
11440
11440
  if (objectReturned(k.file, k.object).kind !== "returned") continue;
11441
11441
  const m = objectMembers(k.file, k.object);
11442
11442
  const member = RESULT_ANCHOR_KEYS.find((key) => m.keys.has(key));
11443
11443
  if (!member) continue;
11444
- unread.push({
11444
+ unread2.push({
11445
11445
  anchor: k.anchor,
11446
11446
  reason: `the computed key \`[${k.expr.slice(0, 40)}]\` at ${k.anchor} sits in a returned result object (it carries \`${member}\`) and may write resultType / ttlMs / cacheScope: which field it writes is unread (D7)`
11447
11447
  });
@@ -11450,7 +11450,7 @@ function handRolledBuilder(tree) {
11450
11450
  const bind = w.object ? objectReturned(w.file, w.object) : w.base && identReturned(w.file, w.base) ? { kind: "returned", how: `\`${w.base}\` returned` } : { kind: "not-returned", how: w.base ? `\`${w.base}\` never returned` : "no base" };
11451
11451
  if (bind.kind === "not-returned") continue;
11452
11452
  if (bind.kind === "unread") {
11453
- unread.push({
11453
+ unread2.push({
11454
11454
  anchor: w.anchor,
11455
11455
  reason: `\`${w.name}\` is written at ${w.anchor} into an object in ${bind.form}: whether a handler returns it is unread (D7)`
11456
11456
  });
@@ -11461,7 +11461,7 @@ function handRolledBuilder(tree) {
11461
11461
  const m = objectMembers(w.file, w.object);
11462
11462
  result = RESULT_PAYLOAD_KEYS.some((k) => m.keys.has(k));
11463
11463
  if (!result && m.spreads.length > 0) {
11464
- unread.push({
11464
+ unread2.push({
11465
11465
  anchor: w.anchor,
11466
11466
  reason: `\`${w.name}\` is written at ${w.anchor} into an object whose other members come from \`...${m.spreads[0]}\`: whether that object is a protocol result is unread (D7)`
11467
11467
  });
@@ -11471,10 +11471,10 @@ function handRolledBuilder(tree) {
11471
11471
  result = baseIsResult(w.file, w.base, tree);
11472
11472
  }
11473
11473
  if (result) {
11474
- return { hand: { file: w.file.rel, line: w.line, field: w.name, form: w.form }, unread };
11474
+ return { hand: { file: w.file.rel, line: w.line, field: w.name, form: w.form }, unread: unread2 };
11475
11475
  }
11476
11476
  }
11477
- return { hand: null, unread };
11477
+ return { hand: null, unread: unread2 };
11478
11478
  }
11479
11479
  function controlTree2(text) {
11480
11480
  const file = {
@@ -11536,7 +11536,7 @@ var d7Inner = {
11536
11536
  };
11537
11537
  }
11538
11538
  if (sdk.kind === "v2") {
11539
- const { hand, unread } = handRolledBuilder(tree);
11539
+ const { hand, unread: unread2 } = handRolledBuilder(tree);
11540
11540
  if (hand) {
11541
11541
  return {
11542
11542
  id: this.id,
@@ -11545,11 +11545,11 @@ var d7Inner = {
11545
11545
  verdict: `hand-rolled result builder (\`${hand.field}\` written by hand as a ${hand.form} into a result object at ${hand.file}:${hand.line}) and @vantageos/mcp-protocol-kit not a dependency -> let the SDK emit resultType/ttlMs/cacheScope (cacheHints) or adopt the kit (D7)`
11546
11546
  };
11547
11547
  }
11548
- if (unread.length > 0) {
11549
- 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}`;
11550
11550
  return {
11551
11551
  id: this.id,
11552
- anchor: unread[0].anchor,
11552
+ anchor: unread2[0].anchor,
11553
11553
  state: "could-not-judge",
11554
11554
  reason,
11555
11555
  verdict: `could not judge: ${reason}`
@@ -12938,7 +12938,7 @@ function findExtensionManifests(tree) {
12938
12938
  } catch {
12939
12939
  return out;
12940
12940
  }
12941
- const walk2 = (dir) => {
12941
+ const walk3 = (dir) => {
12942
12942
  let entries;
12943
12943
  try {
12944
12944
  entries = readdirSync9(dir);
@@ -12960,7 +12960,7 @@ function findExtensionManifests(tree) {
12960
12960
  recordSkip(tree, full, base);
12961
12961
  continue;
12962
12962
  }
12963
- walk2(full);
12963
+ walk3(full);
12964
12964
  } else if (name === "extension.json") {
12965
12965
  if (!st.isFile()) {
12966
12966
  recordSkip(tree, full, base, "not a regular file (FIFO, socket or device) \u2014 not read");
@@ -12970,7 +12970,7 @@ function findExtensionManifests(tree) {
12970
12970
  }
12971
12971
  }
12972
12972
  };
12973
- walk2(base);
12973
+ walk3(base);
12974
12974
  return out;
12975
12975
  }
12976
12976
 
@@ -13619,7 +13619,7 @@ function findHooksDirs(tree, unreadable, gaps) {
13619
13619
  unreadable.push({ anchor, reason });
13620
13620
  }
13621
13621
  };
13622
- const walk2 = (dir) => {
13622
+ const walk3 = (dir) => {
13623
13623
  let entries;
13624
13624
  try {
13625
13625
  entries = readdirSync10(dir);
@@ -13659,10 +13659,10 @@ function findHooksDirs(tree, unreadable, gaps) {
13659
13659
  }
13660
13660
  out.push({ anchor: `${name}/`, tokens });
13661
13661
  }
13662
- walk2(full);
13662
+ walk3(full);
13663
13663
  }
13664
13664
  };
13665
- walk2(base);
13665
+ walk3(base);
13666
13666
  return out;
13667
13667
  }
13668
13668
  var LIFECYCLE_OBJ_RE = /\blifecycle\s*:\s*\{/;
@@ -14178,7 +14178,7 @@ function collectHooksDirSources(tree, unreadable, gaps) {
14178
14178
  unreadable.push({ anchor, reason });
14179
14179
  }
14180
14180
  };
14181
- const walk2 = (dir) => {
14181
+ const walk3 = (dir) => {
14182
14182
  let entries;
14183
14183
  try {
14184
14184
  entries = readdirSync11(dir);
@@ -14233,10 +14233,10 @@ function collectHooksDirSources(tree, unreadable, gaps) {
14233
14233
  });
14234
14234
  }
14235
14235
  }
14236
- walk2(full);
14236
+ walk3(full);
14237
14237
  }
14238
14238
  };
14239
- walk2(base);
14239
+ walk3(base);
14240
14240
  return out;
14241
14241
  }
14242
14242
  var LIFECYCLE_OBJ_RE2 = /\blifecycle\s*:\s*\{/;
@@ -16124,7 +16124,7 @@ function readInstalledAs(tree) {
16124
16124
  continue;
16125
16125
  }
16126
16126
  const files = [];
16127
- const walk2 = (d) => {
16127
+ const walk3 = (d) => {
16128
16128
  let names;
16129
16129
  try {
16130
16130
  names = readdirSync12(d).sort();
@@ -16145,11 +16145,11 @@ function readInstalledAs(tree) {
16145
16145
  out.unread.push(`${full.slice(nm.length + 1)} (not stat'ed: ${e.message})`);
16146
16146
  continue;
16147
16147
  }
16148
- if (st.isDirectory()) walk2(full);
16148
+ if (st.isDirectory()) walk3(full);
16149
16149
  else if (st.isFile() && SOURCE_EXT.test(n) && !n.endsWith(".d.ts")) files.push(full);
16150
16150
  }
16151
16151
  };
16152
- walk2(dir);
16152
+ walk3(dir);
16153
16153
  if (files.length >= MAX_FILES_PER_PACKAGE) {
16154
16154
  out.unread.push(`${dep} (more than ${MAX_FILES_PER_PACKAGE} files: the rest were not read)`);
16155
16155
  }
@@ -16232,7 +16232,7 @@ function delegatedAsElements(tree, fallbackAnchor) {
16232
16232
  const owed = (what) => [
16233
16233
  { status: "owed", text: what, anchor: fallbackAnchor }
16234
16234
  ];
16235
- const 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("; ")})` : "";
16236
16236
  if (!inst.installed) {
16237
16237
  const r = owed(
16238
16238
  "the AS metadata document is written by a dependency, not by this tree, and node_modules is absent: install with the lockfile's manager and re-run, or read the served metadata (--url)"
@@ -16241,7 +16241,7 @@ function delegatedAsElements(tree, fallbackAnchor) {
16241
16241
  }
16242
16242
  if (inst.publishers.length === 0) {
16243
16243
  const r = owed(
16244
- `the AS metadata document is not written by this tree and no installed declared dependency serves ${"`/.well-known/oauth-authorization-server`"}${inst.missing.length > 0 ? ` (declared but not installed: ${inst.missing.slice(0, 5).join(", ")})` : ""}${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)`
16245
16245
  );
16246
16246
  return { g: r, l: r };
16247
16247
  }
@@ -16253,7 +16253,7 @@ function delegatedAsElements(tree, fallbackAnchor) {
16253
16253
  anchor: inst.cimd.anchor
16254
16254
  }
16255
16255
  ] : owed(
16256
- `the installed ${pk} serves the AS metadata but its code does not state ${[inst.cimd ? "" : "client_id_metadata_document_supported: true", inst.none ? "" : '"none" in token_endpoint_auth_methods_supported'].filter(Boolean).join(" nor ")}${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)`
16257
16257
  );
16258
16258
  const l = inst.iss ? [
16259
16259
  {
@@ -16262,7 +16262,7 @@ function delegatedAsElements(tree, fallbackAnchor) {
16262
16262
  anchor: inst.iss.anchor
16263
16263
  }
16264
16264
  ] : owed(
16265
- `the installed ${pk} serves the AS metadata but its code does not state authorization_response_iss_parameter_supported: true${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)`
16266
16266
  );
16267
16267
  return { g, l };
16268
16268
  }
@@ -16840,29 +16840,29 @@ var s9ConfusedDeputy = {
16840
16840
  `${reds.join("; ")} (S-9, positive-control OK)`
16841
16841
  );
16842
16842
  }
16843
- const unread = [];
16843
+ const unread2 = [];
16844
16844
  for (const { file, rows } of proxies) {
16845
16845
  if (!rows.some((r) => CONSENT_CHECK_RE.test(r))) {
16846
- 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)`);
16847
16847
  }
16848
16848
  if (!rows.some((r) => EXACT_RE.test(r))) {
16849
- unread.push(
16849
+ unread2.push(
16850
16850
  `${file.rel}: no equality or membership test of redirect_uri against registered values`
16851
16851
  );
16852
16852
  }
16853
16853
  const stateRows = rows.flatMap((r, i) => STATE_CREATE_RE.test(r) ? [i] : []);
16854
16854
  if (!stateRows.some((i) => RANDOM_RE.test(`${rows[i]}
16855
16855
  ${rows[i + 1] ?? ""}`))) {
16856
- unread.push(
16856
+ unread2.push(
16857
16857
  `${file.rel}: the state is not shown to come from a random source (randomUUID, randomBytes, nanoid ...)`
16858
16858
  );
16859
16859
  }
16860
16860
  }
16861
- if (unread.length > 0) {
16861
+ if (unread2.length > 0) {
16862
16862
  return couldNotJudge(
16863
16863
  this.id,
16864
16864
  `${proxies[0].file.rel}:1`,
16865
- `no S-9 element is contradicted, but the tree does not show: ${unread.join("; ")} (S-9)`
16865
+ `no S-9 element is contradicted, but the tree does not show: ${unread2.join("; ")} (S-9)`
16866
16866
  );
16867
16867
  }
16868
16868
  return presentResult(
@@ -17220,14 +17220,14 @@ var s12ListPagination = {
17220
17220
  const anchor = `${runtime.root} (served list responses)`;
17221
17221
  const methods = declaredListMethods(served.capabilities);
17222
17222
  const red = [];
17223
- const unread = [];
17223
+ const unread2 = [];
17224
17224
  const ok = [];
17225
17225
  for (const m of methods) {
17226
17226
  const l = served.lists.find((x) => x.method === m);
17227
17227
  if (!l) {
17228
- unread.push(`${m}: no record of it in this run`);
17228
+ unread2.push(`${m}: no record of it in this run`);
17229
17229
  } else if (l.outcome !== "answered") {
17230
- unread.push(
17230
+ unread2.push(
17231
17231
  `${m}: ${l.outcome === "refused" ? "refused" : "no answer"} (${l.detail ?? "no detail"})`
17232
17232
  );
17233
17233
  } else if (l.nextCursor === void 0) {
@@ -17239,7 +17239,7 @@ var s12ListPagination = {
17239
17239
  `${m} serves a nextCursor that is not a non-empty string (${JSON.stringify(l.nextCursor)})`
17240
17240
  );
17241
17241
  } else if (!l.followUp || l.followUp.outcome === "no-answer") {
17242
- unread.push(
17242
+ unread2.push(
17243
17243
  `${m}: the served cursor was not presented back (${l.followUp?.detail ?? "no follow-up recorded"})`
17244
17244
  );
17245
17245
  } else if (l.followUp.outcome === "refused") {
@@ -17259,11 +17259,11 @@ var s12ListPagination = {
17259
17259
  };
17260
17260
  }
17261
17261
  const note = undeclaredProbeNote(served.capabilities);
17262
- if (unread.length > 0 || note) {
17262
+ if (unread2.length > 0 || note) {
17263
17263
  return couldNotJudge(
17264
17264
  this.id,
17265
17265
  anchor,
17266
- `served pagination read on ${ok.length > 0 ? ok.join("; ") : "no list method"}; unread: ${[...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)`
17267
17267
  );
17268
17268
  }
17269
17269
  return {
@@ -17833,7 +17833,7 @@ var s15CompletionSecurity = {
17833
17833
  );
17834
17834
  }
17835
17835
  const reds = [];
17836
- const unread = [];
17836
+ const unread2 = [];
17837
17837
  let read = 0;
17838
17838
  for (const h of handlers) {
17839
17839
  let text = "";
@@ -17850,7 +17850,7 @@ var s15CompletionSecurity = {
17850
17850
  text = b ? b.text : "";
17851
17851
  }
17852
17852
  if (text === "") {
17853
- unread.push(h.anchor);
17853
+ unread2.push(h.anchor);
17854
17854
  continue;
17855
17855
  }
17856
17856
  read++;
@@ -17875,7 +17875,7 @@ var s15CompletionSecurity = {
17875
17875
  return couldNotJudge(
17876
17876
  this.id,
17877
17877
  where,
17878
- `the completions surface is present (${where}); handlers read: ${read}${read > 0 ? ", each with input validation and a rate limit" : ""}; sites not read (no body to read): ${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)`
17879
17879
  );
17880
17880
  }
17881
17881
  };
@@ -17994,8 +17994,8 @@ function documentsFootprint(manifestText) {
17994
17994
  } catch {
17995
17995
  return false;
17996
17996
  }
17997
- const walk2 = (v) => {
17998
- if (Array.isArray(v)) return v.some(walk2);
17997
+ const walk3 = (v) => {
17998
+ if (Array.isArray(v)) return v.some(walk3);
17999
17999
  if (v === null || typeof v !== "object") return false;
18000
18000
  for (const [k, val] of Object.entries(v)) {
18001
18001
  if (k === "footprint") {
@@ -18003,11 +18003,11 @@ function documentsFootprint(manifestText) {
18003
18003
  if (Array.isArray(val) && val.length > 0) return true;
18004
18004
  if (val !== null && typeof val === "object" && Object.keys(val).length > 0) return true;
18005
18005
  }
18006
- if (walk2(val)) return true;
18006
+ if (walk3(val)) return true;
18007
18007
  }
18008
18008
  return false;
18009
18009
  };
18010
- return walk2(json);
18010
+ return walk3(json);
18011
18011
  }
18012
18012
 
18013
18013
  // src/detectors/s17-forward-auth.ts
@@ -19144,7 +19144,7 @@ function resultTypeValue(w) {
19144
19144
  function mrtrRounds(tree) {
19145
19145
  const scan = fieldWrites(tree, ["resultType"]);
19146
19146
  const rounds = [];
19147
- const unread = [...scan.unread];
19147
+ const unread2 = [...scan.unread];
19148
19148
  for (const k of scan.computed) {
19149
19149
  const at = computedValueAt(k.file, k.line, k.col);
19150
19150
  if (!at) continue;
@@ -19158,7 +19158,7 @@ function mrtrRounds(tree) {
19158
19158
  }
19159
19159
  }
19160
19160
  if (value !== MRTR_VALUE) continue;
19161
- unread.push({
19161
+ unread2.push({
19162
19162
  anchor: k.anchor,
19163
19163
  reason: `the computed key \`[${k.expr.slice(0, 40)}]\` at ${k.anchor} is written "${MRTR_VALUE}": whether that key is \`resultType\` (an MRTR input round) is unread (S-27)`
19164
19164
  });
@@ -19166,13 +19166,13 @@ function mrtrRounds(tree) {
19166
19166
  for (const w of scan.writes) {
19167
19167
  const v = resultTypeValue(w);
19168
19168
  if (v.kind === "unread") {
19169
- unread.push({
19169
+ unread2.push({
19170
19170
  anchor: w.anchor,
19171
19171
  reason: `\`resultType\` at ${w.anchor} is written as ${v.form}: whether it is "${MRTR_VALUE}" (an MRTR input round) is unread (S-27)`
19172
19172
  });
19173
19173
  } else if (v.value === MRTR_VALUE) rounds.push(w.anchor);
19174
19174
  }
19175
- return { rounds, unread };
19175
+ return { rounds, unread: unread2 };
19176
19176
  }
19177
19177
  function controlTree3(text) {
19178
19178
  const file = {
@@ -19214,7 +19214,7 @@ var s27ElicitationFloor = {
19214
19214
  const reds = [];
19215
19215
  const product = { ...tree, files: tree.files.filter((f) => isProductSource(f.rel)) };
19216
19216
  const mrtrScan = mrtrRounds(product);
19217
- const unread = mrtrScan.unread;
19217
+ const unread2 = mrtrScan.unread;
19218
19218
  mrtr = mrtrScan.rounds.length;
19219
19219
  for (const file of tree.files) {
19220
19220
  if (!isProductSource(file.rel)) continue;
@@ -19244,7 +19244,7 @@ var s27ElicitationFloor = {
19244
19244
  });
19245
19245
  }
19246
19246
  first = mrtrScan.rounds[0] ?? first;
19247
- if (elicitation + mrtr === 0 && unread.length === 0) {
19247
+ if (elicitation + mrtr === 0 && unread2.length === 0) {
19248
19248
  return absentResult(
19249
19249
  this.id,
19250
19250
  "-",
@@ -19263,11 +19263,11 @@ var s27ElicitationFloor = {
19263
19263
  `${reds.join("; ")} (S-27, positive-control OK)`
19264
19264
  );
19265
19265
  }
19266
- if (unread.length > 0) {
19266
+ if (unread2.length > 0) {
19267
19267
  return couldNotJudge(
19268
19268
  this.id,
19269
- unread[0].anchor,
19270
- `${unread.length} resultType value(s) could not be read \u2014 ${unread.map((u) => u.reason).join("; ")}. ${elicitation} elicitation site(s) and ${mrtr} MRTR round(s) read, no sensitive field requested (S-27)`
19269
+ unread2[0].anchor,
19270
+ `${unread2.length} resultType value(s) could not be read \u2014 ${unread2.map((u) => u.reason).join("; ")}. ${elicitation} elicitation site(s) and ${mrtr} MRTR round(s) read, no sensitive field requested (S-27)`
19271
19271
  );
19272
19272
  }
19273
19273
  return couldNotJudge(
@@ -19338,12 +19338,12 @@ function splitTop2(m, from, to) {
19338
19338
  if (start < to && m.slice(start, to).trim() !== "") parts.push([start, to]);
19339
19339
  return parts;
19340
19340
  }
19341
- function listTs(dir, unread, out = []) {
19341
+ function listTs(dir, unread2, out = []) {
19342
19342
  let names;
19343
19343
  try {
19344
19344
  names = readdirSync13(dir);
19345
19345
  } catch (err) {
19346
- unread.push(`${dir} could not be listed (${fsErrorCode(err)})`);
19346
+ unread2.push(`${dir} could not be listed (${fsErrorCode(err)})`);
19347
19347
  return out;
19348
19348
  }
19349
19349
  for (const n of names) {
@@ -19353,12 +19353,12 @@ function listTs(dir, unread, out = []) {
19353
19353
  try {
19354
19354
  st = statSync20(p);
19355
19355
  } catch (err) {
19356
- unread.push(`${p} could not be read (${fsErrorCode(err)})`);
19356
+ unread2.push(`${p} could not be read (${fsErrorCode(err)})`);
19357
19357
  continue;
19358
19358
  }
19359
- if (st.isDirectory()) listTs(p, unread, out);
19359
+ if (st.isDirectory()) listTs(p, unread2, out);
19360
19360
  else if (n.endsWith(".ts") && !n.endsWith(".test.ts") && !n.endsWith(".d.ts")) {
19361
- if (!st.isFile()) 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`);
19362
19362
  else out.push(p);
19363
19363
  }
19364
19364
  }
@@ -19380,14 +19380,14 @@ function discoverBackend(root) {
19380
19380
  }
19381
19381
  return void 0;
19382
19382
  }
19383
- function readDoors(backendRoot, unread) {
19383
+ function readDoors(backendRoot, unread2) {
19384
19384
  const doors = /* @__PURE__ */ new Map();
19385
- for (const path of listTs(backendRoot, unread)) {
19385
+ for (const path of listTs(backendRoot, unread2)) {
19386
19386
  let text;
19387
19387
  try {
19388
19388
  text = readFileSync14(path, "utf8");
19389
19389
  } catch (err) {
19390
- unread.push(`${path} could not be read (${fsErrorCode(err)})`);
19390
+ unread2.push(`${path} could not be read (${fsErrorCode(err)})`);
19391
19391
  continue;
19392
19392
  }
19393
19393
  const file = {
@@ -19509,9 +19509,9 @@ function scanS28(tree) {
19509
19509
  const scan = { violate: [], conform: [], cnj: [], calls: 0, backend: void 0 };
19510
19510
  const backendRoot = tree.backendRoot ?? discoverBackend(tree.root);
19511
19511
  scan.backend = backendRoot;
19512
- const unread = [];
19513
- const doors = backendRoot ? readDoors(backendRoot, unread) : void 0;
19514
- 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("; ")}` : "";
19515
19515
  const files = tree.files.map((f) => ({ f, text: rawText(f), m: masked(f) }));
19516
19516
  const actorDoors = /* @__PURE__ */ new Set();
19517
19517
  for (const { text } of files) {
@@ -22509,6 +22509,1703 @@ var s41LakeReader = {
22509
22509
  }
22510
22510
  };
22511
22511
 
22512
+ // src/detectors/s43-union-input.ts
22513
+ var ID = "S43 union-input";
22514
+ var RULE = "S-43";
22515
+ var MARKER_RE = /\/\/\s*allow-union-input:\s*(.*)$/;
22516
+ var MIN_REASON = 6;
22517
+ var FILE_SPAN = 1e9;
22518
+ var nextBase = 0;
22519
+ var fileByBase = /* @__PURE__ */ new Map();
22520
+ function locate(off) {
22521
+ const base = Math.floor(off / FILE_SPAN) * FILE_SPAN;
22522
+ const file = fileByBase.get(base);
22523
+ if (!file) return null;
22524
+ const lx = lex(file);
22525
+ return { file, line: lineOfOffset(lx.lineStarts, off - base) };
22526
+ }
22527
+ var PUNCT3 = ["===", "!==", "**=", "...", "<<=", ">>=", ">>>", "&&=", "||=", "??="];
22528
+ var PUNCT2 = [
22529
+ "=>",
22530
+ "==",
22531
+ "!=",
22532
+ "<=",
22533
+ ">=",
22534
+ "&&",
22535
+ "||",
22536
+ "??",
22537
+ "?.",
22538
+ "++",
22539
+ "--",
22540
+ "+=",
22541
+ "-=",
22542
+ "*=",
22543
+ "/=",
22544
+ "%=",
22545
+ "&=",
22546
+ "|=",
22547
+ "^=",
22548
+ "<<",
22549
+ ">>",
22550
+ "**"
22551
+ ];
22552
+ var REGEX_AFTER_WORDS = /* @__PURE__ */ new Set([
22553
+ "return",
22554
+ "typeof",
22555
+ "case",
22556
+ "do",
22557
+ "else",
22558
+ "in",
22559
+ "of",
22560
+ "new",
22561
+ "delete",
22562
+ "void",
22563
+ "throw",
22564
+ "instanceof",
22565
+ "yield",
22566
+ "await"
22567
+ ]);
22568
+ var lexCache = /* @__PURE__ */ new WeakMap();
22569
+ function lex(file) {
22570
+ const cached = lexCache.get(file);
22571
+ if (cached) return cached;
22572
+ const text = file.lines.map((l) => l.raw).join("\n");
22573
+ const lineStarts = [0];
22574
+ for (let i2 = 0; i2 < text.length; i2++) if (text[i2] === "\n") lineStarts.push(i2 + 1);
22575
+ const lineAt4 = (off) => lineOfOffset(lineStarts, off);
22576
+ const toks = [];
22577
+ const comments = /* @__PURE__ */ new Map();
22578
+ const addComment = (from, to) => {
22579
+ let a = from;
22580
+ while (a < to) {
22581
+ const nl = text.indexOf("\n", a);
22582
+ const end = nl < 0 || nl > to ? to : nl;
22583
+ const ln = lineAt4(a);
22584
+ comments.set(ln, (comments.get(ln) ?? "") + text.slice(a, end));
22585
+ a = end + 1;
22586
+ }
22587
+ };
22588
+ const regexAllowed = () => {
22589
+ const prev = toks[toks.length - 1];
22590
+ if (!prev) return true;
22591
+ if (prev.t === "id") return REGEX_AFTER_WORDS.has(prev.v);
22592
+ if (prev.t !== "p") return false;
22593
+ return !(prev.v === ")" || prev.v === "]" || prev.v === "}");
22594
+ };
22595
+ let i = 0;
22596
+ while (i < text.length) {
22597
+ const c = text[i];
22598
+ if (c === " " || c === " " || c === "\n" || c === "\r") {
22599
+ i++;
22600
+ continue;
22601
+ }
22602
+ if (c === "/" && text[i + 1] === "/") {
22603
+ const nl = text.indexOf("\n", i);
22604
+ const end = nl < 0 ? text.length : nl;
22605
+ addComment(i, end);
22606
+ i = end;
22607
+ continue;
22608
+ }
22609
+ if (c === "/" && text[i + 1] === "*") {
22610
+ const e = text.indexOf("*/", i + 2);
22611
+ const end = e < 0 ? text.length : e + 2;
22612
+ addComment(i, end);
22613
+ i = end;
22614
+ continue;
22615
+ }
22616
+ if (c === '"' || c === "'") {
22617
+ let j = i + 1;
22618
+ let v = "";
22619
+ while (j < text.length && text[j] !== c && text[j] !== "\n") {
22620
+ if (text[j] === "\\") {
22621
+ v += text[j + 1] ?? "";
22622
+ j += 2;
22623
+ continue;
22624
+ }
22625
+ v += text[j];
22626
+ j++;
22627
+ }
22628
+ toks.push({ t: "str", v, s: i });
22629
+ i = j + 1;
22630
+ continue;
22631
+ }
22632
+ if (c === "`") {
22633
+ let j = i + 1;
22634
+ let v = "";
22635
+ let interp = false;
22636
+ while (j < text.length && text[j] !== "`") {
22637
+ if (text[j] === "\\") {
22638
+ v += text[j + 1] ?? "";
22639
+ j += 2;
22640
+ continue;
22641
+ }
22642
+ if (text[j] === "$" && text[j + 1] === "{") {
22643
+ interp = true;
22644
+ let depth = 1;
22645
+ j += 2;
22646
+ while (j < text.length && depth > 0) {
22647
+ if (text[j] === "{") depth++;
22648
+ else if (text[j] === "}") depth--;
22649
+ else if (text[j] === "`") {
22650
+ j++;
22651
+ while (j < text.length && text[j] !== "`") j += text[j] === "\\" ? 2 : 1;
22652
+ }
22653
+ j++;
22654
+ }
22655
+ continue;
22656
+ }
22657
+ v += text[j];
22658
+ j++;
22659
+ }
22660
+ toks.push(interp ? { t: "tpl", v: "", s: i } : { t: "str", v, s: i });
22661
+ i = j + 1;
22662
+ continue;
22663
+ }
22664
+ if (c === "/" && regexAllowed()) {
22665
+ let j = i + 1;
22666
+ let inClass = false;
22667
+ while (j < text.length && text[j] !== "\n") {
22668
+ if (text[j] === "\\") {
22669
+ j += 2;
22670
+ continue;
22671
+ }
22672
+ if (text[j] === "[") inClass = true;
22673
+ else if (text[j] === "]") inClass = false;
22674
+ else if (text[j] === "/" && !inClass) break;
22675
+ j++;
22676
+ }
22677
+ j++;
22678
+ while (j < text.length && /[a-z]/i.test(text[j])) j++;
22679
+ toks.push({ t: "re", v: text.slice(i, j), s: i });
22680
+ i = j;
22681
+ continue;
22682
+ }
22683
+ if (/[A-Za-z_$]/.test(c)) {
22684
+ let j = i + 1;
22685
+ while (j < text.length && /[\w$]/.test(text[j])) j++;
22686
+ toks.push({ t: "id", v: text.slice(i, j), s: i });
22687
+ i = j;
22688
+ continue;
22689
+ }
22690
+ if (/[0-9]/.test(c) || c === "." && /[0-9]/.test(text[i + 1] ?? "")) {
22691
+ let j = i + 1;
22692
+ while (j < text.length && /[\w.]/.test(text[j])) j++;
22693
+ toks.push({ t: "num", v: text.slice(i, j), s: i });
22694
+ i = j;
22695
+ continue;
22696
+ }
22697
+ const three = text.slice(i, i + 3);
22698
+ const two = text.slice(i, i + 2);
22699
+ const p = PUNCT3.includes(three) ? three : PUNCT2.includes(two) ? two : c;
22700
+ toks.push({ t: "p", v: p, s: i });
22701
+ i += p.length;
22702
+ }
22703
+ nextBase += FILE_SPAN;
22704
+ const base = nextBase;
22705
+ for (const t of toks) t.s += base;
22706
+ fileByBase.set(base, file);
22707
+ const out = { text, toks, comments, lineStarts, base };
22708
+ lexCache.set(file, out);
22709
+ return out;
22710
+ }
22711
+ function lineOfOffset(lineStarts, off) {
22712
+ let lo = 0;
22713
+ let hi = lineStarts.length - 1;
22714
+ while (lo < hi) {
22715
+ const mid = lo + hi + 1 >> 1;
22716
+ if (lineStarts[mid] <= off) lo = mid;
22717
+ else hi = mid - 1;
22718
+ }
22719
+ return lo + 1;
22720
+ }
22721
+ var OPEN2 = { "(": ")", "[": "]", "{": "}" };
22722
+ var STOP = /* @__PURE__ */ new Set([",", ")", "]", "}", ";"]);
22723
+ var Parser = class _Parser {
22724
+ constructor(lx, i) {
22725
+ this.lx = lx;
22726
+ this.i = i;
22727
+ }
22728
+ lx;
22729
+ i;
22730
+ get toks() {
22731
+ return this.lx.toks;
22732
+ }
22733
+ peek(o = 0) {
22734
+ return this.toks[this.i + o];
22735
+ }
22736
+ isP(v, o = 0) {
22737
+ const t = this.peek(o);
22738
+ return t !== void 0 && t.t === "p" && t.v === v;
22739
+ }
22740
+ /** Index just past the bracket group opening at `i`. */
22741
+ skipGroup(i) {
22742
+ const open = this.toks[i];
22743
+ if (!open || open.t !== "p" || !OPEN2[open.v]) return i + 1;
22744
+ let depth = 0;
22745
+ for (let j = i; j < this.toks.length; j++) {
22746
+ const t = this.toks[j];
22747
+ if (t.t !== "p") continue;
22748
+ if (OPEN2[t.v]) depth++;
22749
+ else if (t.v === ")" || t.v === "]" || t.v === "}") {
22750
+ depth--;
22751
+ if (depth === 0) return j + 1;
22752
+ }
22753
+ }
22754
+ return this.toks.length;
22755
+ }
22756
+ /** Skip to the next top-level stop token (exclusive); returns whether every token was a string or `+`. */
22757
+ skipToStop() {
22758
+ let onlyStr = true;
22759
+ while (this.i < this.toks.length) {
22760
+ const t = this.toks[this.i];
22761
+ if (t.t === "p" && STOP.has(t.v)) break;
22762
+ if (t.t === "p" && OPEN2[t.v]) {
22763
+ onlyStr = false;
22764
+ this.i = this.skipGroup(this.i);
22765
+ continue;
22766
+ }
22767
+ if (!(t.t === "str" || t.t === "p" && t.v === "+")) onlyStr = false;
22768
+ this.i++;
22769
+ }
22770
+ return onlyStr;
22771
+ }
22772
+ /** Skip a type annotation (`as T`, `satisfies T`, `: T`): angle brackets nest. */
22773
+ skipType() {
22774
+ let angle = 0;
22775
+ while (this.i < this.toks.length) {
22776
+ const t = this.toks[this.i];
22777
+ if (t.t === "p") {
22778
+ if (t.v === "<") angle++;
22779
+ else if (t.v === ">" && angle > 0) angle--;
22780
+ else if (t.v === ">>" && angle > 0) angle = Math.max(0, angle - 2);
22781
+ else if (angle === 0 && (STOP.has(t.v) || t.v === "=" || t.v === "=>")) return;
22782
+ else if (OPEN2[t.v]) {
22783
+ this.i = this.skipGroup(this.i);
22784
+ continue;
22785
+ }
22786
+ }
22787
+ this.i++;
22788
+ }
22789
+ }
22790
+ /** Skip a type-parameter list `<T extends X<Y>, U = Z>` starting at the current `<`. */
22791
+ skipTypeParams() {
22792
+ let angle = 0;
22793
+ while (this.i < this.toks.length) {
22794
+ const t = this.toks[this.i];
22795
+ this.i++;
22796
+ if (t.t !== "p") continue;
22797
+ if (t.v === "<") angle++;
22798
+ else if (t.v === ">") angle--;
22799
+ else if (t.v === ">>") angle -= 2;
22800
+ if (angle <= 0) return;
22801
+ }
22802
+ }
22803
+ parseExpr() {
22804
+ const start = this.i;
22805
+ const s = this.peek()?.s ?? 0;
22806
+ const fn = this.tryArrow();
22807
+ if (fn) return fn;
22808
+ const node = this.parsePostfix();
22809
+ for (; ; ) {
22810
+ const t = this.peek();
22811
+ if (!t) return node;
22812
+ if (t.t === "id" && (t.v === "as" || t.v === "satisfies")) {
22813
+ this.i++;
22814
+ this.skipType();
22815
+ continue;
22816
+ }
22817
+ if (t.t === "p" && t.v === "!" && !this.isP("=", 1)) {
22818
+ this.i++;
22819
+ continue;
22820
+ }
22821
+ if (t.t === "p" && STOP.has(t.v)) return node;
22822
+ if (t.t === "p" && t.v === ":") return node;
22823
+ this.i = start;
22824
+ const onlyStr = this.skipToStop();
22825
+ return { k: "other", form: this.sliceText(start), strConcat: onlyStr, s };
22826
+ }
22827
+ }
22828
+ sliceText(fromTok) {
22829
+ const a = this.toks[fromTok]?.s ?? 0;
22830
+ const lastTok = this.toks[this.i - 1];
22831
+ const b = lastTok ? lastTok.s + Math.max(lastTok.v.length, 1) : a;
22832
+ const raw = this.lx.text.slice(a - this.lx.base, b - this.lx.base).replace(/\s+/g, " ").trim();
22833
+ return raw.length > 60 ? `${raw.slice(0, 57)}...` : raw;
22834
+ }
22835
+ tryArrow() {
22836
+ const start = this.i;
22837
+ const s = this.peek()?.s ?? 0;
22838
+ if (this.peek()?.t === "id" && this.peek()?.v === "async") this.i++;
22839
+ let params = null;
22840
+ if (this.isP("<")) this.skipTypeParams();
22841
+ const t = this.peek();
22842
+ if (t?.t === "id" && this.isP("=>", 1)) {
22843
+ params = [t.v];
22844
+ this.i += 1;
22845
+ } else if (t?.t === "p" && t.v === "(") {
22846
+ const end = this.skipGroup(this.i);
22847
+ let j = end;
22848
+ if (this.toks[j]?.t === "p" && this.toks[j]?.v === ":") {
22849
+ const save = this.i;
22850
+ this.i = j + 1;
22851
+ this.skipType();
22852
+ j = this.i;
22853
+ this.i = save;
22854
+ }
22855
+ if (this.toks[j]?.t === "p" && this.toks[j]?.v === "=>") {
22856
+ params = this.paramNames(this.i + 1, end - 1);
22857
+ this.i = j;
22858
+ }
22859
+ } else if (t?.t === "id" && t.v === "function") {
22860
+ this.i++;
22861
+ if (this.peek()?.t === "id") this.i++;
22862
+ if (this.isP("<")) this.skipTypeParams();
22863
+ if (!this.isP("(")) {
22864
+ this.i = start;
22865
+ return null;
22866
+ }
22867
+ const end = this.skipGroup(this.i);
22868
+ const ps = this.paramNames(this.i + 1, end - 1);
22869
+ this.i = end;
22870
+ if (this.isP(":")) {
22871
+ this.i++;
22872
+ this.skipType();
22873
+ }
22874
+ return { k: "fn", params: ps, body: this.isP("{") ? this.blockReturn() : null, s };
22875
+ }
22876
+ if (params === null) {
22877
+ this.i = start;
22878
+ return null;
22879
+ }
22880
+ this.i++;
22881
+ if (this.isP("{")) return { k: "fn", params, body: this.blockReturn(), s };
22882
+ return { k: "fn", params, body: this.parseExpr(), s };
22883
+ }
22884
+ /** The expression of the single top-level `return` of a block at `{`, or null; consumes the block. */
22885
+ blockReturn() {
22886
+ const open = this.i;
22887
+ const end = this.skipGroup(open);
22888
+ const returns = [];
22889
+ let depth = 0;
22890
+ for (let j = open; j < end; j++) {
22891
+ const t = this.toks[j];
22892
+ if (t.t === "p" && OPEN2[t.v]) depth++;
22893
+ else if (t.t === "p" && (t.v === ")" || t.v === "]" || t.v === "}")) depth--;
22894
+ else if (t.t === "id" && t.v === "return" && depth === 1) returns.push(j);
22895
+ }
22896
+ this.i = end;
22897
+ if (returns.length !== 1) return null;
22898
+ const sub = new _Parser(this.lx, returns[0] + 1);
22899
+ return sub.parseExpr();
22900
+ }
22901
+ paramNames(from, to) {
22902
+ const names = [];
22903
+ let depth = 0;
22904
+ let expectName = true;
22905
+ for (let j = from; j < to; j++) {
22906
+ const t = this.toks[j];
22907
+ if (t.t === "p" && OPEN2[t.v]) depth++;
22908
+ else if (t.t === "p" && (t.v === ")" || t.v === "]" || t.v === "}")) depth--;
22909
+ if (depth === 0 && t.t === "p" && t.v === ",") {
22910
+ expectName = true;
22911
+ continue;
22912
+ }
22913
+ if (depth === 0 && expectName && t.t === "id") {
22914
+ names.push(t.v);
22915
+ expectName = false;
22916
+ }
22917
+ }
22918
+ return names;
22919
+ }
22920
+ parsePostfix() {
22921
+ let node = this.parsePrimary();
22922
+ for (; ; ) {
22923
+ if (this.isP(".") || this.isP("?.")) {
22924
+ const nt = this.peek(1);
22925
+ if (nt?.t === "id") {
22926
+ this.i += 2;
22927
+ node = { k: "member", obj: node, prop: nt.v, s: node.s };
22928
+ continue;
22929
+ }
22930
+ if (this.isP("?.") && (this.isP("(", 1) || this.isP("[", 1))) {
22931
+ this.i++;
22932
+ continue;
22933
+ }
22934
+ return node;
22935
+ }
22936
+ if (this.isP("(")) {
22937
+ node = { k: "call", callee: node, args: this.parseList(")"), s: node.s };
22938
+ continue;
22939
+ }
22940
+ if (this.isP("[")) {
22941
+ const end = this.skipGroup(this.i);
22942
+ this.i = end;
22943
+ node = { k: "member", obj: node, prop: "[computed]", s: node.s };
22944
+ continue;
22945
+ }
22946
+ if (this.isP("<") && node.k === "member") {
22947
+ const save = this.i;
22948
+ this.i++;
22949
+ this.skipType();
22950
+ if (this.isP(">")) {
22951
+ this.i++;
22952
+ if (this.isP("(")) continue;
22953
+ }
22954
+ this.i = save;
22955
+ return node;
22956
+ }
22957
+ return node;
22958
+ }
22959
+ }
22960
+ /** Comma-separated expressions inside the group opening at the current token. */
22961
+ parseList(close) {
22962
+ const end = this.skipGroup(this.i);
22963
+ this.i++;
22964
+ const out = [];
22965
+ while (this.i < end - 1) {
22966
+ if (this.isP(",")) {
22967
+ this.i++;
22968
+ continue;
22969
+ }
22970
+ if (this.isP(close)) break;
22971
+ if (this.isP("...")) {
22972
+ const s = this.peek()?.s ?? 0;
22973
+ this.i++;
22974
+ const inner = this.parseExpr();
22975
+ out.push({ k: "other", form: `...${describeNode(inner)}`, strConcat: false, s });
22976
+ } else {
22977
+ const before = this.i;
22978
+ out.push(this.parseExpr());
22979
+ if (this.i === before) this.i++;
22980
+ }
22981
+ while (this.i < end - 1 && !this.isP(",")) this.i++;
22982
+ }
22983
+ this.i = end;
22984
+ return out;
22985
+ }
22986
+ parsePrimary() {
22987
+ const t = this.peek();
22988
+ if (!t) return { k: "other", form: "end of file", strConcat: false, s: 0 };
22989
+ const s = t.s;
22990
+ if (t.t === "str") {
22991
+ this.i++;
22992
+ return { k: "lit", v: t.v, s };
22993
+ }
22994
+ if (t.t === "num") {
22995
+ this.i++;
22996
+ return { k: "lit", v: Number(t.v), s };
22997
+ }
22998
+ if (t.t === "tpl") {
22999
+ this.i++;
23000
+ return { k: "other", form: "template literal with interpolation", strConcat: false, s };
23001
+ }
23002
+ if (t.t === "re") {
23003
+ this.i++;
23004
+ return { k: "other", form: "regular expression", strConcat: false, s };
23005
+ }
23006
+ if (t.t === "id") {
23007
+ this.i++;
23008
+ if (t.v === "true" || t.v === "false") return { k: "lit", v: t.v === "true", s };
23009
+ if (t.v === "null" || t.v === "undefined") return { k: "lit", v: null, s };
23010
+ if (t.v === "new") {
23011
+ this.parsePostfix();
23012
+ return { k: "other", form: "new expression", strConcat: false, s };
23013
+ }
23014
+ return { k: "id", name: t.v, s };
23015
+ }
23016
+ if (t.v === "(") {
23017
+ const end = this.skipGroup(this.i);
23018
+ this.i++;
23019
+ const inner = this.parseExpr();
23020
+ this.i = end;
23021
+ return inner;
23022
+ }
23023
+ if (t.v === "[") {
23024
+ return { k: "arr", items: this.parseList("]"), s };
23025
+ }
23026
+ if (t.v === "{") return this.parseObject();
23027
+ if (t.v === "-" && this.peek(1)?.t === "num") {
23028
+ this.i += 2;
23029
+ return { k: "lit", v: -Number(this.toks[this.i - 1].v), s };
23030
+ }
23031
+ this.i++;
23032
+ return { k: "other", form: `token ${t.v}`, strConcat: false, s };
23033
+ }
23034
+ parseObject() {
23035
+ const s = this.peek()?.s ?? 0;
23036
+ const end = this.skipGroup(this.i);
23037
+ this.i++;
23038
+ const entries = [];
23039
+ while (this.i < end - 1) {
23040
+ const t = this.peek();
23041
+ if (!t) break;
23042
+ if (t.t === "p" && t.v === ",") {
23043
+ this.i++;
23044
+ continue;
23045
+ }
23046
+ if (t.t === "p" && t.v === "...") {
23047
+ this.i++;
23048
+ entries.push({ kind: "spread", value: this.parseExpr(), s: t.s });
23049
+ } else if (t.t === "p" && t.v === "[") {
23050
+ this.i = this.skipGroup(this.i);
23051
+ entries.push({ kind: "unread", form: "computed key", s: t.s });
23052
+ if (this.isP(":")) {
23053
+ this.i++;
23054
+ this.parseExpr();
23055
+ }
23056
+ } else if (t.t === "id" || t.t === "str" || t.t === "num") {
23057
+ let key = t.v;
23058
+ let at = this.i;
23059
+ if (t.t === "id" && (t.v === "get" || t.v === "set" || t.v === "async") && (this.peek(1)?.t === "id" || this.peek(1)?.t === "str")) {
23060
+ at = this.i + 1;
23061
+ key = this.toks[at].v;
23062
+ }
23063
+ this.i = at + 1;
23064
+ if (this.isP("?")) this.i++;
23065
+ if (this.isP(":")) {
23066
+ this.i++;
23067
+ entries.push({ kind: "prop", key, value: this.parseExpr(), s: t.s });
23068
+ } else if (this.isP("(")) {
23069
+ this.i = this.skipGroup(this.i);
23070
+ if (this.isP(":")) {
23071
+ this.i++;
23072
+ this.skipType();
23073
+ }
23074
+ if (this.isP("{")) this.i = this.skipGroup(this.i);
23075
+ entries.push({
23076
+ kind: "prop",
23077
+ key,
23078
+ value: { k: "fn", params: [], body: null, s: t.s },
23079
+ s: t.s
23080
+ });
23081
+ } else {
23082
+ entries.push({ kind: "prop", key, value: { k: "id", name: key, s: t.s }, s: t.s });
23083
+ }
23084
+ } else {
23085
+ this.i++;
23086
+ }
23087
+ while (this.i < end - 1 && !this.isP(",")) this.i++;
23088
+ }
23089
+ this.i = end;
23090
+ return { k: "obj", entries, s };
23091
+ }
23092
+ };
23093
+ function describeNode(n) {
23094
+ switch (n.k) {
23095
+ case "id":
23096
+ return n.name;
23097
+ case "lit":
23098
+ return JSON.stringify(n.v);
23099
+ case "member":
23100
+ return `${describeNode(n.obj)}.${n.prop}`;
23101
+ case "call":
23102
+ return `${describeNode(n.callee)}(...)`;
23103
+ case "obj":
23104
+ return "{...}";
23105
+ case "arr":
23106
+ return "[...]";
23107
+ case "fn":
23108
+ return "function";
23109
+ case "other":
23110
+ return n.form;
23111
+ }
23112
+ }
23113
+ var bindingCache = /* @__PURE__ */ new WeakMap();
23114
+ function bracePairs(toks, open) {
23115
+ const pairs = [];
23116
+ let j = open + 1;
23117
+ while (j < toks.length && toks[j].v !== "}") {
23118
+ const tk = toks[j];
23119
+ if (tk.t === "id" && tk.v === "type" && toks[j + 1]?.t === "id" && toks[j + 1].v !== "as") {
23120
+ j++;
23121
+ continue;
23122
+ }
23123
+ if (tk.t === "id" || tk.t === "str") {
23124
+ if (toks[j + 1]?.v === "as" && toks[j + 2]) {
23125
+ pairs.push([tk.v, toks[j + 2].v]);
23126
+ j += 3;
23127
+ continue;
23128
+ }
23129
+ pairs.push([tk.v, tk.v]);
23130
+ }
23131
+ j++;
23132
+ }
23133
+ return { pairs, end: j };
23134
+ }
23135
+ function bindingsOf(file) {
23136
+ const cached = bindingCache.get(file);
23137
+ if (cached) return cached;
23138
+ const lx = lex(file);
23139
+ const toks = lx.toks;
23140
+ const decls = /* @__PURE__ */ new Map();
23141
+ const imports = /* @__PURE__ */ new Map();
23142
+ const reexports = [];
23143
+ const zod = /* @__PURE__ */ new Set();
23144
+ const add = (name, node) => decls.set(name, [...decls.get(name) ?? [], node]);
23145
+ const fromAfter = (j) => toks[j]?.t === "id" && toks[j].v === "from" && toks[j + 1]?.t === "str" ? toks[j + 1].v : null;
23146
+ for (let i = 0; i < toks.length; i++) {
23147
+ const t = toks[i];
23148
+ if (t.t !== "id") continue;
23149
+ const memberAccess = i > 0 && (toks[i - 1].v === "." || toks[i - 1].v === "?.");
23150
+ if (t.v === "import" && !memberAccess && toks[i + 1]?.v !== "(") {
23151
+ let j = i + 1;
23152
+ if (toks[j]?.v === "type") j++;
23153
+ const local = [];
23154
+ if (toks[j]?.t === "id" && toks[j].v !== "from") {
23155
+ local.push(["default", toks[j].v]);
23156
+ j++;
23157
+ if (toks[j]?.v === ",") j++;
23158
+ }
23159
+ if (toks[j]?.v === "{") {
23160
+ const bp = bracePairs(toks, j);
23161
+ local.push(...bp.pairs);
23162
+ j = bp.end + 1;
23163
+ } else if (toks[j]?.v === "*" && toks[j + 1]?.v === "as" && toks[j + 2]?.t === "id") {
23164
+ local.push(["*", toks[j + 2].v]);
23165
+ j += 3;
23166
+ }
23167
+ const mod = fromAfter(j);
23168
+ if (mod !== null) {
23169
+ for (const [orig, name] of local) {
23170
+ imports.set(name, { mod, orig });
23171
+ if (/^zod(\/|$)/.test(mod)) zod.add(name);
23172
+ }
23173
+ }
23174
+ continue;
23175
+ }
23176
+ if (t.v === "export" && !memberAccess) {
23177
+ let j = i + 1;
23178
+ if (toks[j]?.v === "type") j++;
23179
+ if (toks[j]?.v === "{") {
23180
+ const bp = bracePairs(toks, j);
23181
+ const mod = fromAfter(bp.end + 1);
23182
+ if (mod !== null)
23183
+ for (const [orig, exported] of bp.pairs) reexports.push({ mod, exported, orig });
23184
+ } else if (toks[j]?.v === "*" && toks[j + 1]?.v !== "as") {
23185
+ const mod = fromAfter(j + 1);
23186
+ if (mod !== null) reexports.push({ mod, exported: null, orig: null });
23187
+ }
23188
+ continue;
23189
+ }
23190
+ if ((t.v === "const" || t.v === "let" || t.v === "var") && toks[i + 1]?.t === "id") {
23191
+ const name = toks[i + 1].v;
23192
+ const p = new Parser(lx, i + 2);
23193
+ if (p.isP(":")) {
23194
+ p.i++;
23195
+ p.skipType();
23196
+ }
23197
+ if (p.isP("=")) {
23198
+ p.i++;
23199
+ add(name, p.parseExpr());
23200
+ }
23201
+ continue;
23202
+ }
23203
+ if (t.v === "function" && toks[i + 1]?.t === "id" && !memberAccess) {
23204
+ const name = toks[i + 1].v;
23205
+ const p = new Parser(lx, i);
23206
+ add(name, p.parseExpr());
23207
+ }
23208
+ }
23209
+ const out = { decls, imports, reexports, zod };
23210
+ bindingCache.set(file, out);
23211
+ return out;
23212
+ }
23213
+ var unread = (form, at) => ({
23214
+ k: "unread",
23215
+ form,
23216
+ at
23217
+ });
23218
+ var SCALAR = { k: "scalar", name: "scalar" };
23219
+ var SCALAR_FACTORIES = /* @__PURE__ */ new Set([
23220
+ "string",
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
+
22512
24209
  // src/detectors/index.ts
22513
24210
  var registered = [
22514
24211
  d2,
@@ -22614,6 +24311,7 @@ var registered = [
22614
24311
  s39UpstreamError,
22615
24312
  s40UpstreamRowsNarrowed,
22616
24313
  s41LakeReader,
24314
+ s43UnionInput,
22617
24315
  e5ExtensionIsolation,
22618
24316
  a3SandboxRespected,
22619
24317
  a4WcagGate,
@@ -22647,6 +24345,7 @@ var READS_CODE = /* @__PURE__ */ new Set([
22647
24345
  "S-39",
22648
24346
  "S-40",
22649
24347
  "S-41",
24348
+ "S-43",
22650
24349
  "E-5",
22651
24350
  "A-3"
22652
24351
  ]);
@@ -23017,7 +24716,7 @@ const onMessage = (msg) => {
23017
24716
  const props = schemaOf(t).properties;
23018
24717
  return Boolean(props && typeof props === "object" && Object.prototype.hasOwnProperty.call(props, "cursor"));
23019
24718
  };
23020
- 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 }));
23021
24720
  const methods = ["tools/list"];
23022
24721
  if (capabilities.resources) methods.push("resources/list", "resources/templates/list");
23023
24722
  if (capabilities.prompts) methods.push("prompts/list");
@@ -23083,17 +24782,17 @@ const onMessage = (msg) => {
23083
24782
  transport = plan.kind === "http" ? makeHttpTransport() : makeStdioTransport();
23084
24783
  send({ jsonrpc: "2.0", id: 1, method: "initialize", params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "mcp-doctor", version: "0" } } });
23085
24784
  `;
23086
- var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
24785
+ var isObj2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
23087
24786
  var outcomeOf = (v) => v === "answered" || v === "refused" ? v : "no-answer";
23088
24787
  function readServed(raw) {
23089
- if (!isObj(raw)) return void 0;
24788
+ if (!isObj2(raw)) return void 0;
23090
24789
  const readList = (l) => {
23091
- const r = isObj(l) ? l : {};
24790
+ const r = isObj2(l) ? l : {};
23092
24791
  const method = typeof r.method === "string" ? r.method : "<unnamed list>";
23093
- const fu = isObj(r.followUp) ? r.followUp : void 0;
24792
+ const fu = isObj2(r.followUp) ? r.followUp : void 0;
23094
24793
  return {
23095
24794
  method,
23096
- outcome: isObj(l) ? outcomeOf(r.outcome) : "no-answer",
24795
+ outcome: isObj2(l) ? outcomeOf(r.outcome) : "no-answer",
23097
24796
  ...typeof r.detail === "string" ? { detail: r.detail } : {},
23098
24797
  ...Array.isArray(r.resultKeys) ? { resultKeys: r.resultKeys.map(String) } : {},
23099
24798
  ...r.resultType !== void 0 ? { resultType: r.resultType } : {},
@@ -23112,26 +24811,26 @@ function readServed(raw) {
23112
24811
  };
23113
24812
  const lists = (Array.isArray(raw.lists) ? raw.lists : []).map(readList);
23114
24813
  const vp = raw.versionProbe;
23115
- 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" ? {
23116
24815
  kind: "statuses",
23117
24816
  supportedVersion: vp.supportedVersion,
23118
24817
  supported: vp.supported,
23119
24818
  unsupported: vp.unsupported
23120
24819
  } : {
23121
24820
  kind: "not-run",
23122
- 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"
23123
24822
  };
23124
24823
  const as = raw.authServer;
23125
- 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" ? {
23126
24825
  kind: "unavailable",
23127
24826
  url: as.url,
23128
24827
  reason: typeof as.reason === "string" ? as.reason : "no reason given"
23129
24828
  } : {
23130
24829
  kind: "not-run",
23131
- 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"
23132
24831
  };
23133
24832
  return {
23134
- capabilities: isObj(raw.capabilities) ? raw.capabilities : {},
24833
+ capabilities: isObj2(raw.capabilities) ? raw.capabilities : {},
23135
24834
  ...typeof raw.protocolVersion === "string" ? { protocolVersion: raw.protocolVersion } : {},
23136
24835
  lists,
23137
24836
  calls: (Array.isArray(raw.calls) ? raw.calls : []).map(readList),
@@ -23322,7 +25021,8 @@ function introspect(plan, root, evalSource, expectedCommit, evalsNote, secrets)
23322
25021
  const count = evals.counts.get(name);
23323
25022
  const base = t.description ? { name, description: t.description } : { name };
23324
25023
  const withCursor = t.cursorArgument === true ? { ...base, cursorArgument: true } : base;
23325
- 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 };
23326
25026
  });
23327
25027
  return {
23328
25028
  root,