@vantageos/mcp-doctor 0.15.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/doctor.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/doctor.ts
4
- import { readFileSync as readFileSync17, realpathSync } from "fs";
5
- import { dirname as dirname18, join as join29, resolve as resolve4 } from "path";
4
+ import { readFileSync as readFileSync19, realpathSync } from "fs";
5
+ import { dirname as dirname18, join as join30, resolve as resolve4 } from "path";
6
6
  import { fileURLToPath as fileURLToPath2 } from "url";
7
7
 
8
8
  // src/scan.ts
@@ -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 = "9fdad5b80bebef09d790e1ca9a4419f7ea2db7d1";
770
+ var STANDARD_PIN = "6870b7754393a2fb45d4cb536309f20ba91b67c1";
771
771
 
772
772
  // src/detectors/dLocalIdentity.ts
773
773
  var CLOUD_IDENTITY_PACKAGE = "@vantageos/cloud-identity";
@@ -3937,9 +3937,9 @@ function stringValueAt(file, line, col) {
3937
3937
  return { kind: "string", value: m[2] };
3938
3938
  }
3939
3939
  function identReturned(file, name) {
3940
- const esc5 = name.replace(/[$]/g, "\\$&");
3940
+ const esc7 = name.replace(/[$]/g, "\\$&");
3941
3941
  const re = new RegExp(
3942
- `(?:\\breturn|=>)\\s*(?:\\(\\s*)*${esc5}(?![\\w$])(?!\\s*(?:\\?\\.|\\.|\\(|\\[|=))`
3942
+ `(?:\\breturn|=>)\\s*(?:\\(\\s*)*${esc7}(?![\\w$])(?!\\s*(?:\\?\\.|\\.|\\(|\\[|=))`
3943
3943
  );
3944
3944
  return re.test(uncommentedLines(file).join("\n"));
3945
3945
  }
@@ -10163,8 +10163,8 @@ var RECORD_LINE_RE = /^[\s>*_\-+]*Provenance\s*:\s*(.*)$/i;
10163
10163
  var SHASUM_HEX_RE = /\bshasum\b[^\n]*?\b([0-9a-f]{40})\b/i;
10164
10164
  function judgeProvenanceRecord(line, name, version) {
10165
10165
  const body = line.match(RECORD_LINE_RE)?.[1] ?? "";
10166
- const esc5 = (x) => x.replace(/[.+*?^$()[\]{}|\\/]/g, "\\$&");
10167
- const named = new RegExp(`(?:^|[\\s(])${esc5(name)}@v?${esc5(version)}(?![\\w.-]*\\d)`);
10166
+ const esc7 = (x) => x.replace(/[.+*?^$()[\]{}|\\/]/g, "\\$&");
10167
+ const named = new RegExp(`(?:^|[\\s(])${esc7(name)}@v?${esc7(version)}(?![\\w.-]*\\d)`);
10168
10168
  if (!named.test(body)) {
10169
10169
  return { ok: false, why: `it does not name ${name}@${version}, the artifact being published` };
10170
10170
  }
@@ -13051,6 +13051,96 @@ var c33IdentityTool = {
13051
13051
  }
13052
13052
  };
13053
13053
 
13054
+ // src/detectors/c36-readme-npm-limit.ts
13055
+ import { lstatSync, readFileSync as readFileSync11, readdirSync as readdirSync9 } from "fs";
13056
+ import { join as join13 } from "path";
13057
+ var ID2 = "C36 readme-npm-limit";
13058
+ var RULE2 = "C-36";
13059
+ var LIMIT = 61440;
13060
+ var NPM_CUT = 65536;
13061
+ var README_RE = /^readme(\.[^/]*)?$/i;
13062
+ function runStatic2(tree) {
13063
+ const pkgPath = join13(tree.root, "package.json");
13064
+ let pkg;
13065
+ try {
13066
+ pkg = JSON.parse(readFileSync11(pkgPath, "utf8"));
13067
+ } catch (err) {
13068
+ if (fsErrorCode(err) === "ENOENT")
13069
+ return {
13070
+ id: ID2,
13071
+ anchor: tree.root,
13072
+ state: "absent",
13073
+ verdict: `no package.json: not published to npm \u2014 ${RULE2} n/a`
13074
+ };
13075
+ return couldNotJudge(
13076
+ ID2,
13077
+ pkgPath,
13078
+ `package.json could not be read or parsed (${fsErrorCode(err)}) (${RULE2})`
13079
+ );
13080
+ }
13081
+ if (pkg?.private === true)
13082
+ return {
13083
+ id: ID2,
13084
+ anchor: pkgPath,
13085
+ state: "absent",
13086
+ verdict: `"private": true: not published to npm \u2014 ${RULE2} n/a`
13087
+ };
13088
+ let names;
13089
+ try {
13090
+ names = readdirSync9(tree.root).filter((n) => README_RE.test(n));
13091
+ } catch (err) {
13092
+ return couldNotJudge(
13093
+ ID2,
13094
+ tree.root,
13095
+ `the package root could not be listed (${fsErrorCode(err)}) (${RULE2})`
13096
+ );
13097
+ }
13098
+ if (names.length === 0)
13099
+ return {
13100
+ id: ID2,
13101
+ anchor: tree.root,
13102
+ state: "absent",
13103
+ verdict: `no README (no readme* file) at the package root: nothing to measure (its presence is C-1 / C-31's subject) \u2014 ${RULE2} n/a`
13104
+ };
13105
+ const sized = [];
13106
+ for (const name of names.sort()) {
13107
+ const path = join13(tree.root, name);
13108
+ try {
13109
+ const st = lstatSync(path);
13110
+ if (!st.isFile())
13111
+ return couldNotJudge(
13112
+ ID2,
13113
+ path,
13114
+ `${name} is not a regular file, so its shipped size is unread (${RULE2})`
13115
+ );
13116
+ sized.push({ name, size: st.size });
13117
+ } catch (err) {
13118
+ return couldNotJudge(ID2, path, `${name} could not be read (${fsErrorCode(err)}) (${RULE2})`);
13119
+ }
13120
+ }
13121
+ const over = sized.filter((r) => r.size > LIMIT);
13122
+ const list = sized.map((r) => `${r.name} ${r.size} bytes`).join(", ");
13123
+ if (over.length > 0)
13124
+ return {
13125
+ id: ID2,
13126
+ anchor: join13(tree.root, over[0].name),
13127
+ state: "non-conforming",
13128
+ verdict: `${over.map((r) => `${r.name} is ${r.size} bytes${r.size > NPM_CUT ? ` (the last ${r.size - NPM_CUT} bytes are already missing from the package page)` : ""}`).join("; ")}, above the ${LIMIT}-byte limit (npm truncates at ${NPM_CUT}); move long sections to docs/ pages with the README as their index. Shipped: ${list} (${RULE2})`
13129
+ };
13130
+ return {
13131
+ id: ID2,
13132
+ anchor: join13(tree.root, sized[0].name),
13133
+ state: "present",
13134
+ verdict: `${list}: at or under the ${LIMIT}-byte limit (npm truncates at ${NPM_CUT}) (${RULE2})`
13135
+ };
13136
+ }
13137
+ var c36ReadmeNpmLimit = {
13138
+ id: ID2,
13139
+ rule: RULE2,
13140
+ pin: STANDARD_PIN,
13141
+ run: runStatic2
13142
+ };
13143
+
13054
13144
  // src/detectors/d2.ts
13055
13145
  var SESSION_RE = /mcp-session-id/i;
13056
13146
  var GENERATOR_RE = /\bsessionIdGenerator\s*:\s*(?!undefined\b)\S/;
