veoflow 0.5.7 → 0.6.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/veo.mjs CHANGED
@@ -504,6 +504,8 @@ var init_classify = __esm({
504
504
  "tsx",
505
505
  "vue",
506
506
  "svelte",
507
+ // Python (#415, R3).
508
+ "python",
507
509
  "angular-template"
508
510
  ]);
509
511
  UNSUPPORTED = {
@@ -1246,7 +1248,7 @@ function unreadNotice(files) {
1246
1248
  const parts = [...by].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1)).map(([name, n2]) => `${n2.toLocaleString("en-US")} ${name} ${n2 === 1 ? "file" : "files"}`);
1247
1249
  const list = parts.length === 1 ? parts[0] : `${parts.slice(0, -1).join(", ")} and ${parts[parts.length - 1]}`;
1248
1250
  const total = [...by.values()].reduce((a, b) => a + b, 0);
1249
- return `${list} ${total === 1 ? "is" : "are"} listed but not analyzed yet: veoflow analyzes JavaScript and TypeScript (with Vue, Svelte and Angular components) today.`;
1251
+ return `${list} ${total === 1 ? "is" : "are"} listed but not analyzed yet: veoflow analyzes JavaScript and TypeScript (with Vue, Svelte and Angular components) and Python today.`;
1250
1252
  }
1251
1253
  function ignoredSourceFolders(root, unpinned) {
1252
1254
  const out = [];
@@ -1869,7 +1871,7 @@ var init_plan = __esm({
1869
1871
  };
1870
1872
  DEFAULT_MAX_FILE_BYTES = 10 * 1024 * 1024;
1871
1873
  HARD_MAX_FILE_BYTES = 64 * 1024 * 1024;
1872
- RESOLVER_MANIFEST = /(^|\/)(package\.json|project\.json|nx\.json|(ts|js)config[^/]*\.json|package-lock\.json|pnpm-lock\.yaml|pnpm-workspace\.yaml|yarn\.lock|\.npmrc|\.yarnrc\.yml)$/;
1874
+ RESOLVER_MANIFEST = /(^|\/)(package\.json|project\.json|nx\.json|pyproject\.toml|setup\.cfg|requirements[^/]*\.txt|uv\.lock|poetry\.lock|(ts|js)config[^/]*\.json|package-lock\.json|pnpm-lock\.yaml|pnpm-workspace\.yaml|yarn\.lock|\.npmrc|\.yarnrc\.yml)$/;
1873
1875
  RESOLVER_INPUT = /\.(json|jsonc|lock|ya?ml|toml|mod|sum)$|(^|\/)(\.npmrc|\.nvmrc|\.babelrc)$/i;
1874
1876
  MINIFIED_MIN_BYTES = 2e4;
1875
1877
  count = (n2, noun) => `${n2.toLocaleString("en-US")} ${noun}${n2 === 1 ? "" : "s"}`;
@@ -3791,6 +3793,7 @@ var init_src2 = __esm({
3791
3793
  // packages/extract-client/src/index.ts
3792
3794
  var src_exports = {};
3793
3795
  __export(src_exports, {
3796
+ SUPPORTED: () => SUPPORTED,
3794
3797
  acceptsTestLicenses: () => acceptsTestLicenses,
3795
3798
  adapterVersion: () => adapterVersion,
3796
3799
  cacheSize: () => cacheSize,
@@ -3798,6 +3801,9 @@ __export(src_exports, {
3798
3801
  extract: () => extract,
3799
3802
  isAvailable: () => isAvailable,
3800
3803
  languageForPath: () => languageForPath,
3804
+ phaseTimings: () => phaseTimings,
3805
+ platformName: () => platformName,
3806
+ resetPhaseTimings: () => resetPhaseTimings,
3801
3807
  resolve: () => resolve3,
3802
3808
  runQueries: () => runQueries,
3803
3809
  verifyLicense: () => verifyLicense
@@ -3813,12 +3819,17 @@ function native() {
3813
3819
  return binding;
3814
3820
  } catch (e) {
3815
3821
  loadError = new Error(
3816
- "The veo-extract native module is not built for this platform. Run: pnpm --filter @veo/extract-client build:native",
3822
+ process.env.VEO_NATIVE_DIR ? `veoflow has no prebuilt engine for ${platformName()}. ${SUPPORTED}` : `The veo-extract native module is not built for ${platformName()}. Run: pnpm --filter @veo/extract-client build:native`,
3817
3823
  { cause: e }
3818
3824
  );
3819
3825
  throw loadError;
3820
3826
  }
3821
3827
  }
3828
+ function platformName() {
3829
+ const report = process.report?.getReport();
3830
+ const musl = process.platform === "linux" && !report?.header?.glibcVersionRuntime;
3831
+ return `${process.platform}-${process.arch}${musl ? " (musl)" : ""}`;
3832
+ }
3822
3833
  function isAvailable() {
3823
3834
  try {
3824
3835
  native();
@@ -3857,10 +3868,17 @@ function languageForPath(path) {
3857
3868
  const ext = path.slice(path.lastIndexOf(".") + 1).toLowerCase();
3858
3869
  return LANGUAGES[ext];
3859
3870
  }
3860
- var binding, loadError, LANGUAGES;
3871
+ function phaseTimings() {
3872
+ return JSON.parse(native().phaseTimings());
3873
+ }
3874
+ function resetPhaseTimings() {
3875
+ native().resetPhaseTimings();
3876
+ }
3877
+ var binding, loadError, SUPPORTED, LANGUAGES;
3861
3878
  var init_src3 = __esm({
3862
3879
  "packages/extract-client/src/index.ts"() {
3863
3880
  "use strict";
3881
+ SUPPORTED = "It runs on macOS (Apple silicon and Intel), Linux with glibc (x64 and arm64) and Windows (x64), with Node.js 22.13 or newer.";
3864
3882
  LANGUAGES = {
3865
3883
  js: "javascript",
3866
3884
  mjs: "javascript",
@@ -3871,7 +3889,8 @@ var init_src3 = __esm({
3871
3889
  cts: "typescript",
3872
3890
  tsx: "tsx",
3873
3891
  vue: "vue",
3874
- svelte: "svelte"
3892
+ svelte: "svelte",
3893
+ py: "python"
3875
3894
  };
3876
3895
  }
3877
3896
  });
@@ -4893,7 +4912,7 @@ var init_stage1 = __esm({
4893
4912
  byOffset = (a, b) => a.site.start.offset - b.site.start.offset || a.site.end.offset - b.site.end.offset;
4894
4913
  BATCH_BYTES2 = 32 << 20;
4895
4914
  BATCH_FILES = 200;
4896
- STAGE1_VERSION = 1;
4915
+ STAGE1_VERSION = 2;
4897
4916
  stage1 = {
4898
4917
  name: STAGE1,
4899
4918
  version: () => `${STAGE1_VERSION}+${adapterVersion()}`,
@@ -9766,14 +9785,14 @@ function resolveImports(engine, args, cwd) {
9766
9785
  evidence: u.evidence
9767
9786
  }))
9768
9787
  ].sort(byEvidence);
9769
- const statementKey = (id) => id.replace(/^(IMPORTS|unresolved-import)\|/, "");
9788
+ const statementKey2 = (id) => id.replace(/^(IMPORTS|unresolved-import)\|/, "");
9770
9789
  const namesOf = /* @__PURE__ */ new Map();
9771
9790
  for (const n2 of importedNames(reader, file2.id)) {
9772
9791
  const key = n2.id.replace(/^IMPORTS_SYMBOL\|/, "").replace(/\|[^|]*$/, "");
9773
9792
  namesOf.set(key, [...namesOf.get(key) ?? [], n2]);
9774
9793
  }
9775
9794
  for (const i of imports) {
9776
- const names = namesOf.get(statementKey(i.id));
9795
+ const names = namesOf.get(statementKey2(i.id));
9777
9796
  if (names) i.names = names;
9778
9797
  }
9779
9798
  const importers = reader.factsTo("IMPORTS", file2.id).sort(byEvidence);
@@ -11274,7 +11293,7 @@ async function loadCheckers() {
11274
11293
  } catch (e) {
11275
11294
  throw new VeoError(
11276
11295
  "checker-failed",
11277
- `the TypeScript reference checker isn't available here (${e.message}); reinstall veoflow with its dependencies`,
11296
+ `the reference checkers aren't available here (${e.message}); reinstall veoflow with its dependencies`,
11278
11297
  { reason: "unavailable" }
11279
11298
  );
11280
11299
  }
@@ -11295,13 +11314,17 @@ async function checkCode(engine, args, cwd = process.cwd()) {
11295
11314
  const scope2 = relative3(source.root, abs).split(sep6).join("/");
11296
11315
  const inScope = (path) => scope2 === "" || path === scope2 || path.startsWith(`${scope2}/`);
11297
11316
  const { reader } = engine.readAllStages({ project: projectId });
11298
- const analyzed = reader.facts("File").filter(
11299
- (f) => f.source === source.id && (f.status === "analyzed" || f.status === "degraded") && f.language !== null && CHECKED.has(f.language) && !f.path.endsWith(".d.ts")
11317
+ const checkable = (set2) => reader.facts("File").filter(
11318
+ (f) => f.source === source.id && (f.status === "analyzed" || f.status === "degraded") && f.language !== null && set2.has(f.language) && !f.path.endsWith(".d.ts")
11300
11319
  );
11320
+ const script = checkable(CHECKED);
11321
+ const pythonFiles = checkable(CHECKED_PYTHON);
11322
+ const python = pythonFiles.some((f) => inScope(f.path)) && !script.some((f) => inScope(f.path));
11323
+ const analyzed = python ? pythonFiles : script;
11301
11324
  if (!analyzed.some((f) => inScope(f.path)))
11302
11325
  throw new VeoError(
11303
11326
  "invalid-arguments",
11304
- `no analyzed JavaScript or TypeScript files under ${args.path} (the checker reads those; analyze the project first)`,
11327
+ `no analyzed JavaScript, TypeScript or Python files under ${args.path} (the checkers read those; analyze the project first)`,
11305
11328
  { fields: ["path"] }
11306
11329
  );
11307
11330
  const texts = /* @__PURE__ */ new Map();
@@ -11324,11 +11347,11 @@ async function checkCode(engine, args, cwd = process.cwd()) {
11324
11347
  const { extract: extract2 } = await Promise.resolve().then(() => (init_src3(), src_exports));
11325
11348
  let index;
11326
11349
  try {
11327
- index = checkers.indexFolder(source.root, { files: [...texts.keys()] });
11350
+ index = python ? checkers.indexPython(source.root, [...texts.keys()]) : checkers.indexFolder(source.root, { files: [...texts.keys()] });
11328
11351
  } catch (e) {
11329
11352
  throw new VeoError(
11330
11353
  "checker-failed",
11331
- `the TypeScript compiler couldn't index ${source.root}: ${e.message}`,
11354
+ `${python ? "scip-python" : "the TypeScript compiler"} couldn't index ${source.root}: ${e.message}`,
11332
11355
  {
11333
11356
  reason: "index"
11334
11357
  }
@@ -11342,7 +11365,7 @@ async function checkCode(engine, args, cwd = process.cwd()) {
11342
11365
  manifests: [],
11343
11366
  files
11344
11367
  }).files;
11345
- const { calls, candidates, references } = checkers.translate(index, texts);
11368
+ const { calls, candidates, references } = python ? { calls: checkers.translatePython(index, adapter, texts), candidates: [], references: 0 } : checkers.translate(index, texts);
11346
11369
  const report = checkers.compare(adapter, calls, references, candidates.length, inScope);
11347
11370
  const fileId = (path) => ids.file(source.id, path);
11348
11371
  const adapterFiles = new Map(adapter.map((f) => [f.path, f]));
@@ -11463,7 +11486,7 @@ async function checkCode(engine, args, cwd = process.cwd()) {
11463
11486
  source: source.id,
11464
11487
  root: source.root,
11465
11488
  path: scope2,
11466
- checker: "scip-typescript",
11489
+ checker: python ? "scip-python" : "scip-typescript",
11467
11490
  files: [...texts.keys()].filter(inScope).length,
11468
11491
  changed: [...changed].filter(inScope).sort(),
11469
11492
  stage2: stage22,
@@ -11487,7 +11510,7 @@ function stage2Answer(facts, at, stage22, reader) {
11487
11510
  if (r.importOutcome) return `open: ${reasonWords(r.importOutcome)}`;
11488
11511
  return `open: ${reasonWords(r.steps.at(-1)?.kind ?? "unresolved")}`;
11489
11512
  }
11490
- var CHECKED, DISAGREE;
11513
+ var CHECKED, CHECKED_PYTHON, DISAGREE;
11491
11514
  var init_check = __esm({
11492
11515
  "packages/query-imports/src/check.ts"() {
11493
11516
  "use strict";
@@ -11495,6 +11518,7 @@ var init_check = __esm({
11495
11518
  init_protocol();
11496
11519
  init_src2();
11497
11520
  CHECKED = /* @__PURE__ */ new Set(["typescript", "tsx", "javascript", "jsx"]);
11521
+ CHECKED_PYTHON = /* @__PURE__ */ new Set(["python"]);
11498
11522
  DISAGREE = /* @__PURE__ */ new Set(["different-callee", "adapter-only", "checker-only"]);
11499
11523
  }
11500
11524
  });
@@ -22533,6 +22557,1048 @@ var init_together = __esm({
22533
22557
  }
22534
22558
  });
22535
22559
 
22560
+ // packages/stage2/src/python.ts
22561
+ import { posix as posix10 } from "node:path";
22562
+ function pythonProject(plan, forPath) {
22563
+ const roots = /* @__PURE__ */ new Set();
22564
+ const dependencies = /* @__PURE__ */ new Set();
22565
+ const dep = (spec) => {
22566
+ if (/^\s*(git\+|hg\+|svn\+|bzr\+|https?:|file:|\.|\/)/.test(spec)) return;
22567
+ const name = /^\s*([A-Za-z0-9][A-Za-z0-9._-]*)/.exec(spec)?.[1];
22568
+ if (name) dependencies.add(normalize(name));
22569
+ };
22570
+ for (const m of plan.manifests) {
22571
+ const base2 = posix10.basename(m.path);
22572
+ const dir = posix10.dirname(m.path) === "." ? "" : posix10.dirname(m.path);
22573
+ if (forPath !== void 0 && dir && !forPath.startsWith(`${dir}/`)) continue;
22574
+ const at = (p) => posix10.normalize(posix10.join(dir, p)).replace(/^\.\/?$/, "").replace(/\/$/, "");
22575
+ if (base2 === "pyproject.toml") {
22576
+ roots.add(dir);
22577
+ let section = "";
22578
+ let inArray = null;
22579
+ const add2 = (kind, value) => {
22580
+ if (kind === "deps") for (const s of quoted(value)) dep(s);
22581
+ else if (kind === "roots") for (const s of quoted(value)) roots.add(at(s));
22582
+ else if (kind === "poetry")
22583
+ for (const from of value.matchAll(/from\s*=\s*["']([^"']+)["']/g)) roots.add(at(from[1]));
22584
+ else if (kind === "hatch") for (const s of quoted(value)) roots.add(at(posix10.dirname(s)));
22585
+ };
22586
+ for (const raw of m.content.split("\n")) {
22587
+ const line = raw.replace(/\s+#.*$/, "").trim();
22588
+ if (!line) continue;
22589
+ const header = /^\[\[?([^\]]+)\]\]?$/.exec(line);
22590
+ if (header) {
22591
+ section = header[1].trim();
22592
+ inArray = null;
22593
+ continue;
22594
+ }
22595
+ if (inArray) {
22596
+ add2(inArray, line);
22597
+ if (closes(line)) inArray = null;
22598
+ continue;
22599
+ }
22600
+ const kv = /^([A-Za-z0-9_.-]+|"[^"]*")\s*=\s*(.*)$/.exec(line);
22601
+ if (!kv) continue;
22602
+ const key = kv[1].replace(/"/g, "");
22603
+ const value = kv[2];
22604
+ const list = (kind) => {
22605
+ add2(kind, value);
22606
+ if (value.startsWith("[") && !closes(value)) inArray = kind;
22607
+ };
22608
+ if (section === "project" && key === "dependencies") list("deps");
22609
+ else if (section === "project.optional-dependencies" || section === "dependency-groups") list("deps");
22610
+ else if (section === "tool.setuptools.packages.find" && key === "where") list("roots");
22611
+ else if (section === "tool.setuptools.package-dir" && key === "")
22612
+ roots.add(at(quoted(value)[0] ?? ""));
22613
+ else if (/^tool\.poetry(\.group\.[^.]+)?\.(dev-)?dependencies$/.test(section) && key !== "python")
22614
+ dependencies.add(normalize(key));
22615
+ else if (section === "tool.poetry" && key === "packages") list("poetry");
22616
+ else if (section === "tool.hatch.build.targets.wheel" && key === "packages") list("hatch");
22617
+ }
22618
+ } else if (base2 === "setup.cfg") {
22619
+ roots.add(dir);
22620
+ let section = "";
22621
+ let key = "";
22622
+ for (const raw of m.content.split("\n")) {
22623
+ const header = /^\s*\[([^\]]+)\]/.exec(raw);
22624
+ if (header) {
22625
+ section = header[1].trim();
22626
+ key = "";
22627
+ continue;
22628
+ }
22629
+ const kv = /^([A-Za-z0-9_.-]+)\s*=\s*(.*)$/.exec(raw);
22630
+ if (kv) {
22631
+ key = kv[1];
22632
+ if (section === "options" && key === "install_requires") dep(kv[2]);
22633
+ if (section === "options.packages.find" && key === "where" && kv[2].trim())
22634
+ roots.add(at(kv[2].trim()));
22635
+ if (section === "options" && key === "package_dir") {
22636
+ const d = /=\s*(\S+)/.exec(kv[2])?.[1];
22637
+ if (d) roots.add(at(d));
22638
+ }
22639
+ } else if (/^\s+\S/.test(raw) && section === "options" && key === "install_requires") dep(raw.trim());
22640
+ else if (/^\s+=\s*\S/.test(raw) && section === "options" && key === "package_dir")
22641
+ roots.add(at(raw.replace(/^\s+=\s*/, "").trim()));
22642
+ }
22643
+ } else if (base2 === "uv.lock" || base2 === "poetry.lock") {
22644
+ let name = null;
22645
+ let own2 = false;
22646
+ let table = "other";
22647
+ const flush = () => {
22648
+ if (name && !own2) dependencies.add(normalize(name));
22649
+ name = null;
22650
+ own2 = false;
22651
+ };
22652
+ for (const raw of m.content.split("\n")) {
22653
+ const line = raw.trim();
22654
+ if (line === "[[package]]") {
22655
+ flush();
22656
+ table = "package";
22657
+ } else if (line.startsWith("[")) table = line === "[package.source]" ? "source" : "other";
22658
+ else if (table === "package" && name === null && /^name\s*=/.test(line))
22659
+ name = /"([^"]+)"/.exec(line)?.[1] ?? null;
22660
+ else if (table === "package" && /^source\s*=\s*\{\s*(editable|virtual|directory)\s*=/.test(line))
22661
+ own2 = true;
22662
+ else if (table === "source" && /^type\s*=\s*"directory"/.test(line)) own2 = true;
22663
+ }
22664
+ flush();
22665
+ } else if (/^requirements[^/]*\.txt$/.test(base2)) {
22666
+ for (const raw of m.content.split("\n")) {
22667
+ const line = raw.replace(/(^|\s)#.*$/, "").trim();
22668
+ if (line && !line.startsWith("-")) dep(line);
22669
+ }
22670
+ }
22671
+ }
22672
+ roots.add("");
22673
+ return { roots: [...roots].sort((a, b) => b.length - a.length || (a < b ? -1 : 1)), dependencies };
22674
+ }
22675
+ function distribution(top, dependencies) {
22676
+ const plain2 = (d) => d.replace(/-/g, "");
22677
+ const n2 = normalize(top.replace(/^_+/, ""));
22678
+ for (const name of [normalize(DISTRIBUTIONS[top] ?? top), n2, `python-${n2}`])
22679
+ if (dependencies.has(name)) return name;
22680
+ return [...dependencies].find((d) => plain2(d) === plain2(n2)) ?? null;
22681
+ }
22682
+ function distributionByPrefix(top, dependencies) {
22683
+ const n2 = normalize(top);
22684
+ const found = [...dependencies].filter((d) => d.startsWith(`${n2}-`) || d === `${n2}io`).sort((a, b) => a.length - b.length || (a < b ? -1 : 1));
22685
+ return found[0] ?? null;
22686
+ }
22687
+ function moduleIndex(paths) {
22688
+ const files = new Set(paths.filter(isPython));
22689
+ const dirs = /* @__PURE__ */ new Set();
22690
+ for (const p of files)
22691
+ for (let d = posix10.dirname(p); d !== "." && d !== ""; d = posix10.dirname(d)) dirs.add(d);
22692
+ return { files, dirs };
22693
+ }
22694
+ function moduleFile(index, path) {
22695
+ const init = path ? `${path}/__init__.py` : "__init__.py";
22696
+ if (index.files.has(init)) return init;
22697
+ if (path && index.files.has(`${path}.py`)) return `${path}.py`;
22698
+ if (path && index.files.has(`${path}.pyi`)) return `${path}.pyi`;
22699
+ return null;
22700
+ }
22701
+ function moduleVariables(text) {
22702
+ const vars = /* @__PURE__ */ new Map();
22703
+ const code = text.replace(/("""|''')[\s\S]*?\1/g, (m) => m.replace(/[^\n]/g, " "));
22704
+ const set2 = (name, cls) => vars.set(name, vars.has(name) ? "" : cls);
22705
+ let block = null;
22706
+ for (const line of code.split("\n")) {
22707
+ if (!line.trim() || line.trim().startsWith("#")) continue;
22708
+ const indent = /^\s*/.exec(line)[0].length;
22709
+ if (indent === 0) {
22710
+ block = /^(if|elif|else|try|except|finally|with|for|while)\b/.test(line) ? -1 : null;
22711
+ } else if (block === -1) block = indent;
22712
+ const top = indent === 0 || block !== null && block > 0 && indent === block;
22713
+ if (!top) continue;
22714
+ const chain = /^\s*((?:[A-Za-z_]\w*\s*=(?!=)\s*)+)(.*)$/.exec(line);
22715
+ const annotated = /^\s*([A-Za-z_]\w*)\s*:\s*([^=]+?)\s*=(?!=)\s*(.*)$/.exec(line);
22716
+ if (annotated) {
22717
+ const written2 = annotated[2].trim().replace(/^["']|["']$/g, "");
22718
+ set2(annotated[1], indent === 0 && /^[A-Za-z_][\w.]*$/.test(written2) ? written2 : "");
22719
+ } else if (chain) {
22720
+ const names = [...chain[1].matchAll(/([A-Za-z_]\w*)\s*=/g)].map((m) => m[1]);
22721
+ const made = /^([A-Za-z_][\w.]*)\s*\(/.exec(chain[2] ?? "")?.[1];
22722
+ const cls = indent === 0 && made && /^[A-Z]/.test(made.split(".").at(-1)) ? made : "";
22723
+ for (const n2 of names) set2(n2, cls);
22724
+ }
22725
+ }
22726
+ return vars;
22727
+ }
22728
+ function optionalImport(text, line) {
22729
+ const lines = text.split("\n");
22730
+ const indent = (s) => /^\s*/.exec(s)[0].length;
22731
+ let own2 = indent(lines[line - 1] ?? "");
22732
+ for (let i = line - 2; i >= 0 && own2 > 0; i--) {
22733
+ const l = lines[i];
22734
+ if (!l.trim() || l.trim().startsWith("#")) continue;
22735
+ if (indent(l) >= own2) continue;
22736
+ own2 = indent(l);
22737
+ if (/^\s*(def|class|async\s+def)\b/.test(l)) return false;
22738
+ if (!/^\s*try\s*:/.test(l)) continue;
22739
+ for (let j = i + 1; j < lines.length; j++) {
22740
+ const k = lines[j];
22741
+ if (!k.trim() || k.trim().startsWith("#")) continue;
22742
+ if (indent(k) < own2) break;
22743
+ if (indent(k) !== own2) continue;
22744
+ if (!/^\s*except\b/.test(k)) {
22745
+ if (/^\s*(else|finally)\s*:/.test(k)) continue;
22746
+ break;
22747
+ }
22748
+ if (/\b(ImportError|ModuleNotFoundError|Exception|BaseException)\b/.test(k) || /^\s*except\s*:/.test(k))
22749
+ return true;
22750
+ }
22751
+ }
22752
+ return false;
22753
+ }
22754
+ function pythonResults(plans) {
22755
+ const out = /* @__PURE__ */ new Map();
22756
+ for (const plan of plans) {
22757
+ const files = plan.files.filter((f) => f.language === "python" && f.content !== void 0 && !f.skip);
22758
+ if (!files.length) continue;
22759
+ const response = extract({
22760
+ protocolVersion: PROTOCOL_VERSION,
22761
+ root: plan.root,
22762
+ manifests: [],
22763
+ files: files.map((f) => ({ path: f.path, language: f.language, content: f.content }))
22764
+ });
22765
+ for (const r of response.files) out.set(`${plan.sourceId}\0${r.path}`, r);
22766
+ }
22767
+ return out;
22768
+ }
22769
+ function resolvePythonImports(plans, files, results) {
22770
+ const resolved = [];
22771
+ const submodules = /* @__PURE__ */ new Set();
22772
+ const folders = /* @__PURE__ */ new Map();
22773
+ const packagesOf = /* @__PURE__ */ new Map();
22774
+ const packages = /* @__PURE__ */ new Map();
22775
+ const external = (source, ecosystem, name) => {
22776
+ const id = ids.externalPackage(source, ecosystem, name);
22777
+ let pkg = packages.get(id);
22778
+ if (!pkg)
22779
+ packages.set(id, pkg = { type: "ExternalPackage", id, source, ecosystem, name, version: null });
22780
+ return pkg;
22781
+ };
22782
+ for (const plan of plans) {
22783
+ const source = plan.sourceId;
22784
+ const fileNodes = files.filter((f) => f.source === source);
22785
+ const byPath = new Map(fileNodes.map((f) => [f.path, f]));
22786
+ const index = moduleIndex(fileNodes.map((f) => f.path));
22787
+ const projects = /* @__PURE__ */ new Map();
22788
+ const manifestDirs = [
22789
+ ...new Set(plan.manifests.map((m) => posix10.dirname(m.path) === "." ? "" : posix10.dirname(m.path)))
22790
+ ];
22791
+ const projectFor = (path) => {
22792
+ const key = manifestDirs.filter((d) => !d || path.startsWith(`${d}/`)).join("\0");
22793
+ let p = projects.get(key);
22794
+ if (!p) projects.set(key, p = pythonProject(plan, path));
22795
+ return p;
22796
+ };
22797
+ let project2 = projectFor("");
22798
+ const text = new Map(plan.files.filter((f) => f.content !== void 0).map((f) => [f.path, f.content]));
22799
+ const pathIn = (root, dotted) => {
22800
+ const p = posix10.join(root, ...dotted.split("."));
22801
+ return p === "." ? "" : p;
22802
+ };
22803
+ const absoluteFile = (dotted) => {
22804
+ for (const root of project2.roots) {
22805
+ const file2 = moduleFile(index, pathIn(root, dotted));
22806
+ if (file2) return { file: file2, root };
22807
+ }
22808
+ return null;
22809
+ };
22810
+ const absoluteDir = (dotted) => {
22811
+ for (const root of project2.roots) {
22812
+ const dir = pathIn(root, dotted);
22813
+ if (dir && index.dirs.has(dir)) return { dir, root };
22814
+ }
22815
+ return null;
22816
+ };
22817
+ for (const f of fileNodes) {
22818
+ if (f.language !== "python" || f.status === "not_analyzed") continue;
22819
+ const result2 = results.get(`${source}\0${f.path}`);
22820
+ if (!result2) continue;
22821
+ const fileId = f.id;
22822
+ project2 = projectFor(f.path);
22823
+ for (const s of statements(source, f.path, result2)) {
22824
+ let namespaceTarget2 = function(dir) {
22825
+ if (!isFrom) {
22826
+ const local = s.bindings[0]?.[1];
22827
+ if (local) folders.set(`${fileId}\0${local}`, dir);
22828
+ const first = [...index.files].filter((p) => posix10.dirname(p) === dir).sort()[0];
22829
+ return first ? toFile(first, "absolute") : {
22830
+ kind: "unresolved",
22831
+ outcome: "broken",
22832
+ reason: "file-not-found",
22833
+ steps: [
22834
+ ...steps,
22835
+ { kind: "namespace", detail: `${dir} is a namespace package with no module of its own` }
22836
+ ]
22837
+ };
22838
+ }
22839
+ return {
22840
+ kind: "unresolved",
22841
+ outcome: "broken",
22842
+ reason: "file-not-found",
22843
+ steps: [
22844
+ ...steps,
22845
+ {
22846
+ kind: "namespace",
22847
+ detail: `${dir || "the root"} is a namespace package; ${names.join(", ")} isn't a module in it`
22848
+ }
22849
+ ]
22850
+ };
22851
+ };
22852
+ var namespaceTarget = namespaceTarget2;
22853
+ const steps = [];
22854
+ const names = s.bindings.map(([imported]) => imported).filter((n2) => !!n2 && n2 !== "*");
22855
+ const isFrom = s.bindings.some(([imported]) => imported !== "*");
22856
+ const toFile = (path, via) => {
22857
+ const file2 = byPath.get(path);
22858
+ if (file2.status === "not_analyzed")
22859
+ return {
22860
+ kind: "unresolved",
22861
+ outcome: "not-analyzed",
22862
+ reason: file2.reason ?? "not-analyzed",
22863
+ steps: [...steps, { kind: "not-analyzed", detail: `${path} is not analyzed` }]
22864
+ };
22865
+ return { kind: "file", file: file2, via, steps };
22866
+ };
22867
+ const binds = (dir, name) => {
22868
+ const init = results.get(`${source}\0${dir ? `${dir}/` : ""}__init__.py`);
22869
+ return !!init && (init.definitions.some((d) => d.qualifiedName === name) || init.types.some((t) => t.name === name) || init.imports.some(
22870
+ (i) => i.localName === name && !(f.path === `${dir ? `${dir}/` : ""}__init__.py` && i.span.start.offset === s.span.start.offset)
22871
+ ));
22872
+ };
22873
+ const subs = (dir, via, namespace) => {
22874
+ if (!names.length || names.length !== s.bindings.length) return null;
22875
+ const found = names.map(
22876
+ (n2) => namespace || !binds(dir, n2) ? moduleFile(index, dir ? `${dir}/${n2}` : n2) : null
22877
+ );
22878
+ if (found.some((x) => x === null)) return null;
22879
+ if (names.length === 1) submodules.add(statementKey(s));
22880
+ else {
22881
+ folders.set(statementKey(s), dir);
22882
+ names.slice(1).forEach((n2, i) => {
22883
+ const spec = s.specifier.endsWith(".") ? `${s.specifier}${n2}` : `${s.specifier}.${n2}`;
22884
+ const file2 = byPath.get(found[i + 1]);
22885
+ resolved.push({
22886
+ statement: { ...s, specifier: spec, bindings: [[n2, s.bindings[i + 1][1]]], ordinal: 0 },
22887
+ target: file2.status === "not_analyzed" ? {
22888
+ kind: "unresolved",
22889
+ outcome: "not-analyzed",
22890
+ reason: file2.reason ?? "not-analyzed",
22891
+ steps: []
22892
+ } : {
22893
+ kind: "file",
22894
+ file: file2,
22895
+ via,
22896
+ steps: [{ kind: via, detail: `${n2} is the submodule ${found[i + 1]}` }]
22897
+ }
22898
+ });
22899
+ });
22900
+ }
22901
+ steps.push({
22902
+ kind: via,
22903
+ detail: `${names.join(", ")} ${names.length === 1 ? "is the submodule" : "are submodules, the first"} ${found[0]}`
22904
+ });
22905
+ return toFile(found[0], via);
22906
+ };
22907
+ const bindPackage = () => {
22908
+ if (isFrom || !s.specifier.includes(".")) return;
22909
+ const local = s.bindings[0]?.[1];
22910
+ const top = s.specifier.split(".")[0];
22911
+ if (local !== top) return;
22912
+ const file2 = absoluteFile(top);
22913
+ if (file2) packagesOf.set(`${fileId}\0${top}`, byPath.get(file2.file));
22914
+ else {
22915
+ const dir = absoluteDir(top);
22916
+ if (dir) folders.set(`${fileId}\0${top}`, dir.dir);
22917
+ }
22918
+ };
22919
+ let target2;
22920
+ if (s.specifier.startsWith(".")) {
22921
+ const level = /^\.+/.exec(s.specifier)[0].length;
22922
+ const rest = s.specifier.slice(level);
22923
+ let dir = posix10.dirname(f.path) === "." ? "" : posix10.dirname(f.path);
22924
+ for (let i = 1; i < level; i++) dir = posix10.dirname(dir) === "." ? "" : posix10.dirname(dir);
22925
+ const path = rest ? posix10.join(dir, ...rest.split(".")) : dir;
22926
+ steps.push({ kind: "relative", detail: `${s.specifier} from ${f.path} is ${path || "the root"}` });
22927
+ const file2 = moduleFile(index, path);
22928
+ if (file2)
22929
+ target2 = isFrom && file2.endsWith("__init__.py") && subs(path, "relative", false) || toFile(file2, "relative");
22930
+ else if (path === "" || index.dirs.has(path))
22931
+ target2 = isFrom && subs(path, "relative", true) || namespaceTarget2(path);
22932
+ else
22933
+ target2 = {
22934
+ kind: "unresolved",
22935
+ outcome: "broken",
22936
+ reason: "file-not-found",
22937
+ steps: [...steps, { kind: "not-found", detail: `no module ${path}` }]
22938
+ };
22939
+ } else {
22940
+ const top = s.specifier.split(".")[0];
22941
+ const found = absoluteFile(s.specifier);
22942
+ const dist = distribution(top, project2.dependencies);
22943
+ if (found) {
22944
+ steps.push({
22945
+ kind: "absolute",
22946
+ detail: `${s.specifier} is ${found.file}${found.root ? ` (under the root ${found.root})` : ""}`
22947
+ });
22948
+ const dir = pathIn(found.root, s.specifier);
22949
+ target2 = isFrom && found.file.endsWith("__init__.py") && subs(dir, "absolute", false) || toFile(found.file, "absolute");
22950
+ bindPackage();
22951
+ } else if (absoluteFile(top) && !absoluteDir(s.specifier)) {
22952
+ target2 = {
22953
+ kind: "unresolved",
22954
+ outcome: "broken",
22955
+ reason: "file-not-found",
22956
+ steps: [{ kind: "not-found", detail: `${top} is the project's, but it has no ${s.specifier}` }]
22957
+ };
22958
+ } else if (PYTHON_STDLIB.has(top)) {
22959
+ target2 = {
22960
+ kind: "package",
22961
+ pkg: external(source, "python", top),
22962
+ via: "stdlib",
22963
+ steps: [{ kind: "builtin", detail: `${top} is Python's standard library` }]
22964
+ };
22965
+ } else if (dist) {
22966
+ target2 = {
22967
+ kind: "package",
22968
+ pkg: external(source, "pypi", dist),
22969
+ via: "dependency",
22970
+ steps: [{ kind: "dependency", detail: `the project declares ${dist}` }]
22971
+ };
22972
+ } else if (absoluteDir(s.specifier)) {
22973
+ const ns = absoluteDir(s.specifier);
22974
+ steps.push({ kind: "absolute", detail: `${s.specifier} is the namespace package ${ns.dir}` });
22975
+ target2 = isFrom && subs(ns.dir, "absolute", true) || namespaceTarget2(ns.dir);
22976
+ bindPackage();
22977
+ } else if (distributionByPrefix(top, project2.dependencies)) {
22978
+ const name = distributionByPrefix(top, project2.dependencies);
22979
+ target2 = {
22980
+ kind: "package",
22981
+ pkg: external(source, "pypi", name),
22982
+ via: "dependency",
22983
+ steps: [{ kind: "dependency", detail: `the project declares ${name}, named after ${top}` }]
22984
+ };
22985
+ } else if (optionalImport(text.get(f.path) ?? "", s.span.start.line)) {
22986
+ const name = normalize(DISTRIBUTIONS[top] ?? top);
22987
+ target2 = {
22988
+ kind: "package",
22989
+ pkg: external(source, "pypi", name),
22990
+ via: "optional",
22991
+ steps: [{ kind: "optional", detail: `imported in a try whose handler catches ImportError` }]
22992
+ };
22993
+ } else
22994
+ target2 = {
22995
+ kind: "unresolved",
22996
+ outcome: "broken",
22997
+ reason: "unknown-package",
22998
+ steps: [{ kind: "not-found", detail: `nothing in the project or its dependencies is ${top}` }]
22999
+ };
23000
+ }
23001
+ if (target2) resolved.push({ statement: s, target: target2 });
23002
+ }
23003
+ }
23004
+ }
23005
+ return { resolved, submodules, folders, packages: packagesOf };
23006
+ }
23007
+ function linkPython(input2) {
23008
+ const fnByName = new Map(input2.functions.map((f) => [`${f.file}\0${f.qualifiedName}`, f]));
23009
+ const pathOf9 = (fileId) => fileId.slice(fileId.indexOf(":") + 1);
23010
+ const sourceOf7 = (fileId) => fileId.slice(0, fileId.indexOf(":"));
23011
+ const resultOf2 = (fileId) => input2.results.get(`${sourceOf7(fileId)}\0${pathOf9(fileId)}`);
23012
+ const statementsOf = /* @__PURE__ */ new Map();
23013
+ for (const r of input2.imports.resolved) {
23014
+ const list = statementsOf.get(r.statement.fileId) ?? [];
23015
+ list.push(r);
23016
+ statementsOf.set(r.statement.fileId, list);
23017
+ }
23018
+ const fileIds = new Set(input2.imports.resolved.map((r) => r.statement.fileId));
23019
+ for (const r of input2.imports.resolved) if (r.target.kind === "file") fileIds.add(r.target.file.id);
23020
+ const allOf = /* @__PURE__ */ new Map();
23021
+ const dunderAll = (fileId) => {
23022
+ if (allOf.has(fileId)) return allOf.get(fileId);
23023
+ const m = /^__all__\s*(?::[^=]+)?=\s*[[(]([^\])]*)[\])]/m.exec(input2.text(fileId) ?? "");
23024
+ const names = m ? [...m[1].matchAll(/["']([^"']+)["']/g)].map((x) => x[1]) : null;
23025
+ allOf.set(fileId, names);
23026
+ return names;
23027
+ };
23028
+ const step = (kind, detail) => ({ kind, detail });
23029
+ const missing = (stop, detail, hops = [], steps = []) => ({
23030
+ kind: "missing",
23031
+ stop,
23032
+ hops,
23033
+ steps: [...steps, step(stop, detail)]
23034
+ });
23035
+ const variables = /* @__PURE__ */ new Map();
23036
+ const variable = (fileId, name) => {
23037
+ let vars = variables.get(fileId);
23038
+ if (!vars) {
23039
+ vars = moduleVariables(input2.text(fileId) ?? "");
23040
+ variables.set(fileId, vars);
23041
+ }
23042
+ return vars.has(name) ? vars.get(name) : null;
23043
+ };
23044
+ const boundName = (fileId, name, hops) => {
23045
+ const key = `${fileId}\0${name}`;
23046
+ const pkg = input2.imports.packages.get(key);
23047
+ if (pkg)
23048
+ return {
23049
+ kind: "module",
23050
+ file: pkg.id,
23051
+ hops,
23052
+ steps: [step("package", `${name} is the package ${pkg.path}`)]
23053
+ };
23054
+ const dir = input2.imports.folders.get(key);
23055
+ if (dir !== void 0)
23056
+ return {
23057
+ kind: "folder",
23058
+ source: sourceOf7(fileId),
23059
+ dir,
23060
+ hops,
23061
+ steps: [step("namespace", `${name} is the namespace package ${dir || "at the root"}`)]
23062
+ };
23063
+ return null;
23064
+ };
23065
+ const folderMember = (source, dir, name, hops) => {
23066
+ const base2 = dir ? `${dir}/` : "";
23067
+ for (const candidate of [`${base2}${name}/__init__.py`, `${base2}${name}.py`]) {
23068
+ if (input2.results.has(`${source}\0${candidate}`))
23069
+ return {
23070
+ kind: "module",
23071
+ file: `${source}:${candidate}`,
23072
+ hops,
23073
+ steps: [step("submodule", `${name} is the submodule ${candidate}`)]
23074
+ };
23075
+ }
23076
+ return missing("not-exported", `${dir || "the root"} has no module ${name}`, hops);
23077
+ };
23078
+ const lookup = (fileId, name, hops, depth, star) => {
23079
+ const path = pathOf9(fileId);
23080
+ if (depth > MAX_DEPTH3) return missing("cycle", `${path} imports ${name} in a cycle`, hops);
23081
+ const result2 = resultOf2(fileId);
23082
+ if (!result2) return missing("not-found", `${path} was not read`, hops);
23083
+ if (star) {
23084
+ const all2 = dunderAll(fileId);
23085
+ if (all2 ? !all2.includes(name) : name.startsWith("_"))
23086
+ return missing(
23087
+ "not-exported",
23088
+ `${path}'s ${all2 ? "__all__" : "public names"} leave out ${name}`,
23089
+ hops
23090
+ );
23091
+ }
23092
+ const fn = fnByName.get(`${fileId}\0${name}`);
23093
+ if (fn)
23094
+ return { kind: "function", fn: fn.id, hops, steps: [step("definition", `${path} defines ${name}`)] };
23095
+ if (result2.types.some((t) => t.name === name))
23096
+ return {
23097
+ kind: "class",
23098
+ file: fileId,
23099
+ name,
23100
+ hops,
23101
+ steps: [step("definition", `${path} defines the class ${name}`)]
23102
+ };
23103
+ const value = variable(fileId, name);
23104
+ if (value !== null)
23105
+ return {
23106
+ kind: "value",
23107
+ file: fileId,
23108
+ name,
23109
+ cls: value,
23110
+ hops,
23111
+ steps: [step("value", `${path} assigns ${name}${value ? ` (${value})` : ""}`)]
23112
+ };
23113
+ if (hops.includes(fileId)) return missing("cycle", `${path} imports ${name} in a cycle`, hops);
23114
+ const statements2 = statementsOf.get(fileId) ?? [];
23115
+ for (const r of statements2) {
23116
+ const binding2 = r.statement.bindings.find(([, local]) => local === name);
23117
+ if (!binding2) continue;
23118
+ const imported = binding2[0];
23119
+ const via = step("re-export", `${path} imports ${name} from ${r.statement.specifier}`);
23120
+ if (imported === "*") {
23121
+ const ns = bindingAsModule(r);
23122
+ if (ns.kind === "folder") return { ...ns, hops };
23123
+ const t = r.target;
23124
+ if (t.kind === "package") return { kind: "external", pkg: t.pkg.id, hops, steps: [via, ...t.steps] };
23125
+ if (t.kind === "unresolved")
23126
+ return { kind: "unresolved", outcome: t.outcome, hops, steps: [via, ...t.steps] };
23127
+ return { kind: "module", file: t.file.id, hops: [...hops, fileId], steps: [via] };
23128
+ }
23129
+ const e = bindingOf(r, imported, [...hops, fileId], depth + 1);
23130
+ return { ...e, steps: [via, ...e.steps] };
23131
+ }
23132
+ for (const r of statements2) {
23133
+ if (!r.statement.bindings.some(([imported, local]) => imported === "*" && local === null)) continue;
23134
+ if (r.target.kind !== "file") continue;
23135
+ const e = lookup(r.target.file.id, name, [...hops, fileId], depth + 1, true);
23136
+ if (e.kind !== "missing")
23137
+ return {
23138
+ ...e,
23139
+ steps: [step("re-export", `${path} imports everything from ${r.statement.specifier}`), ...e.steps]
23140
+ };
23141
+ }
23142
+ const bound = boundName(fileId, name, hops);
23143
+ if (bound) return bound;
23144
+ if (path.endsWith("__init__.py")) {
23145
+ const dir = posix10.dirname(path);
23146
+ const base2 = dir === "." ? "" : `${dir}/`;
23147
+ for (const candidate of [`${base2}${name}.py`, `${base2}${name}/__init__.py`]) {
23148
+ const id = `${sourceOf7(fileId)}:${candidate}`;
23149
+ if (fileIds.has(id) || input2.results.has(`${sourceOf7(fileId)}\0${candidate}`))
23150
+ return {
23151
+ kind: "module",
23152
+ file: id,
23153
+ hops,
23154
+ steps: [step("submodule", `${name} is the submodule ${candidate}`)]
23155
+ };
23156
+ }
23157
+ }
23158
+ return missing("not-exported", `${path} defines or imports no ${name}`, hops);
23159
+ };
23160
+ const bindingOf = (r, imported, hops, depth) => {
23161
+ const t = r.target;
23162
+ if (t.kind === "package") return { kind: "external", pkg: t.pkg.id, hops, steps: [...t.steps] };
23163
+ if (t.kind === "unresolved") return { kind: "unresolved", outcome: t.outcome, hops, steps: [...t.steps] };
23164
+ if (input2.imports.submodules.has(statementKey(r.statement)))
23165
+ return { kind: "module", file: t.file.id, hops, steps: [...t.steps] };
23166
+ const dir = input2.imports.folders.get(statementKey(r.statement));
23167
+ if (dir !== void 0) return withSteps(folderMember(t.file.source, dir, imported, hops), [...t.steps]);
23168
+ const e = lookup(t.file.id, imported, hops, depth, false);
23169
+ return { ...e, steps: [...t.steps, ...e.steps] };
23170
+ };
23171
+ const classDecl = (c) => resultOf2(c.file)?.types.find((t) => t.name === c.name);
23172
+ const baseMemo = /* @__PURE__ */ new Map();
23173
+ const baseOf2 = (c, base2) => {
23174
+ const key = `${c.file}#${c.name}#${base2}`;
23175
+ let e = baseMemo.get(key);
23176
+ if (!e) baseMemo.set(key, e = baseOfUncached(c, base2));
23177
+ return e;
23178
+ };
23179
+ const baseOfUncached = (c, base2) => {
23180
+ const [head, ...rest] = base2.split(".");
23181
+ if (resultOf2(c.file)?.types.some((t) => t.name === base2))
23182
+ return { kind: "class", file: c.file, name: base2, hops: [], steps: [] };
23183
+ const r = (statementsOf.get(c.file) ?? []).find((s) => s.statement.bindings.some(([, l]) => l === head));
23184
+ let e;
23185
+ if (r) {
23186
+ const imported = r.statement.bindings.find(([, l]) => l === head)[0];
23187
+ e = imported === "*" ? bindingAsModule(r) : bindingOf(r, imported, [], 0);
23188
+ } else
23189
+ e = boundName(c.file, head, []) ?? missing("not-found", `${base2} isn't defined or imported in ${pathOf9(c.file)}`);
23190
+ for (const part of rest) {
23191
+ if (e.kind === "module") e = lookup(e.file, part, [], 0, false);
23192
+ else if (e.kind === "folder") e = folderMember(e.source, e.dir, part, []);
23193
+ else if (e.kind !== "external" && e.kind !== "unresolved")
23194
+ return missing("member", `${base2} can't be followed`);
23195
+ }
23196
+ return e;
23197
+ };
23198
+ const bindingAsModule = (r) => {
23199
+ const local = r.statement.bindings.find(([imported, l]) => imported === "*" && l)?.[1];
23200
+ const ns = local ? input2.imports.folders.get(`${r.statement.fileId}\0${local}`) : void 0;
23201
+ if (ns !== void 0)
23202
+ return {
23203
+ kind: "folder",
23204
+ source: sourceOf7(r.statement.fileId),
23205
+ dir: ns,
23206
+ hops: [],
23207
+ steps: [step("namespace", `${local} is the namespace package ${ns || "at the root"}`)]
23208
+ };
23209
+ const t = r.target;
23210
+ if (t.kind === "package") return { kind: "external", pkg: t.pkg.id, hops: [], steps: [...t.steps] };
23211
+ if (t.kind === "unresolved")
23212
+ return { kind: "unresolved", outcome: t.outcome, hops: [], steps: [...t.steps] };
23213
+ return { kind: "module", file: t.file.id, hops: [], steps: [...t.steps] };
23214
+ };
23215
+ const methodOf = (c, m, seen = /* @__PURE__ */ new Set()) => {
23216
+ const key = `${c.file}#${c.name}`;
23217
+ if (seen.has(key)) return null;
23218
+ seen.add(key);
23219
+ const decl = classDecl(c);
23220
+ if (!decl) return null;
23221
+ const own2 = [...decl.members, ...decl.statics ?? []].find((x) => x.name === m);
23222
+ if (own2?.function) {
23223
+ const fn = fnByName.get(`${c.file}\0${own2.function}`);
23224
+ if (fn) return { fn, definer: c };
23225
+ }
23226
+ if (m === "__init__") {
23227
+ const fn = fnByName.get(`${c.file}\0${c.name}.__init__`);
23228
+ if (fn && !fn.implicit) return { fn, definer: c };
23229
+ }
23230
+ if (own2) return null;
23231
+ let pkg = null;
23232
+ for (const b of decl.bases) {
23233
+ const e = baseOf2(c, b.name);
23234
+ if (e.kind === "class") {
23235
+ const found = methodOf(e, m, seen);
23236
+ if (found && "fn" in found) return found;
23237
+ if (found && "pkg" in found) pkg ??= found.pkg;
23238
+ } else if (e.kind === "external") pkg ??= e.pkg;
23239
+ }
23240
+ return pkg ? { pkg } : null;
23241
+ };
23242
+ const constructorOf = (c) => {
23243
+ const found = methodOf(c, "__init__");
23244
+ if (found && "fn" in found) return found.fn;
23245
+ return fnByName.get(`${c.file}\0${c.name}.__init__`);
23246
+ };
23247
+ let classes = null;
23248
+ const allClasses = () => {
23249
+ if (classes) return classes;
23250
+ const out = [];
23251
+ for (const [key, result2] of input2.results) {
23252
+ if (result2.language !== "python") continue;
23253
+ const fileId = ids.file(key.slice(0, key.indexOf("\0")), key.slice(key.indexOf("\0") + 1));
23254
+ for (const decl of result2.types) out.push({ file: fileId, decl });
23255
+ }
23256
+ return classes = out.sort(
23257
+ (a, b) => a.file < b.file ? -1 : a.file > b.file ? 1 : a.decl.span.start.offset - b.decl.span.start.offset
23258
+ );
23259
+ };
23260
+ const ancestors2 = /* @__PURE__ */ new Map();
23261
+ const ancestorsOf = (c) => {
23262
+ const key = `${c.file}#${c.name}`;
23263
+ const known = ancestors2.get(key);
23264
+ if (known) return known;
23265
+ const out = /* @__PURE__ */ new Set([key]);
23266
+ ancestors2.set(key, out);
23267
+ for (const b of classDecl(c)?.bases ?? []) {
23268
+ const e = baseOf2(c, b.name);
23269
+ if (e.kind === "class") for (const a of ancestorsOf(e)) out.add(a);
23270
+ }
23271
+ return out;
23272
+ };
23273
+ const reaches = (c, target2) => ancestorsOf(c).has(`${target2.file}#${target2.name}`);
23274
+ const evidence = (file2, span) => ({
23275
+ file: file2,
23276
+ span,
23277
+ commit: input2.revisions.get(sourceOf7(file2)) ?? ""
23278
+ });
23279
+ const baseClause = (file2, decl, base2) => {
23280
+ const b = decl.bases.find((x) => x.name === base2);
23281
+ if (!b) return null;
23282
+ const text = input2.text(file2);
23283
+ if (!text) return b.span;
23284
+ const bytes = Buffer.from(text, "utf8");
23285
+ const open3 = bytes.lastIndexOf(40, b.span.start.offset);
23286
+ const close = bytes.indexOf(41, decl.bases.at(-1).span.end.offset);
23287
+ if (open3 < decl.span.start.offset || close < 0) return b.span;
23288
+ const pos = (offset) => {
23289
+ const before = bytes.subarray(0, offset).toString("utf8");
23290
+ const line = before.split("\n").length;
23291
+ const column = [...before.slice(before.lastIndexOf("\n") + 1)].length + 1;
23292
+ return { line, column, offset };
23293
+ };
23294
+ return { start: pos(open3), end: pos(close + 1) };
23295
+ };
23296
+ const candidateMemo = /* @__PURE__ */ new Map();
23297
+ const typedCandidates = (c, m) => {
23298
+ const key = `${c.file}#${c.name}#${m}`;
23299
+ let found = candidateMemo.get(key);
23300
+ if (!found) candidateMemo.set(key, found = typedCandidatesOf(c, m));
23301
+ return found;
23302
+ };
23303
+ const typedCandidatesOf = (c, m) => {
23304
+ const bodies = /* @__PURE__ */ new Map();
23305
+ for (const { file: file2, decl } of allClasses()) {
23306
+ const cls = { file: file2, name: decl.name };
23307
+ if (!reaches(cls, c)) continue;
23308
+ const body = methodOf(cls, m);
23309
+ if (!body || !("fn" in body) || bodies.has(body.fn.id)) continue;
23310
+ const own2 = body.definer.file === c.file && body.definer.name === c.name;
23311
+ let basis;
23312
+ if (own2) basis = evidence(body.fn.file, body.fn.evidence.span);
23313
+ else {
23314
+ const definerDecl = classDecl(body.definer);
23315
+ const parent = definerDecl.bases.find((b) => {
23316
+ const e = baseOf2(body.definer, b.name);
23317
+ return e.kind === "class" && reaches(e, c);
23318
+ });
23319
+ const span = parent ? baseClause(body.definer.file, definerDecl, parent.name) : null;
23320
+ basis = evidence(body.definer.file, span ?? definerDecl.span);
23321
+ }
23322
+ bodies.set(body.fn.id, { fn: body.fn, basis });
23323
+ }
23324
+ return [...bodies.values()].sort(
23325
+ (a, b) => a.fn.file < b.fn.file ? -1 : a.fn.file > b.fn.file ? 1 : a.fn.evidence.span.start.offset - b.fn.evidence.span.start.offset
23326
+ );
23327
+ };
23328
+ const memberOf = (e, m) => {
23329
+ const found = methodOf(e, m);
23330
+ return found && "fn" in found ? {
23331
+ kind: "function",
23332
+ fn: found.fn.id,
23333
+ hops: e.hops,
23334
+ steps: [...e.steps, step("instance", `${e.name}'s ${m} is ${found.fn.qualifiedName}`)]
23335
+ } : found && "pkg" in found ? { kind: "external", pkg: found.pkg, hops: e.hops, steps: e.steps } : missing("member", `no class up ${e.name}'s chain declares ${m}`, e.hops, e.steps);
23336
+ };
23337
+ const classNamed = (fileId, name) => {
23338
+ const [head] = name.split(".");
23339
+ if (resultOf2(fileId)?.types.some((t) => t.name === name))
23340
+ return { kind: "class", file: fileId, name, hops: [], steps: [] };
23341
+ const r = (statementsOf.get(fileId) ?? []).find((s) => s.statement.bindings.some(([, l]) => l === head));
23342
+ if (!r) return missing("not-found", `${name} isn't defined or imported here`);
23343
+ return baseOf2({ file: fileId, name: "" }, name);
23344
+ };
23345
+ const resolutions = [];
23346
+ const edges = [];
23347
+ for (const site of input2.sites) {
23348
+ const base2 = {
23349
+ type: "SiteResolution",
23350
+ id: ids.resolution(site.id),
23351
+ site: site.id,
23352
+ file: site.file,
23353
+ evidence: site.evidence
23354
+ };
23355
+ if (site.reason === "dynamic-dispatch") {
23356
+ const table = /^([A-Za-z_]\w*)\[/.exec(site.expression)?.[1];
23357
+ if (table) {
23358
+ const tables = (resultOf2(site.file)?.tables ?? []).filter((t) => t.name === table);
23359
+ if (tables.length === 1) {
23360
+ const t = tables[0];
23361
+ const candidates = t.entries.flatMap((e2) => {
23362
+ const fn = e2.function ? fnByName.get(`${site.file}\0${e2.function}`) : void 0;
23363
+ return fn ? [{ function: fn.id, basis: evidence(site.file, e2.span) }] : [];
23364
+ });
23365
+ if (candidates.length)
23366
+ resolutions.push({
23367
+ ...base2,
23368
+ status: "unresolved",
23369
+ target: null,
23370
+ externalPackage: null,
23371
+ importOutcome: null,
23372
+ steps: [step("table", `${table} is a dict of functions; the call runs one of its values`)],
23373
+ candidates,
23374
+ ...t.exhaustive ? {} : { exhaustive: false }
23375
+ });
23376
+ }
23377
+ continue;
23378
+ }
23379
+ const raw = resultOf2(site.file)?.unresolved.find(
23380
+ (u) => u.site.start.offset === site.evidence.span.start.offset && u.expression === site.expression
23381
+ );
23382
+ if (raw?.receiverType && raw.member) {
23383
+ const c = classNamed(site.file, raw.receiverType);
23384
+ if (c.kind !== "class") continue;
23385
+ const found = typedCandidates(c, raw.member);
23386
+ if (found.length)
23387
+ resolutions.push({
23388
+ ...base2,
23389
+ status: "unresolved",
23390
+ target: null,
23391
+ externalPackage: null,
23392
+ importOutcome: null,
23393
+ steps: [step("typed", `${site.expression}'s receiver is annotated ${raw.receiverType}`)],
23394
+ candidates: found.map((x) => ({ function: x.fn.id, basis: x.basis })),
23395
+ exhaustive: false
23396
+ });
23397
+ }
23398
+ continue;
23399
+ }
23400
+ if (site.reason !== "imported-symbol" || !site.importSpecifier) continue;
23401
+ const local = /^[A-Za-z_]\w*/.exec(site.expression)?.[0] ?? "";
23402
+ const inherited = /^(self|cls)\./.test(site.expression) || site.expression.startsWith("super()");
23403
+ const statements2 = (statementsOf.get(site.file) ?? []).filter(
23404
+ (r) => r.statement.specifier === site.importSpecifier
23405
+ );
23406
+ const statement = inherited ? statements2.find(
23407
+ (r) => r.statement.bindings.some(
23408
+ ([imported, l]) => (imported ?? l) === site.importedName || l === site.importedName
23409
+ )
23410
+ ) ?? statements2.find((r) => r.statement.bindings.some(([imported]) => imported === "*")) : statements2.find((r) => r.statement.bindings.some(([, l]) => l === local)) ?? // A method on an instance of an imported class (`a = A(); a.run()`): the binding of A.
23411
+ statements2.find(
23412
+ (r) => r.statement.bindings.some(
23413
+ ([imported, l]) => l === site.importedName || imported === site.importedName
23414
+ )
23415
+ ) ?? statements2[0];
23416
+ let e;
23417
+ if (inherited) {
23418
+ const name = site.importedName;
23419
+ const b = statement?.statement.bindings.find(
23420
+ ([imported, l]) => (l === name || imported === name) && imported !== "*"
23421
+ );
23422
+ e = !statement ? missing("not-found", `no import of ${site.importSpecifier} in this file`) : b ? bindingOf(statement, b[0], [], 0) : bindingAsModule(statement);
23423
+ if (e.kind === "module") e = withSteps(lookup(e.file, name, e.hops, 0, false), e.steps);
23424
+ else if (e.kind === "folder") e = folderMember(e.source, e.dir, name, e.hops);
23425
+ } else {
23426
+ const dotted = (statementsOf.get(site.file) ?? []).find(
23427
+ (r) => r.statement.specifier.startsWith(`${site.importSpecifier}.`) && r.statement.bindings.some(([imported, l]) => imported === "*" && l === local) && r.target.kind === "package"
23428
+ );
23429
+ if (!statement)
23430
+ e = boundName(site.file, local, []) ?? (dotted ? bindingAsModule(dotted) : missing("not-found", `no import of ${site.importSpecifier} in this file`));
23431
+ else {
23432
+ const binding2 = statement.statement.bindings.find(([, l]) => l === local) ?? statement.statement.bindings.find(
23433
+ ([imported, l]) => l === site.importedName || imported === site.importedName
23434
+ ) ?? statement.statement.bindings[0];
23435
+ e = binding2[0] === "*" ? bindingAsModule(statement) : bindingOf(statement, binding2[0], [], 0);
23436
+ }
23437
+ if (!statement || statement.statement.bindings.some(([imported, l]) => imported === "*" && l === local)) {
23438
+ if (site.importedName && e.kind === "module")
23439
+ e = withSteps(lookup(e.file, site.importedName, e.hops, 0, false), e.steps);
23440
+ else if (site.importedName && e.kind === "folder")
23441
+ e = folderMember(e.source, e.dir, site.importedName, e.hops);
23442
+ }
23443
+ }
23444
+ let called = !site.member;
23445
+ if (site.member && (e.kind === "module" || e.kind === "folder")) {
23446
+ e = e.kind === "module" ? withSteps(lookup(e.file, site.member, e.hops, 0, false), e.steps) : folderMember(e.source, e.dir, site.member, e.hops);
23447
+ called = true;
23448
+ } else if (site.member && e.kind === "value") {
23449
+ const v = e;
23450
+ const cls = v.cls ? classNamed(v.file, v.cls) : null;
23451
+ e = !cls ? missing(
23452
+ "member",
23453
+ `${v.name} is a variable of ${pathOf9(v.file)}; what it holds isn't followed`,
23454
+ v.hops,
23455
+ v.steps
23456
+ ) : cls.kind === "class" || cls.kind === "external" || cls.kind === "unresolved" ? { ...cls, hops: v.hops, steps: [...v.steps, ...cls.steps] } : missing("member", `${v.name} holds a ${v.cls}, which can't be followed`, v.hops, v.steps);
23457
+ if (e.kind === "class") e = memberOf(e, site.member);
23458
+ } else if (site.member && e.kind === "class") e = memberOf(e, site.member);
23459
+ else if (site.member && e.kind === "function")
23460
+ e = missing(
23461
+ "member",
23462
+ `${site.expression} calls a member of what ${local} names, a function`,
23463
+ e.hops,
23464
+ e.steps
23465
+ );
23466
+ if (called) {
23467
+ if (e.kind === "class") {
23468
+ const ctor = constructorOf(e);
23469
+ e = ctor ? {
23470
+ kind: "function",
23471
+ fn: ctor.id,
23472
+ hops: e.hops,
23473
+ steps: [...e.steps, step("constructor", `calling ${e.name} runs ${ctor.qualifiedName}`)]
23474
+ } : missing("not-a-function", `${e.name} has no constructor Stage 2 can follow`, e.hops, e.steps);
23475
+ } else if (e.kind === "module" || e.kind === "folder")
23476
+ e = missing("not-a-function", `${site.expression} is a module`, e.hops, e.steps);
23477
+ else if (e.kind === "value")
23478
+ e = missing(
23479
+ "not-a-function",
23480
+ `${e.name} is a variable of ${pathOf9(e.file)}, not a function Stage 2 follows`,
23481
+ e.hops,
23482
+ e.steps
23483
+ );
23484
+ }
23485
+ const via = inherited ? "inherited" : "import";
23486
+ e = withSteps(e, [
23487
+ step(
23488
+ "import",
23489
+ inherited ? `${site.expression} reaches ${site.importedName}, a base imported from ${site.importSpecifier}` : `${site.expression} goes through the import of ${site.importSpecifier}`
23490
+ )
23491
+ ]);
23492
+ switch (e.kind) {
23493
+ case "function":
23494
+ resolutions.push({
23495
+ ...base2,
23496
+ status: "linked",
23497
+ target: e.fn,
23498
+ externalPackage: null,
23499
+ via,
23500
+ importOutcome: null,
23501
+ steps: e.steps,
23502
+ hops: e.hops
23503
+ });
23504
+ edges.push({
23505
+ type: "CALLS_CROSS_FILE",
23506
+ id: ids.linkedCall(site.id),
23507
+ from: site.enclosingFn,
23508
+ to: e.fn,
23509
+ form: "plain",
23510
+ resolution: "static-exact",
23511
+ confidence: 1,
23512
+ evidence: site.evidence,
23513
+ via: "import"
23514
+ });
23515
+ break;
23516
+ case "external":
23517
+ resolutions.push({
23518
+ ...base2,
23519
+ status: "external",
23520
+ target: null,
23521
+ externalPackage: e.pkg,
23522
+ importOutcome: null,
23523
+ steps: e.steps
23524
+ });
23525
+ break;
23526
+ case "unresolved":
23527
+ resolutions.push({
23528
+ ...base2,
23529
+ status: "unresolved",
23530
+ target: null,
23531
+ externalPackage: null,
23532
+ importOutcome: e.outcome,
23533
+ steps: e.steps
23534
+ });
23535
+ break;
23536
+ default:
23537
+ resolutions.push({
23538
+ ...base2,
23539
+ status: "unresolved",
23540
+ target: null,
23541
+ externalPackage: null,
23542
+ importOutcome: null,
23543
+ steps: e.steps
23544
+ });
23545
+ }
23546
+ }
23547
+ return { resolutions, edges };
23548
+ function withSteps(e, before) {
23549
+ return { ...e, steps: [...before, ...e.steps] };
23550
+ }
23551
+ }
23552
+ var PYTHON_STDLIB, DISTRIBUTIONS, normalize, isPython, quoted, closes, statementKey, MAX_DEPTH3;
23553
+ var init_python = __esm({
23554
+ "packages/stage2/src/python.ts"() {
23555
+ "use strict";
23556
+ init_src();
23557
+ init_src3();
23558
+ init_protocol();
23559
+ init_imports();
23560
+ PYTHON_STDLIB = new Set(
23561
+ "abc aifc argparse array ast asynchat asyncio asyncore atexit audioop base64 bdb binascii bisect builtins bz2 cProfile calendar cgi cgitb chunk cmath cmd code codecs codeop collections colorsys compileall concurrent configparser contextlib contextvars copy copyreg crypt csv ctypes curses dataclasses datetime dbm decimal difflib dis distutils doctest email encodings ensurepip enum errno faulthandler fcntl filecmp fileinput fnmatch fractions ftplib functools gc genericpath getopt getpass gettext glob graphlib grp gzip hashlib heapq hmac html http idlelib imaplib imghdr imp importlib inspect io ipaddress itertools json keyword lib2to3 linecache locale logging lzma mailbox mailcap marshal math mimetypes mmap modulefinder msilib msvcrt multiprocessing netrc nis nntplib ntpath nturl2path numbers opcode operator optparse os ossaudiodev pathlib pdb pickle pickletools pipes pkgutil platform plistlib poplib posix posixpath pprint profile pstats pty pwd py_compile pyclbr pydoc pydoc_data pyexpat queue quopri random re readline reprlib resource rlcompleter runpy sched secrets select selectors shelve shlex shutil signal site smtpd smtplib sndhdr socket socketserver spwd sqlite3 sre_compile sre_constants sre_parse ssl stat statistics string stringprep struct subprocess sunau symtable sys sysconfig syslog tabnanny tarfile telnetlib tempfile termios textwrap this threading time timeit tkinter token tokenize tomllib trace traceback tracemalloc tty turtle turtledemo types typing unicodedata unittest urllib uu uuid venv warnings wave weakref webbrowser winreg winsound wsgiref xdrlib xml xmlrpc zipapp zipfile zipimport zlib zoneinfo __future__ _thread typing_extensions".split(" ")
23562
+ );
23563
+ DISTRIBUTIONS = {
23564
+ yaml: "pyyaml",
23565
+ PIL: "pillow",
23566
+ sklearn: "scikit-learn",
23567
+ bs4: "beautifulsoup4",
23568
+ cv2: "opencv-python",
23569
+ dateutil: "python-dateutil",
23570
+ jwt: "pyjwt",
23571
+ dotenv: "python-dotenv",
23572
+ magic: "python-magic",
23573
+ attr: "attrs",
23574
+ google: "google",
23575
+ jose: "python-jose",
23576
+ multipart: "python-multipart",
23577
+ slugify: "python-slugify",
23578
+ Crypto: "pycryptodome",
23579
+ OpenSSL: "pyopenssl",
23580
+ serial: "pyserial",
23581
+ usb: "pyusb",
23582
+ zmq: "pyzmq",
23583
+ psycopg2: "psycopg2-binary",
23584
+ MySQLdb: "mysqlclient",
23585
+ grpc: "grpcio",
23586
+ qcloud_cos: "cos-python-sdk-v5",
23587
+ baidubce: "bce-python-sdk",
23588
+ obs: "esdk-obs-python",
23589
+ Tea: "alibabacloud-tea",
23590
+ docx: "python-docx",
23591
+ pptx: "python-pptx"
23592
+ };
23593
+ normalize = (name) => name.toLowerCase().replace(/[-_.]+/g, "-");
23594
+ isPython = (path) => path.endsWith(".py") || path.endsWith(".pyi");
23595
+ quoted = (value) => [...value.replace(/\{[^}]*\}/g, "").matchAll(/["']([^"']*)["']/g)].map((m) => m[1]);
23596
+ closes = (line) => line.replace(/"[^"]*"|'[^']*'/g, "").includes("]");
23597
+ statementKey = (s) => `${s.fileId}\0${s.span.start.offset}\0${s.specifier}`;
23598
+ MAX_DEPTH3 = 32;
23599
+ }
23600
+ });
23601
+
22536
23602
  // packages/stage2/src/index.ts
22537
23603
  function scopeOf2(fact) {
22538
23604
  switch (fact.type) {
@@ -22619,14 +23685,31 @@ async function runStage2(ctx, options2 = {}) {
22619
23685
  }
22620
23686
  await step(1, "resolving imports", () => files.length, "files");
22621
23687
  const { resolved, results } = resolveImports2(ctx.plans, files);
22622
- const { edges, unresolved, packages } = importFacts(resolved);
23688
+ const pyResults = pythonResults(ctx.plans);
23689
+ const pyImports = resolvePythonImports(ctx.plans, files, pyResults);
23690
+ const { edges, unresolved, packages } = importFacts([...resolved, ...pyImports.resolved]);
23691
+ const pyFiles = new Set(files.filter((f) => f.language === "python").map((f) => f.id));
23692
+ const allSites = view.facts("UnresolvedCallSite");
22623
23693
  const linkInput = {
22624
23694
  resolved,
22625
23695
  results,
22626
23696
  functions: view.facts("Function"),
22627
- sites: view.facts("UnresolvedCallSite"),
23697
+ sites: allSites.filter((s) => !pyFiles.has(s.file)),
22628
23698
  revisions: new Map(ctx.plans.map((p) => [p.sourceId, p.revision]))
22629
23699
  };
23700
+ const pyText = new Map(
23701
+ ctx.plans.flatMap(
23702
+ (p) => p.files.filter((f) => f.content !== void 0 && f.language === "python").map((f) => [ids.file(p.sourceId, f.path), f.content])
23703
+ )
23704
+ );
23705
+ const pyLinked = linkPython({
23706
+ imports: pyImports,
23707
+ results: pyResults,
23708
+ functions: linkInput.functions,
23709
+ sites: allSites.filter((s) => pyFiles.has(s.file)),
23710
+ revisions: linkInput.revisions,
23711
+ text: (id) => pyText.get(id)
23712
+ });
22630
23713
  await step(2, "linking calls", () => linkInput.sites.length, "call sites");
22631
23714
  const graph = typeGraph(linkInput);
22632
23715
  const linked = link(linkInput, graph);
@@ -22754,6 +23837,7 @@ async function runStage2(ctx, options2 = {}) {
22754
23837
  // Stage 2's links and R1's template links.
22755
23838
  calls: [
22756
23839
  ...linked.edges,
23840
+ ...pyLinked.edges,
22757
23841
  ...typed.edges,
22758
23842
  ...injected.edges,
22759
23843
  ...returned.edges,
@@ -22781,6 +23865,8 @@ async function runStage2(ctx, options2 = {}) {
22781
23865
  ...packages,
22782
23866
  ...kept,
22783
23867
  ...named.resolutions,
23868
+ ...pyLinked.resolutions,
23869
+ ...pyLinked.edges,
22784
23870
  ...typed.edges,
22785
23871
  ...injected.edges,
22786
23872
  ...returned.edges,
@@ -22826,6 +23912,7 @@ var init_src8 = __esm({
22826
23912
  init_types();
22827
23913
  init_typegraph();
22828
23914
  init_together();
23915
+ init_python();
22829
23916
  init_imports();
22830
23917
  init_link();
22831
23918
  init_candidates();
@@ -22839,7 +23926,7 @@ var init_src8 = __esm({
22839
23926
  symbolsScope = (fileId) => `${STAGE23}:symbols:${fileId}`;
22840
23927
  groupSource = (groupId) => groupId.split("|")[1];
22841
23928
  STEPS = 5;
22842
- STAGE2_VERSION = 9;
23929
+ STAGE2_VERSION = 10;
22843
23930
  stage2 = createStage2();
22844
23931
  }
22845
23932
  });
@@ -53788,8 +54875,8 @@ var require_resolve = __commonJS({
53788
54875
  }
53789
54876
  return count2;
53790
54877
  }
53791
- function getFullPath(resolver, id = "", normalize2) {
53792
- if (normalize2 !== false)
54878
+ function getFullPath(resolver, id = "", normalize3) {
54879
+ if (normalize3 !== false)
53793
54880
  id = normalizeId(id);
53794
54881
  const p = resolver.parse(id);
53795
54882
  return _getFullPath(resolver, p);
@@ -55384,7 +56471,7 @@ var require_fast_uri = __commonJS({
55384
56471
  }
55385
56472
  return decodedScheme;
55386
56473
  }
55387
- function normalize2(uri, options2) {
56474
+ function normalize3(uri, options2) {
55388
56475
  if (typeof uri === "string") {
55389
56476
  uri = /** @type {T} */
55390
56477
  normalizeString(uri, options2);
@@ -55762,7 +56849,7 @@ var require_fast_uri = __commonJS({
55762
56849
  }
55763
56850
  var fastUri = {
55764
56851
  SCHEMES,
55765
- normalize: normalize2,
56852
+ normalize: normalize3,
55766
56853
  resolve: resolve9,
55767
56854
  resolveComponent,
55768
56855
  equal,
@@ -65756,7 +66843,7 @@ var require_send = __commonJS({
65756
66843
  var { createHttpError } = require_createHttpError();
65757
66844
  var extname = path.extname;
65758
66845
  var join14 = path.join;
65759
- var normalize2 = path.normalize;
66846
+ var normalize3 = path.normalize;
65760
66847
  var resolve9 = path.resolve;
65761
66848
  var sep9 = path.sep;
65762
66849
  var Readable = stream.Readable;
@@ -65835,20 +66922,20 @@ var require_send = __commonJS({
65835
66922
  let parts;
65836
66923
  if (root !== null) {
65837
66924
  if (path2) {
65838
- path2 = normalize2("." + sep9 + path2);
66925
+ path2 = normalize3("." + sep9 + path2);
65839
66926
  }
65840
66927
  if (UP_PATH_REGEXP.test(path2)) {
65841
66928
  debug('malicious path "%s"', path2);
65842
66929
  return { statusCode: 403 };
65843
66930
  }
65844
66931
  parts = path2.split(sep9);
65845
- path2 = normalize2(join14(root, path2));
66932
+ path2 = normalize3(join14(root, path2));
65846
66933
  } else {
65847
66934
  if (UP_PATH_REGEXP.test(path2)) {
65848
66935
  debug('malicious path "%s"', path2);
65849
66936
  return { statusCode: 403 };
65850
66937
  }
65851
- parts = normalize2(path2).split(sep9);
66938
+ parts = normalize3(path2).split(sep9);
65852
66939
  path2 = resolve9(path2);
65853
66940
  }
65854
66941
  return { path: path2, parts };
@@ -84876,11 +85963,11 @@ var require_pino = __commonJS({
84876
85963
  depthLimit: 5,
84877
85964
  edgeLimit: 100
84878
85965
  };
84879
- var normalize2 = createArgsNormalizer(defaultOptions2);
85966
+ var normalize3 = createArgsNormalizer(defaultOptions2);
84880
85967
  var serializers = Object.assign(/* @__PURE__ */ Object.create(null), stdSerializers);
84881
85968
  function pino(...args) {
84882
85969
  const instance = {};
84883
- const { opts, stream } = normalize2(instance, caller(), ...args);
85970
+ const { opts, stream } = normalize3(instance, caller(), ...args);
84884
85971
  if (opts.level && typeof opts.level === "string" && DEFAULT_LEVELS[opts.level.toLowerCase()] !== void 0) opts.level = opts.level.toLowerCase();
84885
85972
  const {
84886
85973
  redact: redact2,
@@ -91316,7 +92403,7 @@ var require_fast_uri2 = __commonJS({
91316
92403
  }
91317
92404
  return decodedScheme;
91318
92405
  }
91319
- function normalize2(uri, options2) {
92406
+ function normalize3(uri, options2) {
91320
92407
  if (typeof uri === "string") {
91321
92408
  uri = /** @type {T} */
91322
92409
  normalizeString(uri, options2);
@@ -91709,7 +92796,7 @@ var require_fast_uri2 = __commonJS({
91709
92796
  }
91710
92797
  var fastUri = {
91711
92798
  SCHEMES,
91712
- normalize: normalize2,
92799
+ normalize: normalize3,
91713
92800
  resolve: resolve9,
91714
92801
  resolveComponent,
91715
92802
  equal,
@@ -102077,7 +103164,7 @@ function unresolvedName(ctx, r, verb) {
102077
103164
  ...r.near.length ? { note: "Functions with similar names are listed." } : {}
102078
103165
  };
102079
103166
  }
102080
- function normalize(question) {
103167
+ function normalize2(question) {
102081
103168
  return question.trim().replace(/\s+/g, " ").replace(/^(?:please\s+|can you\s+|could you\s+)?(?:tell me\s+|show me\s+(?=the\s+))?/i, "").replace(/[?!.\s]+$/, "");
102082
103169
  }
102083
103170
  function repositoryOf(text, sources) {
@@ -102091,7 +103178,7 @@ function repositoryOf(text, sources) {
102091
103178
  return hit ? { source: hit.id, text: m[1] } : null;
102092
103179
  }
102093
103180
  function answerWithGrammar(engine, project2, question, options2 = {}) {
102094
- let text = normalize(question);
103181
+ let text = normalize2(question);
102095
103182
  let sources = [];
102096
103183
  try {
102097
103184
  sources = engine.listSources({ project: project2 }).sources;
@@ -102107,7 +103194,7 @@ function answerWithGrammar(engine, project2, question, options2 = {}) {
102107
103194
  const name = new Map(sources.map((s) => [s.id, s.name ?? s.id]));
102108
103195
  const answer = run2(text, source);
102109
103196
  if (answer !== void 0) return answer;
102110
- return named ? run2(normalize(question), scope2) ?? null : null;
103197
+ return named ? run2(normalize2(question), scope2) ?? null : null;
102111
103198
  function run2(text2, source2) {
102112
103199
  for (const intent of INTENTS)
102113
103200
  for (const pattern of intent.patterns) {
@@ -103334,7 +104421,7 @@ __export(src_exports3, {
103334
104421
  configPath: () => configPath,
103335
104422
  loadSettings: () => loadSettings,
103336
104423
  nameRepositories: () => nameRepositories,
103337
- normalize: () => normalize,
104424
+ normalize: () => normalize2,
103338
104425
  publicSettings: () => publicSettings,
103339
104426
  repositoryOf: () => repositoryOf,
103340
104427
  saveSettings: () => saveSettings,
@@ -104580,8 +105667,9 @@ Usage:
104580
105667
  the license in force; install a license key (from a file,
104581
105668
  or "-" for stdin); check the installed one again (offline)
104582
105669
  veoflow check [<file|folder>] [--json] [--project <id>]
104583
- the TypeScript compiler's second opinion: each call site
104584
- where it and veoflow disagree, with both answers
105670
+ a reference checker's second opinion (the TypeScript compiler;
105671
+ Pyright for Python): each call site where it and veoflow
105672
+ disagree, with both answers
104585
105673
  veoflow report <file>:<line> [--include-code] [--out <file>] [--force] [--project <id>]
104586
105674
  a bundle to reproduce an analysis bug there (no source code
104587
105675
  unless --include-code); review it before sharing it
@@ -104652,7 +105740,7 @@ function describeCheck(r, cwd, projectFlag) {
104652
105740
  const disagree1 = s1["different-callee"] + s1["adapter-only"] + s1["checker-only"];
104653
105741
  const disagree2 = s2["different-callee"] + s2["checker-only"];
104654
105742
  out.push(
104655
- `checked ${r.source}${r.path ? `:${r.path}` : ""} (${r.files} files) with the TypeScript compiler (scip-typescript)`
105743
+ `checked ${r.source}${r.path ? `:${r.path}` : ""} (${r.files} files) with ${r.checker === "scip-python" ? "Pyright (scip-python)" : "the TypeScript compiler (scip-typescript)"}`
104656
105744
  );
104657
105745
  out.push(
104658
105746
  ` calls within files (Stage 1): ${s1.agree} agree, ${disagree1} disagree; ${s1.outside} resolve outside the source (not compared)`
@@ -105335,7 +106423,7 @@ try: ${answer.suggestions.join(" \xB7 ")}`);
105335
106423
  throw new UsageError("usage: veoflow check [<file|folder>] [--json] [--project <id>]");
105336
106424
  const project2 = pickProject(engine, values.project, io.cwd);
105337
106425
  const path = positionals[0] ?? ".";
105338
- io.err("running the TypeScript compiler over the source (this can take a while)\u2026");
106426
+ io.err("running the reference checker over the source (this can take a while)\u2026");
105339
106427
  const r = await checkCode(engine, { project: project2, path }, io.cwd);
105340
106428
  if (values.json) io.out(JSON.stringify(r, null, 2));
105341
106429
  else for (const line of describeCheck(r, io.cwd, values.project)) io.out(line);