@@ -13724,10 +13814,10 @@ var RESULT_PAYLOAD_KEYS = [
13724
13814
  var RESULT_ANCHOR_KEYS = ["content", "structuredContent", "resultType"];
13725
13815
  function baseIsResult(file, base, tree) {
13726
13816
  if (!base) return false;
13727
- const esc5 = base.replace(/[$]/g, "\\$&");
13817
+ const esc7 = base.replace(/[$]/g, "\\$&");
13728
13818
  const keys = RESULT_PAYLOAD_KEYS.join("|");
13729
13819
  const assigned = new RegExp(
13730
- `\\b${esc5}\\s*(?:\\.\\s*(?:${keys})|\\[\\s*["'](?:${keys})["']\\s*\\])\\s*=(?![=>])`
13820
+ `\\b${esc7}\\s*(?:\\.\\s*(?:${keys})|\\[\\s*["'](?:${keys})["']\\s*\\])\\s*=(?![=>])`
13731
13821
  );
13732
13822
  if (file.lines.some((l) => !l.comment && assigned.test(l.raw))) return true;
13733
13823
  const one = { ...tree, files: [file] };
@@ -13877,7 +13967,7 @@ var d7 = guardUnreadablePackageJson(d7Inner, { authoritative: true });
13877
13967
 
13878
13968
  // src/detectors/d8.ts
13879
13969
  import { existsSync as existsSync12, statSync as statSync12 } from "fs";
13880
- import { dirname as dirname6, join as join13, relative as relative9 } from "path";
13970
+ import { dirname as dirname6, join as join14, relative as relative9 } from "path";
13881
13971
  var POSITIVE_CONTROL2 = 'server.registerTool("list_items", { ... }, handler);';
13882
13972
  function d8PositiveControl() {
13883
13973
  return {
@@ -13897,7 +13987,7 @@ function resolveBaseDir(tree) {
13897
13987
  function findEvalsFile(tree) {
13898
13988
  let dir = resolveBaseDir(tree);
13899
13989
  for (let depth = 0; depth < 8; depth++) {
13900
- const candidate = join13(dir, "evals", "evals.json");
13990
+ const candidate = join14(dir, "evals", "evals.json");
13901
13991
  if (existsSync12(candidate)) return candidate;
13902
13992
  const parent = dirname6(dir);
13903
13993
  if (parent === dir) break;
@@ -14051,7 +14141,7 @@ var d8 = {
14051
14141
 
14052
14142
  // src/detectors/d9.ts
14053
14143
  import { existsSync as existsSync13 } from "fs";
14054
- import { dirname as dirname7, join as join14 } from "path";
14144
+ import { dirname as dirname7, join as join15 } from "path";
14055
14145
  var SEMVER_RE = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
14056
14146
  var POSITIVE_CONTROL3 = "1.2.3-beta.1+build.7";
14057
14147
  function d9PositiveControl() {
@@ -14100,7 +14190,7 @@ var d9Inner = {
14100
14190
  };
14101
14191
  }
14102
14192
  const projectDir = dirname7(pkgPath);
14103
- const changelogPath = join14(projectDir, "CHANGELOG.md");
14193
+ const changelogPath = join15(projectDir, "CHANGELOG.md");
14104
14194
  const hasChangelog = existsSync13(changelogPath);
14105
14195
  const validSemver = SEMVER_RE.test(version);
14106
14196
  if (validSemver && hasChangelog) {
@@ -14131,7 +14221,7 @@ var d9 = guardUnreadablePackageJson(d9Inner, { authoritative: false });
14131
14221
 
14132
14222
  // src/detectors/d10.ts
14133
14223
  import { existsSync as existsSync14 } from "fs";
14134
- import { dirname as dirname8, join as join15 } from "path";
14224
+ import { dirname as dirname8, join as join16 } from "path";
14135
14225
  var DESCRIPTION_FR_RE = /"description_fr"\s*:\s*"[^"]+"/;
14136
14226
  var POSITIVE_CONTROL4 = '"description_fr": "Un serveur MCP conforme.",';
14137
14227
  function d10PositiveControl() {
@@ -14264,7 +14354,7 @@ var d10Inner = {
14264
14354
  };
14265
14355
  }
14266
14356
  const hasDescriptionFr = hasDescriptionFrJson || sourceScan.present;
14267
- const readmeFrPath = join15(root, "README.fr.md");
14357
+ const readmeFrPath = join16(root, "README.fr.md");
14268
14358
  const hasReadmeFr = existsSync14(readmeFrPath);
14269
14359
  const missing = [];
14270
14360
  if (!hasDescriptionFr) missing.push("description_fr (package.json or source _meta)");
@@ -14673,8 +14763,8 @@ var d15 = {
14673
14763
  };
14674
14764
 
14675
14765
  // src/detectors/d16.ts
14676
- import { existsSync as existsSync15, readFileSync as readFileSync11, statSync as statSync13 } from "fs";
14677
- import { dirname as dirname9, join as join16 } from "path";
14766
+ import { existsSync as existsSync15, readFileSync as readFileSync12, statSync as statSync13 } from "fs";
14767
+ import { dirname as dirname9, join as join17 } from "path";
14678
14768
  var DISCOVER_RE2 = /server\/discover|DiscoverResult|ServerDiscover|handleServerDiscover/;
14679
14769
  var HEALTH_ROUTE_FRAMEWORK_RE = /\b[A-Za-z_$][\w$]*\.(?:get|post|put|patch|delete|all|route|use)\s*\(\s*["'`][^"'`]*\/health/;
14680
14770
  var HEALTH_ROUTE_RAWPATH_RE = /\bpathname\s*===?\s*["'`][^"'`]*\/health/;
@@ -14758,7 +14848,7 @@ function manifestVersionEqualsPackage(tree) {
14758
14848
  if (typeof pkgVersion !== "string" || pkgVersion.length === 0 || !tree.packageJson) return false;
14759
14849
  try {
14760
14850
  const manifest = JSON.parse(
14761
- readFileSync11(join16(dirname9(tree.packageJson.path), "mcp-server.json"), "utf8")
14851
+ readFileSync12(join17(dirname9(tree.packageJson.path), "mcp-server.json"), "utf8")
14762
14852
  );
14763
14853
  return manifest.version === pkgVersion;
14764
14854
  } catch {
@@ -15046,10 +15136,10 @@ function readPackageVersion(root) {
15046
15136
  try {
15047
15137
  let dir = statSync13(root).isDirectory() ? root : dirname9(root);
15048
15138
  for (let depth = 0; depth < 8; depth++) {
15049
- const candidate = join16(dir, "package.json");
15139
+ const candidate = join17(dir, "package.json");
15050
15140
  if (existsSync15(candidate)) {
15051
15141
  if (!statSync13(candidate).isFile()) return null;
15052
- const pkg = JSON.parse(readFileSync11(candidate, "utf8"));
15142
+ const pkg = JSON.parse(readFileSync12(candidate, "utf8"));
15053
15143
  return typeof pkg.version === "string" ? pkg.version : null;
15054
15144
  }
15055
15145
  const parent = dirname9(dir);
@@ -15063,8 +15153,8 @@ function readPackageVersion(root) {
15063
15153
  }
15064
15154
 
15065
15155
  // src/detectors/dAppI18n.ts
15066
- import { existsSync as existsSync16, readFileSync as readFileSync12, statSync as statSync14 } from "fs";
15067
- import { dirname as dirname10, join as join17 } from "path";
15156
+ import { existsSync as existsSync16, readFileSync as readFileSync13, statSync as statSync14 } from "fs";
15157
+ import { dirname as dirname10, join as join18 } from "path";
15068
15158
  function flattenKeys(obj, prefix = "") {
15069
15159
  if (obj === null || typeof obj !== "object" || Array.isArray(obj)) {
15070
15160
  return prefix ? [prefix] : [];
@@ -15098,7 +15188,7 @@ function dAppI18nPositiveControls() {
15098
15188
  function readJson2(path) {
15099
15189
  try {
15100
15190
  if (!statSync14(path).isFile()) return { ok: false };
15101
- return { ok: true, value: JSON.parse(readFileSync12(path, "utf8")) };
15191
+ return { ok: true, value: JSON.parse(readFileSync13(path, "utf8")) };
15102
15192
  } catch {
15103
15193
  return { ok: false };
15104
15194
  }
@@ -15115,9 +15205,9 @@ var dAppI18n = {
15115
15205
  );
15116
15206
  }
15117
15207
  const root = tree.packageJson ? dirname10(tree.packageJson.path) : tree.root;
15118
- const i18nDir = join17(root, "i18n");
15119
- const enPath = join17(i18nDir, "en.json");
15120
- const frPath = join17(i18nDir, "fr.json");
15208
+ const i18nDir = join18(root, "i18n");
15209
+ const enPath = join18(i18nDir, "en.json");
15210
+ const frPath = join18(i18nDir, "fr.json");
15121
15211
  const hasI18n = existsSync16(i18nDir);
15122
15212
  const hasFr = existsSync16(frPath);
15123
15213
  if (!hasI18n && !hasFr) {
@@ -15296,27 +15386,27 @@ var dDebugOptIn = {
15296
15386
  };
15297
15387
 
15298
15388
  // src/detectors/extManifests.ts
15299
- import { readdirSync as readdirSync9, statSync as statSync15 } from "fs";
15300
- import { join as join18 } from "path";
15389
+ import { readdirSync as readdirSync10, statSync as statSync15 } from "fs";
15390
+ import { join as join19 } from "path";
15301
15391
  function findExtensionManifests(tree) {
15302
15392
  const out = [];
15303
15393
  const root = tree.root;
15304
15394
  let base;
15305
15395
  try {
15306
- base = statSync15(root).isDirectory() ? root : join18(root, "..");
15396
+ base = statSync15(root).isDirectory() ? root : join19(root, "..");
15307
15397
  } catch {
15308
15398
  return out;
15309
15399
  }
15310
15400
  const walk3 = (dir) => {
15311
15401
  let entries;
15312
15402
  try {
15313
- entries = readdirSync9(dir);
15403
+ entries = readdirSync10(dir);
15314
15404
  } catch (err) {
15315
15405
  recordSkip(tree, dir, base, `could not be listed (${fsErrorCode(err)}) \u2014 not read`);
15316
15406
  return;
15317
15407
  }
15318
15408
  for (const name of entries) {
15319
- const full = join18(dir, name);
15409
+ const full = join19(dir, name);
15320
15410
  let st;
15321
15411
  try {
15322
15412
  st = statSync15(full);
@@ -15344,8 +15434,8 @@ function findExtensionManifests(tree) {
15344
15434
  }
15345
15435
 
15346
15436
  // src/detectors/vendorRegistry.ts
15347
- import { existsSync as existsSync17, readFileSync as readFileSync13 } from "fs";
15348
- import { dirname as dirname11, join as join19 } from "path";
15437
+ import { existsSync as existsSync17, readFileSync as readFileSync14 } from "fs";
15438
+ import { dirname as dirname11, join as join20 } from "path";
15349
15439
  import { fileURLToPath } from "url";
15350
15440
  function locateRegistry() {
15351
15441
  let dir;
@@ -15355,7 +15445,7 @@ function locateRegistry() {
15355
15445
  return null;
15356
15446
  }
15357
15447
  for (let depth = 0; depth < 5; depth++) {
15358
- const candidate = join19(dir, "vendor-namespaces.json");
15448
+ const candidate = join20(dir, "vendor-namespaces.json");
15359
15449
  if (existsSync17(candidate)) return candidate;
15360
15450
  const parent = dirname11(dir);
15361
15451
  if (parent === dir) break;
@@ -15373,7 +15463,7 @@ function loadRegistry(path) {
15373
15463
  }
15374
15464
  let parsed;
15375
15465
  try {
15376
- parsed = JSON.parse(readFileSync13(p, "utf8"));
15466
+ parsed = JSON.parse(readFileSync14(p, "utf8"));
15377
15467
  } catch (err) {
15378
15468
  return {
15379
15469
  ok: false,
@@ -15951,8 +16041,8 @@ var dExt3 = {
15951
16041
  };
15952
16042
 
15953
16043
  // src/detectors/dExt4.ts
15954
- import { readdirSync as readdirSync10, statSync as statSync16 } from "fs";
15955
- import { join as join20, relative as relative10 } from "path";
16044
+ import { readdirSync as readdirSync11, statSync as statSync16 } from "fs";
16045
+ import { join as join21, relative as relative10 } from "path";
15956
16046
  function canonical(name) {
15957
16047
  return name.replace(/[-_]/g, "").toLowerCase();
15958
16048
  }
@@ -15976,7 +16066,7 @@ function findHooksDirs(tree, unreadable, gaps) {
15976
16066
  const out = [];
15977
16067
  let base;
15978
16068
  try {
15979
- base = statSync16(root).isDirectory() ? root : join20(root, "..");
16069
+ base = statSync16(root).isDirectory() ? root : join21(root, "..");
15980
16070
  } catch {
15981
16071
  return out;
15982
16072
  }
@@ -15991,13 +16081,13 @@ function findHooksDirs(tree, unreadable, gaps) {
15991
16081
  const walk3 = (dir) => {
15992
16082
  let entries;
15993
16083
  try {
15994
- entries = readdirSync10(dir);
16084
+ entries = readdirSync11(dir);
15995
16085
  } catch (err) {
15996
16086
  noteUnread(dir, "could not be listed", err);
15997
16087
  return;
15998
16088
  }
15999
16089
  for (const name of entries) {
16000
- const full = join20(dir, name);
16090
+ const full = join21(dir, name);
16001
16091
  let st;
16002
16092
  try {
16003
16093
  st = statSync16(full);
@@ -16015,7 +16105,7 @@ function findHooksDirs(tree, unreadable, gaps) {
16015
16105
  const tokens = /* @__PURE__ */ new Set();
16016
16106
  let files;
16017
16107
  try {
16018
- files = readdirSync10(full);
16108
+ files = readdirSync11(full);
16019
16109
  } catch (err) {
16020
16110
  noteUnread(full, "could not be listed", err);
16021
16111
  files = [];
@@ -16179,7 +16269,7 @@ var dExt4 = {
16179
16269
 
16180
16270
  // src/detectors/dExt5.ts
16181
16271
  import { existsSync as existsSync18 } from "fs";
16182
- import { dirname as dirname12, join as join21 } from "path";
16272
+ import { dirname as dirname12, join as join22 } from "path";
16183
16273
  function nonEmptyString(v) {
16184
16274
  return typeof v === "string" && v.trim().length > 0;
16185
16275
  }
@@ -16241,7 +16331,7 @@ var dExt5 = {
16241
16331
  if (!nonEmptyString(parsed.description_fr)) {
16242
16332
  missing.push("description_fr (extension.json)");
16243
16333
  }
16244
- if (!existsSync18(join21(root, "README.fr.md"))) {
16334
+ if (!existsSync18(join22(root, "README.fr.md"))) {
16245
16335
  missing.push("README.fr.md");
16246
16336
  }
16247
16337
  if (isToolExtension(parsed.type) && "tools" in parsed) {
@@ -16285,7 +16375,7 @@ var dExt5 = {
16285
16375
 
16286
16376
  // src/detectors/dExt7.ts
16287
16377
  import { existsSync as existsSync19 } from "fs";
16288
- import { dirname as dirname13, join as join22 } from "path";
16378
+ import { dirname as dirname13, join as join23 } from "path";
16289
16379
  var ABSENCE_FLAG_FIELDS = [
16290
16380
  "extensionAbsent",
16291
16381
  "extension_absent",
@@ -16353,7 +16443,7 @@ var dExt7 = {
16353
16443
  for (const manifestPath2 of manifests) {
16354
16444
  const extDir = dirname13(manifestPath2);
16355
16445
  const extLabel = extDir.split("/").pop() ?? extDir;
16356
- const evalsPath = join22(extDir, "evals", "evals.json");
16446
+ const evalsPath = join23(extDir, "evals", "evals.json");
16357
16447
  const shortPath = `${extLabel}/evals/evals.json`;
16358
16448
  if (!existsSync19(evalsPath)) {
16359
16449
  return {
@@ -16420,7 +16510,7 @@ var dExt7 = {
16420
16510
 
16421
16511
  // src/detectors/dExt8.ts
16422
16512
  import { existsSync as existsSync20 } from "fs";
16423
- import { dirname as dirname14, join as join23 } from "path";
16513
+ import { dirname as dirname14, join as join24 } from "path";
16424
16514
  var SEMVER_RE2 = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
16425
16515
  var POSITIVE_CONTROL5 = "1.2.3-beta.1+build.7";
16426
16516
  function dExt8PositiveControl() {
@@ -16456,7 +16546,7 @@ var dExt8 = {
16456
16546
  for (const manifestPath2 of manifests) {
16457
16547
  const extDir = dirname14(manifestPath2);
16458
16548
  const extLabel = extDir.split("/").pop() ?? extDir;
16459
- const pkgPath = join23(extDir, "package.json");
16549
+ const pkgPath = join24(extDir, "package.json");
16460
16550
  const shortPkgPath = `${extLabel}/package.json`;
16461
16551
  if (!existsSync20(pkgPath)) {
16462
16552
  unreadable.push({
@@ -16493,7 +16583,7 @@ var dExt8 = {
16493
16583
  continue;
16494
16584
  }
16495
16585
  const validSemver = SEMVER_RE2.test(version);
16496
- const changelogPath = join23(extDir, "CHANGELOG.md");
16586
+ const changelogPath = join24(extDir, "CHANGELOG.md");
16497
16587
  const hasChangelog = existsSync20(changelogPath);
16498
16588
  if (!validSemver) {
16499
16589
  finding ??= {
@@ -16528,14 +16618,14 @@ var dExt8 = {
16528
16618
  };
16529
16619
 
16530
16620
  // src/detectors/dExt9.ts
16531
- import { readFileSync as readFileSync14, readdirSync as readdirSync11, statSync as statSync17 } from "fs";
16532
- import { join as join24, relative as relative11 } from "path";
16621
+ import { readFileSync as readFileSync15, readdirSync as readdirSync12, statSync as statSync17 } from "fs";
16622
+ import { join as join25, relative as relative11 } from "path";
16533
16623
  function collectHooksDirSources(tree, unreadable, gaps) {
16534
16624
  const root = tree.root;
16535
16625
  const out = [];
16536
16626
  let base;
16537
16627
  try {
16538
- base = statSync17(root).isDirectory() ? root : join24(root, "..");
16628
+ base = statSync17(root).isDirectory() ? root : join25(root, "..");
16539
16629
  } catch {
16540
16630
  return out;
16541
16631
  }
@@ -16550,13 +16640,13 @@ function collectHooksDirSources(tree, unreadable, gaps) {
16550
16640
  const walk3 = (dir) => {
16551
16641
  let entries;
16552
16642
  try {
16553
- entries = readdirSync11(dir);
16643
+ entries = readdirSync12(dir);
16554
16644
  } catch (err) {
16555
16645
  noteUnread(dir, "could not be listed", err);
16556
16646
  return;
16557
16647
  }
16558
16648
  for (const name of entries) {
16559
- const full = join24(dir, name);
16649
+ const full = join25(dir, name);
16560
16650
  let st;
16561
16651
  try {
16562
16652
  st = statSync17(full);
@@ -16573,7 +16663,7 @@ function collectHooksDirSources(tree, unreadable, gaps) {
16573
16663
  if (name === "hooks") {
16574
16664
  let files;
16575
16665
  try {
16576
- files = readdirSync11(full);
16666
+ files = readdirSync12(full);
16577
16667
  } catch (err) {
16578
16668
  noteUnread(full, "could not be listed", err);
16579
16669
  files = [];
@@ -16582,11 +16672,11 @@ function collectHooksDirSources(tree, unreadable, gaps) {
16582
16672
  if (!f.endsWith(".ts") || f.endsWith(".d.ts")) continue;
16583
16673
  const stem = f.replace(/\.ts$/, "");
16584
16674
  if (stem === "index") continue;
16585
- const filePath = join24(full, f);
16675
+ const filePath = join25(full, f);
16586
16676
  let body;
16587
16677
  try {
16588
16678
  if (!statSync17(filePath).isFile()) throw new Error("not a regular file");
16589
- body = readFileSync14(filePath, "utf8");
16679
+ body = readFileSync15(filePath, "utf8");
16590
16680
  } catch {
16591
16681
  const shortPath = filePath.split("/").slice(-2).join("/");
16592
16682
  unreadable.push({
@@ -18216,7 +18306,7 @@ var e10MrtrOnly = {
18216
18306
 
18217
18307
  // src/detectors/e11-surfaces-derived.ts
18218
18308
  import { existsSync as existsSync21, statSync as statSync18 } from "fs";
18219
- import { dirname as dirname15, join as join25, relative as relative12, sep as sep6 } from "path";
18309
+ import { dirname as dirname15, join as join26, relative as relative12, sep as sep6 } from "path";
18220
18310
  var ALL = ["chat", "cowork", "claude-code"];
18221
18311
  function excludedSurfaces(c) {
18222
18312
  const cause = /* @__PURE__ */ new Map();
@@ -18305,7 +18395,7 @@ var e11SurfacesDerived = {
18305
18395
  text: `${m.rel} surfaces ${unknown.join(", ")} are not in {${ALL.join(", ")}}`
18306
18396
  });
18307
18397
  }
18308
- const mcp = join25(folder, ".mcp.json");
18398
+ const mcp = join26(folder, ".mcp.json");
18309
18399
  let localMcp = false;
18310
18400
  if (existsSync21(mcp)) {
18311
18401
  const mj = readJsonRecord(mcp);
@@ -18324,9 +18414,9 @@ var e11SurfacesDerived = {
18324
18414
  }
18325
18415
  }
18326
18416
  const cause = excludedSurfaces({
18327
- bin: isDir(join25(folder, "bin"), rel(join25(folder, "bin")), unreadable),
18328
- hooks: isDir(join25(folder, "hooks"), rel(join25(folder, "hooks")), unreadable),
18329
- agents: isDir(join25(folder, "agents"), rel(join25(folder, "agents")), unreadable),
18417
+ bin: isDir(join26(folder, "bin"), rel(join26(folder, "bin")), unreadable),
18418
+ hooks: isDir(join26(folder, "hooks"), rel(join26(folder, "hooks")), unreadable),
18419
+ agents: isDir(join26(folder, "agents"), rel(join26(folder, "agents")), unreadable),
18330
18420
  localMcp
18331
18421
  });
18332
18422
  for (const s of declared) {
@@ -18450,8 +18540,8 @@ var e12HostCapabilityPlacement = {
18450
18540
  };
18451
18541
 
18452
18542
  // src/detectors/installedAs.ts
18453
- import { readdirSync as readdirSync12, statSync as statSync19 } from "fs";
18454
- import { join as join26 } from "path";
18543
+ import { readdirSync as readdirSync13, statSync as statSync19 } from "fs";
18544
+ import { join as join27 } from "path";
18455
18545
  var KEY = (k) => `(?:["']${k}["']|\\b${k}\\b)`;
18456
18546
  function flagTrueRe(key) {
18457
18547
  return new RegExp(`${KEY(key)}\\s*:\\s*true\\b`);
@@ -18476,7 +18566,7 @@ function declaredDependencies(tree) {
18476
18566
  }
18477
18567
  function readInstalledAs(tree) {
18478
18568
  const out = { installed: false, missing: [], publishers: [], unread: [] };
18479
- const nm = join26(baseOf(tree), "node_modules");
18569
+ const nm = join27(baseOf(tree), "node_modules");
18480
18570
  try {
18481
18571
  out.installed = statSync19(nm).isDirectory();
18482
18572
  } catch {
@@ -18485,7 +18575,7 @@ function readInstalledAs(tree) {
18485
18575
  if (!out.installed) return out;
18486
18576
  const methods = authMethodsRe();
18487
18577
  for (const dep of declaredDependencies(tree)) {
18488
- const dir = join26(nm, dep);
18578
+ const dir = join27(nm, dep);
18489
18579
  try {
18490
18580
  if (!statSync19(dir).isDirectory()) throw new Error("not a directory");
18491
18581
  } catch {
@@ -18496,7 +18586,7 @@ function readInstalledAs(tree) {
18496
18586
  const walk3 = (d) => {
18497
18587
  let names;
18498
18588
  try {
18499
- names = readdirSync12(d).sort();
18589
+ names = readdirSync13(d).sort();
18500
18590
  } catch (e) {
18501
18591
  out.unread.push(
18502
18592
  `${d.slice(nm.length + 1)} (directory not listed: ${e.message})`
@@ -18506,7 +18596,7 @@ function readInstalledAs(tree) {
18506
18596
  for (const n of names) {
18507
18597
  if (files.length >= MAX_FILES_PER_PACKAGE) return;
18508
18598
  if (n === "node_modules") continue;
18509
- const full = join26(d, n);
18599
+ const full = join27(d, n);
18510
18600
  let st;
18511
18601
  try {
18512
18602
  st = statSync19(full);
@@ -21659,8 +21749,55 @@ var s27ElicitationFloor = {
21659
21749
  };
21660
21750
 
21661
21751
  // src/detectors/s28-claim-forwarded.ts
21662
- import { existsSync as existsSync22, readFileSync as readFileSync15, readdirSync as readdirSync13, statSync as statSync20 } from "fs";
21663
- import { dirname as dirname16, join as join27, relative as relative13 } from "path";
21752
+ import { existsSync as existsSync22, readFileSync as readFileSync16, readdirSync as readdirSync14, statSync as statSync20 } from "fs";
21753
+ import { dirname as dirname16, join as join28, relative as relative13 } from "path";
21754
+
21755
+ // src/detectors/backendReceiver.ts
21756
+ var CLIENT_NAME = /convex|client/i;
21757
+ var CLIENT_TYPE = /\bConvex\w*Client\b/;
21758
+ function esc4(s) {
21759
+ return s.replace(/\$/g, "\\$");
21760
+ }
21761
+ function backendReceiver(m, recv, at, depth = 0) {
21762
+ if (CLIENT_NAME.test(recv)) return { kind: "client", how: `named ${recv}` };
21763
+ if (depth > 4) return { kind: "unresolved", why: `${recv}: alias chain too deep` };
21764
+ if (/\.\s*$/.test(m.slice(Math.max(0, at - 4), at)))
21765
+ return {
21766
+ kind: "unresolved",
21767
+ why: `${recv} is a property whose value this scan does not follow`
21768
+ };
21769
+ const head = m.slice(0, at);
21770
+ const r = esc4(recv);
21771
+ if (new RegExp(`(?<![\\w$.])${r}\\s*\\??\\s*:\\s*[\\w$.<>|\\s]*${CLIENT_TYPE.source}`).test(head))
21772
+ return { kind: "client", how: `${recv} typed as a Convex client` };
21773
+ const destr = new RegExp(`[{,]\\s*([A-Za-z_$][\\w$]*)\\s*:\\s*${r}\\s*[,}=]`).exec(head);
21774
+ if (destr && CLIENT_NAME.test(destr[1]))
21775
+ return { kind: "client", how: `${recv} destructured from ${destr[1]}` };
21776
+ let init;
21777
+ for (const b of head.matchAll(
21778
+ new RegExp(`\\b(?:const|let|var)\\s+${r}\\s*(?::[^=;]*)?=\\s*([^;\\n]+)`, "g")
21779
+ ))
21780
+ init = b[1].trim();
21781
+ if (init !== void 0) {
21782
+ if (/^(?:new\s+)?Convex\w*Client\s*\(/.test(init))
21783
+ return { kind: "client", how: `${recv} = ${init.split("(")[0]}(\u2026)` };
21784
+ const id = /^([A-Za-z_$][\w$]*)\s*(?:as\s+[\w$.<>]+)?\s*$/.exec(init);
21785
+ if (id) {
21786
+ const inner = backendReceiver(m, id[1], head.lastIndexOf(init), depth + 1);
21787
+ return inner.kind === "client" ? { kind: "client", how: `${recv} = ${id[1]} (${inner.how})` } : { kind: "unresolved", why: `${recv} = ${id[1]}: ${inner.why}` };
21788
+ }
21789
+ return {
21790
+ kind: "unresolved",
21791
+ why: `${recv} is bound to an expression this scan does not resolve (${init.slice(0, 40)})`
21792
+ };
21793
+ }
21794
+ return { kind: "unresolved", why: `${recv} has no binding this scan can read` };
21795
+ }
21796
+ function importsConvex(m, raw) {
21797
+ return /\bfrom\s+["']convex\/[\w/-]+["']|\brequire\(\s*["']convex\//.test(raw) || CLIENT_TYPE.test(m);
21798
+ }
21799
+
21800
+ // src/detectors/s28-claim-forwarded.ts
21664
21801
  var PIN11 = STANDARD_PIN;
21665
21802
  var CLAIM_TOKEN = /\bverified(?:Org|Person)\b/;
21666
21803
  var ANY_CLAIM = /\bverified(?:Actor|Org|Person)\b/g;
@@ -21721,14 +21858,14 @@ function splitTop2(m, from, to) {
21721
21858
  function listTs(dir, unread2, out = []) {
21722
21859
  let names;
21723
21860
  try {
21724
- names = readdirSync13(dir);
21861
+ names = readdirSync14(dir);
21725
21862
  } catch (err) {
21726
21863
  unread2.push(`${dir} could not be listed (${fsErrorCode(err)})`);
21727
21864
  return out;
21728
21865
  }
21729
21866
  for (const n of names) {
21730
21867
  if (n === "node_modules" || n === "_generated" || n === "__tests__") continue;
21731
- const p = join27(dir, n);
21868
+ const p = join28(dir, n);
21732
21869
  let st;
21733
21870
  try {
21734
21871
  st = statSync20(p);
@@ -21752,8 +21889,8 @@ function discoverBackend(root) {
21752
21889
  return void 0;
21753
21890
  }
21754
21891
  for (let up = 0; up < 5; up++) {
21755
- const cand = join27(dir, "convex");
21756
- if (existsSync22(join27(cand, "schema.ts"))) return cand;
21892
+ const cand = join28(dir, "convex");
21893
+ if (existsSync22(join28(cand, "schema.ts"))) return cand;
21757
21894
  const parent = dirname16(dir);
21758
21895
  if (parent === dir) break;
21759
21896
  dir = parent;
@@ -21765,7 +21902,7 @@ function readDoors(backendRoot, unread2) {
21765
21902
  for (const path of listTs(backendRoot, unread2)) {
21766
21903
  let text;
21767
21904
  try {
21768
- text = readFileSync15(path, "utf8");
21905
+ text = readFileSync16(path, "utf8");
21769
21906
  } catch (err) {
21770
21907
  unread2.push(`${path} could not be read (${fsErrorCode(err)})`);
21771
21908
  continue;
@@ -21830,8 +21967,8 @@ function readDoors(backendRoot, unread2) {
21830
21967
  return doors;
21831
21968
  }
21832
21969
  function definitionOf(name, files) {
21833
- const esc5 = name.replace(/\$/g, "\\$");
21834
- const re = new RegExp(`(?:\\b(?:const|let|var)\\s+${esc5}\\b|\\bfunction\\s+${esc5}\\b)`);
21970
+ const esc7 = name.replace(/\$/g, "\\$");
21971
+ const re = new RegExp(`(?:\\b(?:const|let|var)\\s+${esc7}\\b|\\bfunction\\s+${esc7}\\b)`);
21835
21972
  for (const f of files) {
21836
21973
  const hit = re.exec(f.m);
21837
21974
  if (!hit) continue;
@@ -21871,9 +22008,273 @@ function readHelper(name, files, seen = /* @__PURE__ */ new Set(), depth = 0) {
21871
22008
  }
21872
22009
  return { forwards, optional };
21873
22010
  }
22011
+ var IDENT2 = /^\s*([A-Za-z_$][\w$]*)\s*(?:as\s+[\w$.<>[\]]+\s*)?$/;
22012
+ function esc5(name) {
22013
+ return name.replace(/\$/g, "\\$");
22014
+ }
22015
+ function enclosingFn(m, at, x) {
22016
+ let best;
22017
+ for (const hit of m.slice(0, at).matchAll(new RegExp(`\\(\\s*${esc5(x)}\\s*[?:,)]`, "g"))) {
22018
+ const close = matchClose2(m, hit.index);
22019
+ if (close < 0 || close > at) continue;
22020
+ if (/^\s*(?::[^{=;]*?)?\s*(?:=>|\{)/.test(m.slice(close + 1, close + 240)))
22021
+ best = { open: hit.index, close };
22022
+ }
22023
+ return best;
22024
+ }
22025
+ function enclosingCall(m, offset) {
22026
+ let depth = 0;
22027
+ for (let i = offset - 1; i >= 0; i--) {
22028
+ const ch = m[i];
22029
+ if (ch === ")" || ch === "]" || ch === "}") depth++;
22030
+ else if (ch === "(" || ch === "[" || ch === "{") {
22031
+ if (depth > 0) {
22032
+ depth--;
22033
+ continue;
22034
+ }
22035
+ if (ch !== "(") return void 0;
22036
+ const callee = /([A-Za-z_$][\w$]*)\s*(?:<[^<>]*>)?\s*$/.exec(
22037
+ m.slice(Math.max(0, i - 200), i)
22038
+ );
22039
+ if (!callee || /^(?:if|for|while|switch|catch|function|return)$/.test(callee[1]))
22040
+ return void 0;
22041
+ const close = matchClose2(m, i);
22042
+ if (close < 0) return void 0;
22043
+ const index = splitTop2(m, i + 1, close).findIndex(([a, b]) => offset >= a && offset < b);
22044
+ return index < 0 ? void 0 : { callee: callee[1], index };
22045
+ }
22046
+ }
22047
+ return void 0;
22048
+ }
22049
+ function paramOf(callee, index, files) {
22050
+ const c = esc5(callee);
22051
+ const re = new RegExp(
22052
+ `(?:\\bfunction\\s*\\*?\\s*${c}\\s*(?:<[^<>]*>)?\\s*\\(|\\b(?:const|let|var)\\s+${c}\\s*(?::[^=]*)?=\\s*(?:async\\s*)?(?:function\\s*)?\\()`
22053
+ );
22054
+ for (const fr of files) {
22055
+ const hit = re.exec(fr.m);
22056
+ if (!hit) continue;
22057
+ const open = hit.index + hit[0].length - 1;
22058
+ const close = matchClose2(fr.m, open);
22059
+ if (close < 0) return { file: fr, text: void 0 };
22060
+ const part = splitTop2(fr.m, open + 1, close)[index];
22061
+ return part ? { file: fr, text: fr.m.slice(part[0], part[1]).trim(), span: part } : { file: fr, text: void 0 };
22062
+ }
22063
+ return void 0;
22064
+ }
22065
+ function paramItem(param, key, callee) {
22066
+ const t = param.text;
22067
+ if (t === void 0) return `is handed to ${callee}, whose parameter cannot be read`;
22068
+ if (t.startsWith("{")) {
22069
+ if (key === void 0) return `is handed to ${callee}, whose parameter destructures it`;
22070
+ const k = esc5(key);
22071
+ const alias = new RegExp(`(?<![\\w$.])${k}\\s*:\\s*([A-Za-z_$][\\w$]*)`).exec(t);
22072
+ if (alias) return { name: alias[1], scope: [param.file], skip: param.span };
22073
+ if (new RegExp(`(?<![\\w$.])${k}\\s*[,}=]`).test(t))
22074
+ return { name: key, scope: [param.file], skip: param.span };
22075
+ return `is handed to ${callee} as property ${key}, which its parameter does not take`;
22076
+ }
22077
+ const id = /^(?:\.\.\.)?([A-Za-z_$][\w$]*)/.exec(t);
22078
+ if (!id) return `is handed to ${callee}, whose parameter cannot be read`;
22079
+ return {
22080
+ name: key === void 0 ? id[1] : `${id[1]}.${key}`,
22081
+ scope: [param.file],
22082
+ skip: param.span
22083
+ };
22084
+ }
22085
+ function handOff(at, o, len, files, propertyOf, expression = false) {
22086
+ const pre = at.m.slice(Math.max(0, o - 160), o);
22087
+ const after = at.m.slice(o + len, o + len + 40);
22088
+ let argAt = o;
22089
+ let key = propertyOf;
22090
+ if (!(/[(,]\s*$/.test(pre) && (expression || /^\s*[,)]/.test(after)))) {
22091
+ const prop = /[{,]\s*([A-Za-z_$][\w$]*)\s*:\s*$/.exec(pre);
22092
+ const short = !expression && /[{,]\s*$/.test(pre) && /^\s*[,}]/.test(after);
22093
+ if (!prop && !short) return void 0;
22094
+ if (key !== void 0) return "is nested two objects deep, which this scan does not follow";
22095
+ key = prop ? prop[1] : at.m.slice(o, o + len);
22096
+ let depth = 0;
22097
+ let brace = -1;
22098
+ for (let i = o - 1; i >= 0; i--) {
22099
+ const ch = at.m[i];
22100
+ if (ch === ")" || ch === "]" || ch === "}") depth++;
22101
+ else if (ch === "(" || ch === "[" || ch === "{") {
22102
+ if (depth > 0) depth--;
22103
+ else {
22104
+ brace = ch === "{" ? i : -1;
22105
+ break;
22106
+ }
22107
+ }
22108
+ }
22109
+ const end = brace < 0 ? -1 : matchClose2(at.m, brace);
22110
+ if (end < 0 || !/[(,]\s*$/.test(at.m.slice(Math.max(0, brace - 40), brace)) || !/^\s*[,)]/.test(at.m.slice(end + 1, end + 40)))
22111
+ return `is property ${key} of an object that is not passed directly to a function`;
22112
+ argAt = brace;
22113
+ }
22114
+ const call = enclosingCall(at.m, argAt);
22115
+ if (!call) return "is passed in a form this scan does not follow";
22116
+ const param = paramOf(call.callee, call.index, files);
22117
+ if (!param) return `is handed to ${call.callee}, whose definition is not in the scanned tree`;
22118
+ return paramItem(param, key, call.callee);
22119
+ }
22120
+ function readFetchers(files, scan, onCall) {
22121
+ const wrappers = /* @__PURE__ */ new Set();
22122
+ for (const fr of files) {
22123
+ const calls = new RegExp(CALL_RE2.source, "g");
22124
+ for (let hit = calls.exec(fr.m); hit; hit = calls.exec(fr.m)) {
22125
+ const open = hit.index + hit[0].length - 1;
22126
+ const close = matchClose2(fr.m, open);
22127
+ if (close < 0) continue;
22128
+ const parts = splitTop2(fr.m, open + 1, close);
22129
+ const first = parts[0] ? IDENT2.exec(fr.m.slice(parts[0][0], parts[0][1])) : null;
22130
+ if (!first) continue;
22131
+ const fn = enclosingFn(fr.m, hit.index, first[1]);
22132
+ if (!fn) continue;
22133
+ const rcv = backendReceiver(fr.m, hit[1], hit.index);
22134
+ wrappers.add(`${fr.f.rel}:${hit.index}`);
22135
+ if (rcv.kind === "unresolved") {
22136
+ scan.cnj.push({
22137
+ file: fr.f.rel,
22138
+ line: lineAt2(fr.text, hit.index),
22139
+ door: "?",
22140
+ tool: toolNameBefore(fr.text, hit.index).name,
22141
+ note: `a fetcher-shaped call (its door is the enclosing function's first parameter) on a receiver not resolved to a backend client \u2014 ${rcv.why}: the doors it reaches are unknown`
22142
+ });
22143
+ continue;
22144
+ }
22145
+ const argText2 = parts[1] ? fr.m.slice(parts[1][0], parts[1][1]) : "";
22146
+ let wrapperClaim = CLAIM_TOKEN.test(argText2);
22147
+ if (!wrapperClaim) {
22148
+ for (const h of argText2.matchAll(/(?:\.\.\.\s*|\b)([A-Za-z_$][\w$]*)\s*(?:\(\s*\))?/g))
22149
+ if (h[1] !== first[1] && readHelper(h[1], files).forwards) {
22150
+ wrapperClaim = true;
22151
+ break;
22152
+ }
22153
+ }
22154
+ const label = toolNameBefore(fr.text, hit.index).name;
22155
+ const before = fr.m.slice(Math.max(0, fn.open - 240), fn.open);
22156
+ const named = /\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*(?::[^=]*)?=\s*(?:async\s*)?$/.exec(before) ?? /\bfunction\s*\*?\s*([A-Za-z_$][\w$]*)\s*(?:<[^<>]*>)?\s*$/.exec(before);
22157
+ const where = `${fr.f.rel}:${lineAt2(fr.text, fn.open)}`;
22158
+ const name = named ? named[1] : "(anonymous)";
22159
+ const via = { name, where, label, wrapperClaim };
22160
+ const cnj = (at, offset, note) => scan.cnj.push({
22161
+ file: at.f.rel,
22162
+ line: lineAt2(at.text, offset),
22163
+ door: "?",
22164
+ tool: label,
22165
+ note: `the fetcher ${name} injected at ${where} ${note}: the doors it reaches are unknown`
22166
+ });
22167
+ const queue = [];
22168
+ if (named) queue.push({ name: named[1], scope: [fr] });
22169
+ else {
22170
+ const asyncAt = /async\s*$/.exec(before);
22171
+ const start = asyncAt ? fn.open - (before.length - asyncAt.index) : fn.open;
22172
+ const h = handOff(fr, start, fn.open - start + 1, files, void 0, true);
22173
+ if (h === void 0 || typeof h === "string") {
22174
+ cnj(fr, fn.open, h ?? "is not handed to a named function");
22175
+ continue;
22176
+ }
22177
+ queue.push(h);
22178
+ }
22179
+ const seen = /* @__PURE__ */ new Set();
22180
+ let reached = 0;
22181
+ let unknown = 0;
22182
+ while (queue.length > 0) {
22183
+ const item = queue.shift();
22184
+ for (const at of item.scope) {
22185
+ const key = `${item.name}@${at.f.rel}`;
22186
+ if (seen.has(key)) continue;
22187
+ seen.add(key);
22188
+ const segs = item.name.split(".");
22189
+ const pattern = segs.map(esc5).join("\\s*\\.\\s*");
22190
+ for (const occ of at.m.matchAll(new RegExp(`(?<![\\w$.])${pattern}(?![\\w$])`, "g"))) {
22191
+ const o = occ.index;
22192
+ const len = occ[0].length;
22193
+ if (item.skip && at === item.scope[0] && o >= item.skip[0] && o < item.skip[1])
22194
+ continue;
22195
+ const after = at.m.slice(o + len, o + len + 240);
22196
+ const pre = at.m.slice(Math.max(0, o - 60), o);
22197
+ if (/\b(?:const|let|var|function)\s*\*?\s*$/.test(pre)) continue;
22198
+ if (/^\s*\??\s*:/.test(after)) continue;
22199
+ if (/^\s*(?:<[^<>]*>)?\s*\(/.test(after)) {
22200
+ const po = o + len + after.indexOf("(");
22201
+ const pc = matchClose2(at.m, po);
22202
+ if (pc < 0) {
22203
+ unknown++;
22204
+ cnj(at, o, "has a call here that could not be read");
22205
+ continue;
22206
+ }
22207
+ const cp = splitTop2(at.m, po + 1, pc);
22208
+ const raw = cp[0] ? at.text.slice(cp[0][0], cp[0][1]) : "";
22209
+ const lit = /^\s*(?:\/\/[^\n]*\n\s*)*["'`]([\w/]+:[\w]+)["'`]/.exec(raw);
22210
+ const ref = /^\s*(?:api|internal)\.([\w]+)\.([\w]+)/.exec(raw);
22211
+ const door = lit ? lit[1] : ref ? `${ref[1]}:${ref[2]}` : void 0;
22212
+ scan.calls++;
22213
+ if (!door) {
22214
+ unknown++;
22215
+ cnj(
22216
+ at,
22217
+ o,
22218
+ "is called here with its door named by an expression (not statically resolvable)"
22219
+ );
22220
+ continue;
22221
+ }
22222
+ reached++;
22223
+ onCall(at, o, door, cp[1] ? at.m.slice(cp[1][0], cp[1][1]) : "", via);
22224
+ continue;
22225
+ }
22226
+ const h = handOff(at, o, len, files);
22227
+ if (h !== void 0) {
22228
+ if (typeof h === "string") {
22229
+ unknown++;
22230
+ cnj(at, o, h);
22231
+ } else queue.push(h);
22232
+ continue;
22233
+ }
22234
+ unknown++;
22235
+ cnj(at, o, "is used here in a form this scan does not follow");
22236
+ }
22237
+ if (segs.length === 2) {
22238
+ for (const occ of at.m.matchAll(
22239
+ new RegExp(`(?<![\\w$.])${esc5(segs[0])}(?![\\w$])(?!\\s*\\.)`, "g")
22240
+ )) {
22241
+ const pre = at.m.slice(Math.max(0, occ.index - 60), occ.index);
22242
+ const after = at.m.slice(occ.index + segs[0].length, occ.index + segs[0].length + 40);
22243
+ if (!(/[(,]\s*$/.test(pre) && /^\s*[,)]/.test(after))) continue;
22244
+ const call = enclosingCall(at.m, occ.index);
22245
+ const param = call ? paramOf(call.callee, call.index, files) : void 0;
22246
+ if (!call) continue;
22247
+ if (!param) {
22248
+ unknown++;
22249
+ cnj(
22250
+ at,
22251
+ occ.index,
22252
+ `travels in ${segs[0]}, handed to ${call.callee}, whose definition is not in the scanned tree`
22253
+ );
22254
+ continue;
22255
+ }
22256
+ const next = paramItem(param, segs[1], call.callee);
22257
+ if (typeof next === "string") {
22258
+ unknown++;
22259
+ cnj(at, occ.index, next);
22260
+ } else queue.push(next);
22261
+ }
22262
+ }
22263
+ }
22264
+ }
22265
+ if (reached === 0 && unknown === 0) cnj(fr, fn.open, "has no call site in the scanned tree");
22266
+ }
22267
+ }
22268
+ return { wrappers };
22269
+ }
21874
22270
  function toolNameBefore(text, offset) {
21875
22271
  const head = text.slice(0, offset);
21876
22272
  const open = Math.max(head.lastIndexOf("defineTool("), head.lastIndexOf("registerTool("));
22273
+ const res = head.lastIndexOf("registerResource(");
22274
+ if (res > open) {
22275
+ const r = /registerResource\(\s*["'`]([^"'`]+)["'`]/.exec(head.slice(res));
22276
+ return { name: r ? `resource ${r[1]}` : "resource (unnamed)", start: res };
22277
+ }
21877
22278
  if (open >= 0) {
21878
22279
  const m = /^\s*"([a-z][a-z0-9_]*)",?\s*$/m.exec(head.slice(open));
21879
22280
  if (m) return { name: m[1], start: open };
@@ -21898,10 +22299,127 @@ function scanS28(tree) {
21898
22299
  const hit = ACTOR_SET_RE.exec(text);
21899
22300
  if (hit) for (const s of hit[2].matchAll(/["'`]([\w/]+:[\w]+)["'`]/g)) actorDoors.add(s[1]);
21900
22301
  }
22302
+ const judge2 = (text, m, at, door, argText2, tool, site) => {
22303
+ const region = m.slice(tool.start, at);
22304
+ const regionRaw = text.slice(tool.start, at);
22305
+ const guard = GUARD_RE.test(region) || GUARD_RE.test(regionRaw);
22306
+ let direct = CLAIM_TOKEN.test(argText2);
22307
+ let viaHelper;
22308
+ let virtual = argText2;
22309
+ const bare = /^\s*([A-Za-z_$][\w$]*)\s*$/.exec(argText2);
22310
+ if (bare && !direct) {
22311
+ const v = bare[1].replace(/\$/g, "\\$");
22312
+ const pieces = [];
22313
+ for (const a of region.matchAll(new RegExp(`Object\\.assign\\s*\\(\\s*${v}\\s*,`, "g"))) {
22314
+ const o = a.index + a[0].length - 1;
22315
+ const c = matchClose2(region, region.lastIndexOf("(", o));
22316
+ pieces.push(region.slice(o, c < 0 ? o + 400 : c));
22317
+ }
22318
+ for (const a of region.matchAll(new RegExp(`\\b${v}\\.verified(?:Org|Person|Actor)\\b`, "g")))
22319
+ pieces.push(a[0]);
22320
+ const decl = new RegExp(`\\b(?:const|let)\\s+${v}\\b[^=]*=\\s*\\{`).exec(region);
22321
+ if (decl) {
22322
+ const o = decl.index + decl[0].length - 1;
22323
+ const c = matchClose2(region, o);
22324
+ pieces.push(region.slice(o, c < 0 ? o + 600 : c + 1));
22325
+ }
22326
+ virtual = pieces.join("\n");
22327
+ direct = CLAIM_TOKEN.test(virtual);
22328
+ }
22329
+ if (!direct) {
22330
+ for (const sp of virtual.matchAll(/\.\.\.\s*([A-Za-z_$][\w$]*)/g)) {
22331
+ const h = readHelper(sp[1], files);
22332
+ if (h.forwards) {
22333
+ viaHelper = h;
22334
+ break;
22335
+ }
22336
+ }
22337
+ if (!viaHelper) {
22338
+ for (const sp of virtual.matchAll(/\b([A-Za-z_$][\w$]*)\s*\(\s*\)/g)) {
22339
+ const h = readHelper(sp[1], files);
22340
+ if (h.forwards) {
22341
+ viaHelper = h;
22342
+ break;
22343
+ }
22344
+ }
22345
+ }
22346
+ }
22347
+ if (direct) {
22348
+ scan.conform.push(site("forwards the verified claim in the call"));
22349
+ return;
22350
+ }
22351
+ if (viaHelper) {
22352
+ if (viaHelper.optional && !guard) {
22353
+ scan.violate.push(
22354
+ site(
22355
+ "forwards its claim through an optional helper (it returns {} when the bearer holds none) and no refusal precedes the call in the handler: a bearer with no resolvable organisation is sent claimless"
22356
+ )
22357
+ );
22358
+ } else {
22359
+ scan.conform.push(
22360
+ site(
22361
+ viaHelper.optional ? "forwards the verified claim through a helper and refuses before the call when it holds none" : "forwards the verified claim through a helper"
22362
+ )
22363
+ );
22364
+ }
22365
+ return;
22366
+ }
22367
+ if (!doors) {
22368
+ scan.cnj.push(
22369
+ site(
22370
+ "forwards no verified claim and no backend source was found above the scanned tree (no convex/ with a schema.ts, and no backend root given): whether the door is an exit cannot be read"
22371
+ )
22372
+ );
22373
+ return;
22374
+ }
22375
+ const info = doors.get(door);
22376
+ if (!info) {
22377
+ scan.cnj.push(
22378
+ site(
22379
+ `forwards no verified claim and the door ${door} is not defined in the supplied backend (${backendRoot})${unreadNote}`
22380
+ )
22381
+ );
22382
+ return;
22383
+ }
22384
+ if (info.exit) {
22385
+ scan.conform.push(site(`needs no claim: the door is ${info.exit}`));
22386
+ return;
22387
+ }
22388
+ if (!info.resolvesCaller) {
22389
+ scan.cnj.push(
22390
+ site(
22391
+ `forwards no verified claim and the door ${door} shows no caller resolution in its own source (its scope comes from a helper or a run call that this scan does not follow)`
22392
+ )
22393
+ );
22394
+ return;
22395
+ }
22396
+ const accepts = info.claims.length > 0 ? `the door accepts ${info.claims.join(", ")} and the tool omits it` : "the door accepts no claim argument, so R-54 must add one before the tool can forward it";
22397
+ const actorNote = actorDoors.has(door) ? "; verifiedActor is added by the wrapped client only for a bearer that resolved an agent, and a bearer that resolved no agent (a seat or person token, an org-level token) is sent claimless" : "";
22398
+ scan.violate.push(site(`forwards no verified claim \u2014 ${accepts}${actorNote}`));
22399
+ };
22400
+ const fetchers = readFetchers(files, scan, (fr, at, door, argText2, via) => {
22401
+ const tool = toolNameBefore(fr.text, at);
22402
+ const line = lineAt2(fr.text, at);
22403
+ const where = ` (through the fetcher ${via.name} injected at ${via.where}${via.label ? `, ${via.label}` : ""})`;
22404
+ const site = (note) => ({
22405
+ file: fr.f.rel,
22406
+ line,
22407
+ door,
22408
+ tool: tool.name ?? via.label,
22409
+ note: note + where
22410
+ });
22411
+ if (via.wrapperClaim) {
22412
+ scan.conform.push(
22413
+ site(`forwards the verified claim: the fetcher ${via.name} adds it to every call`)
22414
+ );
22415
+ return;
22416
+ }
22417
+ judge2(fr.text, fr.m, at, door, argText2, tool, site);
22418
+ });
21901
22419
  for (const { f, text, m } of files) {
21902
22420
  for (let hit = CALL_RE2.exec(m); hit; hit = CALL_RE2.exec(m)) {
21903
22421
  const recv = hit[1];
21904
- if (!/convex|client/i.test(recv)) continue;
22422
+ const rcv = backendReceiver(m, recv, hit.index);
21905
22423
  const open = hit.index + hit[0].length - 1;
21906
22424
  const close = matchClose2(m, open);
21907
22425
  if (close < 0) continue;
@@ -21924,113 +22442,30 @@ function scanS28(tree) {
21924
22442
  tool: tool.name,
21925
22443
  note
21926
22444
  });
21927
- if (door === void 0) {
21928
- scan.cnj.push(
21929
- site(
21930
- "the door is named by an expression the scan cannot resolve (not statically resolvable)"
21931
- )
21932
- );
21933
- continue;
21934
- }
21935
- const argText2 = parts[1] ? m.slice(parts[1][0], parts[1][1]) : "";
21936
- const region = m.slice(tool.start, hit.index);
21937
- const regionRaw = text.slice(tool.start, hit.index);
21938
- const guard = GUARD_RE.test(region) || GUARD_RE.test(regionRaw);
21939
- let direct = CLAIM_TOKEN.test(argText2);
21940
- let viaHelper;
21941
- let virtual = argText2;
21942
- const bare = /^\s*([A-Za-z_$][\w$]*)\s*$/.exec(argText2);
21943
- if (bare && !direct) {
21944
- const v = bare[1].replace(/\$/g, "\\$");
21945
- const pieces = [];
21946
- for (const a of region.matchAll(new RegExp(`Object\\.assign\\s*\\(\\s*${v}\\s*,`, "g"))) {
21947
- const o = a.index + a[0].length - 1;
21948
- const c = matchClose2(region, region.lastIndexOf("(", o));
21949
- pieces.push(region.slice(o, c < 0 ? o + 400 : c));
21950
- }
21951
- for (const a of region.matchAll(
21952
- new RegExp(`\\b${v}\\.verified(?:Org|Person|Actor)\\b`, "g")
21953
- ))
21954
- pieces.push(a[0]);
21955
- const decl = new RegExp(`\\b(?:const|let)\\s+${v}\\b[^=]*=\\s*\\{`).exec(region);
21956
- if (decl) {
21957
- const o = decl.index + decl[0].length - 1;
21958
- const c = matchClose2(region, o);
21959
- pieces.push(region.slice(o, c < 0 ? o + 600 : c + 1));
21960
- }
21961
- virtual = pieces.join("\n");
21962
- direct = CLAIM_TOKEN.test(virtual);
21963
- }
21964
- if (!direct) {
21965
- for (const sp of virtual.matchAll(/\.\.\.\s*([A-Za-z_$][\w$]*)/g)) {
21966
- const h = readHelper(sp[1], files);
21967
- if (h.forwards) {
21968
- viaHelper = h;
21969
- break;
21970
- }
21971
- }
21972
- if (!viaHelper) {
21973
- for (const sp of virtual.matchAll(/\b([A-Za-z_$][\w$]*)\s*\(\s*\)/g)) {
21974
- const h = readHelper(sp[1], files);
21975
- if (h.forwards) {
21976
- viaHelper = h;
21977
- break;
21978
- }
21979
- }
21980
- }
21981
- }
21982
- if (direct) {
21983
- scan.conform.push(site("forwards the verified claim in the call"));
21984
- continue;
21985
- }
21986
- if (viaHelper) {
21987
- if (viaHelper.optional && !guard) {
21988
- scan.violate.push(
21989
- site(
21990
- "forwards its claim through an optional helper (it returns {} when the bearer holds none) and no refusal precedes the call in the handler: a bearer with no resolvable organisation is sent claimless"
21991
- )
21992
- );
21993
- } else {
21994
- scan.conform.push(
21995
- site(
21996
- viaHelper.optional ? "forwards the verified claim through a helper and refuses before the call when it holds none" : "forwards the verified claim through a helper"
21997
- )
21998
- );
21999
- }
22000
- continue;
22001
- }
22002
- if (!doors) {
22003
- scan.cnj.push(
22004
- site(
22005
- "forwards no verified claim and no backend source was found above the scanned tree (no convex/ with a schema.ts, and no backend root given): whether the door is an exit cannot be read"
22006
- )
22007
- );
22008
- continue;
22009
- }
22010
- const info = doors.get(door);
22011
- if (!info) {
22012
- scan.cnj.push(
22013
- site(
22014
- `forwards no verified claim and the door ${door} is not defined in the supplied backend (${backendRoot})${unreadNote}`
22015
- )
22016
- );
22017
- continue;
22018
- }
22019
- if (info.exit) {
22020
- scan.conform.push(site(`needs no claim: the door is ${info.exit}`));
22445
+ if (fetchers.wrappers.has(`${f.rel}:${hit.index}`)) continue;
22446
+ if (rcv.kind === "unresolved") {
22447
+ if (door !== void 0 || importsConvex(m, text))
22448
+ scan.cnj.push(site(`the receiver is not resolved to a backend client \u2014 ${rcv.why}`));
22449
+ else scan.calls--;
22021
22450
  continue;
22022
22451
  }
22023
- if (!info.resolvesCaller) {
22452
+ if (door === void 0) {
22024
22453
  scan.cnj.push(
22025
22454
  site(
22026
- `forwards no verified claim and the door ${door} shows no caller resolution in its own source (its scope comes from a helper or a run call that this scan does not follow)`
22455
+ "the door is named by an expression the scan cannot resolve (not statically resolvable)"
22027
22456
  )
22028
22457
  );
22029
22458
  continue;
22030
22459
  }
22031
- const accepts = info.claims.length > 0 ? `the door accepts ${info.claims.join(", ")} and the tool omits it` : "the door accepts no claim argument, so R-54 must add one before the tool can forward it";
22032
- const actorNote = actorDoors.has(door) ? "; verifiedActor is added by the wrapped client only for a bearer that resolved an agent, and a bearer that resolved no agent (a seat or person token, an org-level token) is sent claimless" : "";
22033
- scan.violate.push(site(`forwards no verified claim \u2014 ${accepts}${actorNote}`));
22460
+ judge2(
22461
+ text,
22462
+ m,
22463
+ hit.index,
22464
+ door,
22465
+ parts[1] ? m.slice(parts[1][0], parts[1][1]) : "",
22466
+ tool,
22467
+ site
22468
+ );
22034
22469
  }
22035
22470
  }
22036
22471
  return scan;
@@ -22471,7 +22906,7 @@ function blockEnd(m, at) {
22471
22906
  return m.length;
22472
22907
  }
22473
22908
  var lineAt3 = (m, offset) => m.slice(0, offset).split("\n").length;
22474
- var esc4 = (s) => s.replace(/\$/g, "\\$");
22909
+ var esc6 = (s) => s.replace(/\$/g, "\\$");
22475
22910
  function boundNames(m, callStart) {
22476
22911
  const lineStart = m.lastIndexOf("\n", callStart - 1) + 1;
22477
22912
  const before = m.slice(lineStart, callStart);
@@ -22556,7 +22991,7 @@ function rebound(m, names, from, to) {
22556
22991
  for (const name of names) {
22557
22992
  for (const hit of region.matchAll(
22558
22993
  new RegExp(
22559
- `\\b(?:const|let|var)\\s+([A-Za-z_$][\\w$]*)\\s*(?::[^=]+)?=\\s*${esc4(name)}\\s*(?:;|$)`,
22994
+ `\\b(?:const|let|var)\\s+([A-Za-z_$][\\w$]*)\\s*(?::[^=]+)?=\\s*${esc6(name)}\\s*(?:;|$)`,
22560
22995
  "gm"
22561
22996
  )
22562
22997
  )) {
@@ -22569,7 +23004,7 @@ function narrowingsOver(m, names, from, to) {
22569
23004
  const out = [];
22570
23005
  const region = m.slice(from, to);
22571
23006
  for (const name of names) {
22572
- const n = esc4(name);
23007
+ const n = esc6(name);
22573
23008
  for (const hit of region.matchAll(/\bscopeFilter(List|Get)\s*\(/g)) {
22574
23009
  const open = from + (hit.index ?? 0) + hit[0].length - 1;
22575
23010
  const close = matchClose3(m, open);
@@ -22616,8 +23051,8 @@ function scanS35(tree) {
22616
23051
  const m = masked2(file);
22617
23052
  const raw = file.lines.map((l) => l.raw).join("\n");
22618
23053
  for (const hit of m.matchAll(CALL_RE3)) {
22619
- if (!/convex|client/i.test(hit[1])) continue;
22620
23054
  const start = hit.index ?? 0;
23055
+ const rcv = backendReceiver(m, hit[1], start);
22621
23056
  const open = start + hit[0].length - 1;
22622
23057
  const close = matchClose3(m, open);
22623
23058
  if (close < 0) continue;
@@ -22629,6 +23064,15 @@ function scanS35(tree) {
22629
23064
  const lit = new RegExp(String.raw`^\s*["'\x60]([\w/]+:[\w]+)["'\x60]${cast}`).exec(first);
22630
23065
  const ref = new RegExp(String.raw`^\s*(?:api|internal)\.([\w]+)\.([\w]+)${cast}`).exec(first);
22631
23066
  const door = lit ? lit[1] : ref ? `${ref[1]}:${ref[2]}` : void 0;
23067
+ if (rcv.kind === "unresolved") {
23068
+ if (door !== void 0 || importsConvex(m, raw))
23069
+ res.cnj.push({
23070
+ anchor,
23071
+ note: `${anchor}: the receiver is not resolved to a backend client \u2014 ${rcv.why}`
23072
+ });
23073
+ else res.calls--;
23074
+ continue;
23075
+ }
22632
23076
  if (door === void 0) {
22633
23077
  res.cnj.push({
22634
23078
  anchor,
@@ -24956,13 +25400,265 @@ var s41LakeReader = {
24956
25400
  }
24957
25401
  };
24958
25402
 
25403
+ // src/detectors/s42-write-read-claims.ts
25404
+ import { readFileSync as readFileSync17 } from "fs";
25405
+ import { relative as relative14 } from "path";
25406
+ var ID3 = "S42 write-read-claims";
25407
+ var RULE3 = "S-42";
25408
+ var CLAIMS = ["verifiedOrg", "verifiedPerson", "verifiedActor", "seatOrgSlug"];
25409
+ var KEY_RE = new RegExp(`\\b(${CLAIMS.join("|")})\\s*\\??\\s*:`, "g");
25410
+ var CALL_RE4 = /\b([A-Za-z_$][\w$]*)\s*\.\s*(query|mutation|action)\s*\(/g;
25411
+ var ACTOR_SET_RE2 = /\bconst\s+(VERIFIED_\w*DOORS)\b[^=]*=\s*new\s+Set\s*(?:<[^>]*>)?\s*\(\s*\[([\s\S]*?)\]\s*\)/;
25412
+ function definitionText(name, files) {
25413
+ const esc7 = name.replace(/\$/g, "\\$");
25414
+ const re = new RegExp(`(?:\\b(?:const|let|var)\\s+${esc7}\\b[^=]*=|\\bfunction\\s+${esc7}\\b)`);
25415
+ for (const { m } of files) {
25416
+ const hit = re.exec(m);
25417
+ if (!hit) continue;
25418
+ let i = hit.index + hit[0].length;
25419
+ let depth = 0;
25420
+ for (; i < m.length; i++) {
25421
+ const c = m[i];
25422
+ if (c === "(" || c === "{" || c === "[") depth++;
25423
+ else if (c === ")" || c === "}" || c === "]") depth--;
25424
+ else if ((c === ";" || c === "\n") && depth <= 0 && i > hit.index + hit[0].length + 2) {
25425
+ if (c === ";" || /^\s*(?:const|let|var|function|export|\/\/|$)/.test(m.slice(i + 1, i + 40)))
25426
+ break;
25427
+ }
25428
+ if (depth < 0) break;
25429
+ }
25430
+ return m.slice(hit.index, i);
25431
+ }
25432
+ return void 0;
25433
+ }
25434
+ function helperClaims(name, files, seen = /* @__PURE__ */ new Set(), depth = 0) {
25435
+ if (seen.has(name) || depth > 3) return void 0;
25436
+ seen.add(name);
25437
+ const def = definitionText(name, files);
25438
+ if (def === void 0) return void 0;
25439
+ const keys = new Set([...def.matchAll(KEY_RE)].map((k) => k[1]));
25440
+ if (keys.size > 0) return keys;
25441
+ for (const r of def.matchAll(/(?:\breturn\s+|[:?]\s*|=>\s*)([A-Za-z_$][\w$]*)\s*\(/g)) {
25442
+ const sub = helperClaims(r[1], files, seen, depth + 1);
25443
+ if (sub && sub.size > 0) return sub;
25444
+ }
25445
+ return /\{\s*\}/.test(def) ? /* @__PURE__ */ new Set() : void 0;
25446
+ }
25447
+ function readDoorAccess(backendRoot, unread2) {
25448
+ const out = /* @__PURE__ */ new Map();
25449
+ for (const path of listTs(backendRoot, unread2)) {
25450
+ let text;
25451
+ try {
25452
+ text = readFileSync17(path, "utf8");
25453
+ } catch (err) {
25454
+ unread2.push(`${path} could not be read (${fsErrorCode(err)})`);
25455
+ continue;
25456
+ }
25457
+ const file = {
25458
+ path,
25459
+ rel: relative14(backendRoot, path),
25460
+ lines: text.split("\n").map((raw, i) => ({ n: i + 1, raw, comment: false }))
25461
+ };
25462
+ const m = masked(file);
25463
+ const module = relative14(backendRoot, path).replace(/\.ts$/, "").split("\\").join("/");
25464
+ const re = /\bexport\s+const\s+([A-Za-z_$][\w$]*)\s*=\s*(query|mutation|action|internalMutation|internalQuery)\s*\(/g;
25465
+ for (let hit = re.exec(m); hit; hit = re.exec(m)) {
25466
+ const open = hit.index + hit[0].length - 1;
25467
+ const close = matchClose2(m, open);
25468
+ if (close < 0) continue;
25469
+ const raw = text.slice(hit.index, close + 1);
25470
+ const argTables = /* @__PURE__ */ new Map();
25471
+ for (const a of raw.matchAll(/\b(\w+)\s*:\s*v\s*\.\s*id\s*\(\s*["'`](\w+)["'`]/g))
25472
+ argTables.set(a[1], a[2]);
25473
+ const acc = { writes: /* @__PURE__ */ new Set(), reads: /* @__PURE__ */ new Set() };
25474
+ const fnBodyRaw = (name) => {
25475
+ const r2 = new RegExp(
25476
+ `(?:\\bfunction\\s+${name}\\s*\\(|\\b(?:const|let)\\s+${name}\\s*=\\s*(?:async\\s*)?\\()`
25477
+ );
25478
+ const h2 = r2.exec(m);
25479
+ if (!h2) return void 0;
25480
+ const paren = h2.index + h2[0].length - 1;
25481
+ const pclose = matchClose2(m, paren);
25482
+ if (pclose < 0) return void 0;
25483
+ const o = m.indexOf("{", pclose);
25484
+ const c = o < 0 ? -1 : matchClose2(m, o);
25485
+ return c < 0 ? void 0 : text.slice(o, c + 1);
25486
+ };
25487
+ const walk3 = (body, seen, depth) => {
25488
+ for (const h of body.matchAll(/\bdb\s*\.\s*insert\s*\(\s*["'`](\w+)["'`]/g))
25489
+ acc.writes.add(h[1]);
25490
+ for (const h of body.matchAll(/\bdb\s*\.\s*query\s*\(\s*["'`](\w+)["'`]/g))
25491
+ acc.reads.add(h[1]);
25492
+ for (const h of body.matchAll(/\bdb\s*\.\s*get\s*\(\s*args\s*\.\s*(\w+)/g)) {
25493
+ const t = argTables.get(h[1]);
25494
+ if (t) acc.reads.add(t);
25495
+ }
25496
+ if (depth >= 3) return;
25497
+ for (const c of body.matchAll(/\b([A-Za-z_$][\w$]*)\s*\(/g)) {
25498
+ if (seen.has(c[1])) continue;
25499
+ seen.add(c[1]);
25500
+ const sub = fnBodyRaw(c[1]);
25501
+ if (sub) walk3(sub, seen, depth + 1);
25502
+ }
25503
+ };
25504
+ walk3(raw, /* @__PURE__ */ new Set([hit[1]]), 0);
25505
+ out.set(`${module}:${hit[1]}`, acc);
25506
+ }
25507
+ }
25508
+ return out;
25509
+ }
25510
+ function scanS42(tree) {
25511
+ const unread2 = [];
25512
+ const files = tree.files.map((f) => ({ f, text: rawText(f), m: masked(f) }));
25513
+ const actorDoors = /* @__PURE__ */ new Set();
25514
+ for (const { text } of files) {
25515
+ const hit = ACTOR_SET_RE2.exec(text);
25516
+ if (hit) for (const s of hit[2].matchAll(/["'`]([\w/]+:[\w]+)["'`]/g)) actorDoors.add(s[1]);
25517
+ }
25518
+ const calls = [];
25519
+ for (const { f, text, m } of files) {
25520
+ for (let hit = CALL_RE4.exec(m); hit; hit = CALL_RE4.exec(m)) {
25521
+ const rcv = backendReceiver(m, hit[1], hit.index);
25522
+ const open = hit.index + hit[0].length - 1;
25523
+ const close = matchClose2(m, open);
25524
+ if (close < 0) continue;
25525
+ const at = `${f.rel}:${lineAt2(text, hit.index)}`;
25526
+ const tool = toolNameBefore(text, hit.index).name ?? "(unnamed tool)";
25527
+ const parts = splitTop2(m, open + 1, close);
25528
+ const first = parts[0] ? text.slice(parts[0][0], parts[0][1]) : "";
25529
+ const lit = /^\s*["'`]([\w/]+:[\w]+)["'`]/.exec(first);
25530
+ const ref = /^\s*(?:api|internal)\.([\w]+)\.([\w]+)/.exec(first);
25531
+ const door = lit ? lit[1] : ref ? `${ref[1]}:${ref[2]}` : void 0;
25532
+ if (rcv.kind === "unresolved") {
25533
+ if (door !== void 0 || importsConvex(m, text))
25534
+ unread2.push({
25535
+ anchor: at,
25536
+ reason: `${tool}: the receiver is not resolved to a backend client \u2014 ${rcv.why} (${RULE3})`
25537
+ });
25538
+ continue;
25539
+ }
25540
+ if (door === void 0) {
25541
+ unread2.push({
25542
+ anchor: at,
25543
+ reason: `${tool}: a backend door named by an expression (${RULE3})`
25544
+ });
25545
+ continue;
25546
+ }
25547
+ const argMasked = parts[1] ? m.slice(parts[1][0], parts[1][1]) : "";
25548
+ const argRaw = parts[1] ? text.slice(parts[1][0], parts[1][1]) : "";
25549
+ const claims = new Set([...argMasked.matchAll(KEY_RE)].map((k) => k[1]));
25550
+ let keyed = false;
25551
+ let unresolved;
25552
+ for (const sp of argRaw.matchAll(
25553
+ /\.\.\.\s*([A-Za-z_$][\w$]*)\s*\(\s*(["'`]([\w/]+:[\w]+)["'`])?/g
25554
+ )) {
25555
+ if (sp[3] === door) {
25556
+ keyed = true;
25557
+ continue;
25558
+ }
25559
+ const h = helperClaims(sp[1], files);
25560
+ if (h === void 0) {
25561
+ unresolved = sp[1];
25562
+ continue;
25563
+ }
25564
+ for (const c of h) claims.add(c);
25565
+ }
25566
+ if (unresolved !== void 0) {
25567
+ unread2.push({
25568
+ anchor: at,
25569
+ reason: `${tool}: the claims spread by ${unresolved}(...) cannot be resolved (no definition with readable claim keys in the tree) (${RULE3})`
25570
+ });
25571
+ continue;
25572
+ }
25573
+ calls.push({ tool, door, at, claims, keyed });
25574
+ }
25575
+ }
25576
+ const backendRoot = tree.backendRoot ?? discoverBackend(tree.root);
25577
+ if (calls.length > 0 && !backendRoot)
25578
+ unread2.push({
25579
+ anchor: tree.root,
25580
+ reason: `no backend source found above the scanned tree, so no door's table can be read (${RULE3})`
25581
+ });
25582
+ const fsUnread = [];
25583
+ const access = backendRoot ? readDoorAccess(backendRoot, fsUnread) : /* @__PURE__ */ new Map();
25584
+ for (const u of fsUnread)
25585
+ unread2.push({ anchor: backendRoot ?? tree.root, reason: `${u} (${RULE3})` });
25586
+ return { calls, unread: unread2, backend: backendRoot, access };
25587
+ }
25588
+ function runStatic3(tree) {
25589
+ const { calls, unread: unread2, access } = scanS42(tree);
25590
+ if (calls.length === 0 && unread2.length === 0)
25591
+ return {
25592
+ id: ID3,
25593
+ anchor: tree.root,
25594
+ state: "absent",
25595
+ verdict: `no backend door call in the tree \u2014 ${RULE3} n/a`
25596
+ };
25597
+ const writesOf = /* @__PURE__ */ new Map();
25598
+ const readsOf = /* @__PURE__ */ new Map();
25599
+ for (const c of calls) {
25600
+ const a = access.get(c.door);
25601
+ if (!a) {
25602
+ if (c.claims.size > 0 || c.keyed)
25603
+ unread2.push({
25604
+ anchor: c.at,
25605
+ reason: `${c.tool}: door ${c.door} is not defined in the backend read (${RULE3})`
25606
+ });
25607
+ continue;
25608
+ }
25609
+ for (const t of a.writes) writesOf.set(t, [...writesOf.get(t) ?? [], c]);
25610
+ for (const t of a.reads) readsOf.set(t, [...readsOf.get(t) ?? [], c]);
25611
+ }
25612
+ const red = [];
25613
+ const keyedTables = [];
25614
+ let compared = 0;
25615
+ for (const [table, writers] of writesOf) {
25616
+ const readers = readsOf.get(table) ?? [];
25617
+ if (readers.length === 0) continue;
25618
+ compared++;
25619
+ if ([...writers, ...readers].every((c) => c.keyed)) {
25620
+ keyedTables.push(table);
25621
+ continue;
25622
+ }
25623
+ for (const w of writers) {
25624
+ if (w.keyed) continue;
25625
+ for (const r of readers) {
25626
+ if (r.keyed) continue;
25627
+ const missing = [...r.claims].filter((c) => !w.claims.has(c));
25628
+ if (missing.length > 0)
25629
+ red.push(
25630
+ `${w.tool} (${w.door}, ${w.at}) writes ${table} without ${missing.join(", ")}, which ${r.tool} (${r.door}) forwards to read it`
25631
+ );
25632
+ }
25633
+ }
25634
+ }
25635
+ const decided = red.length > 0 ? {
25636
+ id: ID3,
25637
+ anchor: red[0].slice(red[0].indexOf("(") + 1).split(", ")[1]?.replace(")", "") ?? tree.root,
25638
+ state: "non-conforming",
25639
+ verdict: `${red.length} write/read claim mismatch(es): a row written without a claim its reads forward is stored where those reads cannot return it (${RULE3}): ${red.join("; ")}.`
25640
+ } : {
25641
+ id: ID3,
25642
+ anchor: tree.root,
25643
+ state: "present",
25644
+ verdict: `${compared} table(s) with both a write and a read tool compared: every write forwards the claims its reads forward${keyedTables.length > 0 ? `; resolved by one helper keyed by the door on ${keyedTables.join(", ")}` : ""} (${RULE3}).`
25645
+ };
25646
+ return settle(ID3, decided, unread2);
25647
+ }
25648
+ var s42WriteReadClaims = {
25649
+ id: ID3,
25650
+ rule: RULE3,
25651
+ pin: STANDARD_PIN,
25652
+ run: runStatic3
25653
+ };
25654
+
24959
25655
  // src/detectors/s44-closed-output.ts
24960
- var ID2 = "S44 closed-output";
24961
- var RULE2 = "S-44";
25656
+ var ID4 = "S44 closed-output";
25657
+ var RULE4 = "S-44";
24962
25658
  function judge(sites, j) {
24963
25659
  for (const s of sites) {
24964
25660
  if (s.kind === "unread")
24965
- j.unread.push({ anchor: s.anchor, reason: `${s.path}: ${s.form} (${RULE2})` });
25661
+ j.unread.push({ anchor: s.anchor, reason: `${s.path}: ${s.form} (${RULE4})` });
24966
25662
  else if (s.exempt) j.exempt.push(s);
24967
25663
  else j.violations.push(s);
24968
25664
  }
@@ -24971,23 +25667,23 @@ function verdictOf2(j, scope, anchorFallback) {
24971
25667
  const ex = j.exempt.length > 0 ? ` Exempted (${j.exempt.length}): ${j.exempt.map((e) => `${e.path} (${e.anchor}) \u2014 "${e.exempt}"`).join("; ")}.` : "";
24972
25668
  if (j.withOutput === 0 && j.unread.length === 0)
24973
25669
  return {
24974
- id: ID2,
25670
+ id: ID4,
24975
25671
  anchor: anchorFallback,
24976
25672
  state: "absent",
24977
- verdict: `${j.toolCount} tool(s) read (${scope}), none declares an output schema \u2014 ${RULE2} n/a`
25673
+ verdict: `${j.toolCount} tool(s) read (${scope}), none declares an output schema \u2014 ${RULE4} n/a`
24978
25674
  };
24979
25675
  const decided = j.violations.length > 0 ? {
24980
- id: ID2,
25676
+ id: ID4,
24981
25677
  anchor: j.violations[0].anchor,
24982
25678
  state: "non-conforming",
24983
- verdict: `${j.violations.length} closed object(s) in the output schemas of ${j.withOutput} tool(s): each refuses a field added later, which breaks every client connected before the release (${RULE2}): ${j.violations.map((v) => `${v.path} (${v.form}, ${v.anchor})`).join(", ")}.${ex}`
25679
+ verdict: `${j.violations.length} closed object(s) in the output schemas of ${j.withOutput} tool(s): each refuses a field added later, which breaks every client connected before the release (${RULE4}): ${j.violations.map((v) => `${v.path} (${v.form}, ${v.anchor})`).join(", ")}.${ex}`
24984
25680
  } : {
24985
- id: ID2,
25681
+ id: ID4,
24986
25682
  anchor: anchorFallback,
24987
25683
  state: "present",
24988
- verdict: `${j.withOutput} output schema(s) read (${scope}): no object refuses an added field (${RULE2}).${ex}`
25684
+ verdict: `${j.withOutput} output schema(s) read (${scope}): no object refuses an added field (${RULE4}).${ex}`
24989
25685
  };
24990
- return settle(ID2, decided, j.unread);
25686
+ return settle(ID4, decided, j.unread);
24991
25687
  }
24992
25688
  function s44Controls() {
24993
25689
  const red = closedServedSites(
@@ -25005,7 +25701,7 @@ function s44Controls() {
25005
25701
  spares: green.length === 0
25006
25702
  };
25007
25703
  }
25008
- function runStatic2(tree) {
25704
+ function runStatic4(tree) {
25009
25705
  const controls = s44Controls();
25010
25706
  if (!controls.sees || !controls.spares)
25011
25707
  throw new Error(
@@ -25017,18 +25713,18 @@ function runStatic2(tree) {
25017
25713
  if (tools.length === 0) {
25018
25714
  const surface = toolSurfaceAnchor(tree);
25019
25715
  if (surface || unresolved.length > 0) {
25020
- const reason = noToolsLocatedReason(tree, `no output schema could be read (${RULE2})`);
25716
+ const reason = noToolsLocatedReason(tree, `no output schema could be read (${RULE4})`);
25021
25717
  return couldNotJudge(
25022
- ID2,
25718
+ ID4,
25023
25719
  surface ?? unresolved[0],
25024
25720
  unresolved.length > 0 ? `${reason}; unresolved registration site(s): ${unresolved.join(", ")}` : reason
25025
25721
  );
25026
25722
  }
25027
25723
  return {
25028
- id: ID2,
25724
+ id: ID4,
25029
25725
  anchor: tree.root,
25030
25726
  state: "absent",
25031
- verdict: `no MCP tool registered in product source \u2014 ${RULE2} n/a`
25727
+ verdict: `no MCP tool registered in product source \u2014 ${RULE4} n/a`
25032
25728
  };
25033
25729
  }
25034
25730
  const j = {
@@ -25041,7 +25737,7 @@ function runStatic2(tree) {
25041
25737
  for (const a of unresolved)
25042
25738
  j.unread.push({
25043
25739
  anchor: a,
25044
- reason: `a tool registered here has a name the scan cannot resolve, so its output schema is unread (${RULE2})`
25740
+ reason: `a tool registered here has a name the scan cannot resolve, so its output schema is unread (${RULE4})`
25045
25741
  });
25046
25742
  for (const tool of tools) {
25047
25743
  const read = closedOutputSites(tree, tool.name, tool.anchor);
@@ -25055,9 +25751,9 @@ function runServedHalf2(runtime) {
25055
25751
  const anchor = `${runtime.root} (served)`;
25056
25752
  if (runtime.launchError)
25057
25753
  return couldNotJudge(
25058
- ID2,
25754
+ ID4,
25059
25755
  anchor,
25060
- `the server could not be started/introspected, so no served outputSchema was read: ${runtime.launchError} (${RULE2})`
25756
+ `the server could not be started/introspected, so no served outputSchema was read: ${runtime.launchError} (${RULE4})`
25061
25757
  );
25062
25758
  const j = {
25063
25759
  violations: [],
@@ -25074,10 +25770,10 @@ function runServedHalf2(runtime) {
25074
25770
  return verdictOf2(j, "served tools/list outputSchema", anchor);
25075
25771
  }
25076
25772
  var s44ClosedOutput = {
25077
- id: ID2,
25078
- rule: RULE2,
25773
+ id: ID4,
25774
+ rule: RULE4,
25079
25775
  pin: STANDARD_PIN,
25080
- run: runStatic2,
25776
+ run: runStatic4,
25081
25777
  runServed: (runtime) => runServedHalf2(runtime)
25082
25778
  };
25083
25779
 
@@ -25115,6 +25811,7 @@ var registered = [
25115
25811
  c25BuildIdentity,
25116
25812
  c26SubpackageLockfile,
25117
25813
  c31PluginInstallable,
25814
+ c36ReadmeNpmLimit,
25118
25815
  s5AuthzElements,
25119
25816
  s29EventsDeclared,
25120
25817
  s30EventDescriptors,
@@ -25186,6 +25883,7 @@ var registered = [
25186
25883
  s39UpstreamError,
25187
25884
  s40UpstreamRowsNarrowed,
25188
25885
  s41LakeReader,
25886
+ s42WriteReadClaims,
25189
25887
  s43UnionInput,
25190
25888
  s44ClosedOutput,
25191
25889
  e5ExtensionIsolation,
@@ -25221,6 +25919,7 @@ var READS_CODE = /* @__PURE__ */ new Set([
25221
25919
  "S-39",
25222
25920
  "S-40",
25223
25921
  "S-41",
25922
+ "S-42",
25224
25923
  "S-43",
25225
25924
  "S-44",
25226
25925
  "E-5",
@@ -25232,8 +25931,8 @@ var detectors = registered.map(
25232
25931
 
25233
25932
  // src/runtime/launch.ts
25234
25933
  import { spawnSync as spawnSync2 } from "child_process";
25235
- import { existsSync as existsSync23, readFileSync as readFileSync16, statSync as statSync21 } from "fs";
25236
- import { dirname as dirname17, isAbsolute, join as join28, resolve as resolve3 } from "path";
25934
+ import { existsSync as existsSync23, readFileSync as readFileSync18, statSync as statSync21 } from "fs";
25935
+ import { dirname as dirname17, isAbsolute, join as join29, resolve as resolve3 } from "path";
25237
25936
  function findPackageDir(target) {
25238
25937
  let dir;
25239
25938
  try {
@@ -25242,7 +25941,7 @@ function findPackageDir(target) {
25242
25941
  return null;
25243
25942
  }
25244
25943
  for (let depth = 0; depth < 8; depth++) {
25245
- if (existsSync23(join28(dir, "package.json"))) return dir;
25944
+ if (existsSync23(join29(dir, "package.json"))) return dir;
25246
25945
  const parent = dirname17(dir);
25247
25946
  if (parent === dir) break;
25248
25947
  dir = parent;
@@ -25267,13 +25966,13 @@ function deriveLaunchPlan(target) {
25267
25966
  }
25268
25967
  let pkg;
25269
25968
  try {
25270
- if (!statSync21(join28(pkgDir, "package.json")).isFile()) {
25271
- return { error: `${join28(pkgDir, "package.json")} is not a regular file \u2014 not read` };
25969
+ if (!statSync21(join29(pkgDir, "package.json")).isFile()) {
25970
+ return { error: `${join29(pkgDir, "package.json")} is not a regular file \u2014 not read` };
25272
25971
  }
25273
- pkg = JSON.parse(readFileSync16(join28(pkgDir, "package.json"), "utf8"));
25972
+ pkg = JSON.parse(readFileSync18(join29(pkgDir, "package.json"), "utf8"));
25274
25973
  } catch (err) {
25275
25974
  return {
25276
- error: `could not parse ${join28(pkgDir, "package.json")}: ${err instanceof Error ? err.message : String(err)}`
25975
+ error: `could not parse ${join29(pkgDir, "package.json")}: ${err instanceof Error ? err.message : String(err)}`
25277
25976
  };
25278
25977
  }
25279
25978
  const bin = firstBinEntry(pkg.bin);
@@ -25721,14 +26420,14 @@ function readEvalCounts(target) {
25721
26420
  if (!pkgDir) return { counts };
25722
26421
  let dir = pkgDir;
25723
26422
  for (let depth = 0; depth < 8; depth++) {
25724
- const candidate = join28(dir, "evals", "evals.json");
26423
+ const candidate = join29(dir, "evals", "evals.json");
25725
26424
  if (existsSync23(candidate)) {
25726
26425
  let text;
25727
26426
  try {
25728
26427
  if (!statSync21(candidate).isFile()) {
25729
26428
  return { counts, unreadable: `${candidate} is not a regular file \u2014 not read` };
25730
26429
  }
25731
- text = readFileSync16(candidate, "utf8");
26430
+ text = readFileSync18(candidate, "utf8");
25732
26431
  } catch (err) {
25733
26432
  return {
25734
26433
  counts,
@@ -26359,7 +27058,7 @@ var USAGE = [
26359
27058
  function readVersion() {
26360
27059
  try {
26361
27060
  const here = dirname18(fileURLToPath2(import.meta.url));
26362
- const manifest = JSON.parse(readFileSync17(join29(here, "..", "package.json"), "utf8"));
27061
+ const manifest = JSON.parse(readFileSync19(join30(here, "..", "package.json"), "utf8"));
26363
27062
  return manifest.version ?? null;
26364
27063
  } catch {
26365
27064
  return null;