devlensio 1.1.1 → 1.4.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.
Files changed (64) hide show
  1. package/dist/graph/buildLookup.d.ts +30 -0
  2. package/dist/graph/buildLookup.js +36 -1
  3. package/dist/graph/edges/aliasChain.d.ts +7 -0
  4. package/dist/graph/edges/aliasChain.js +63 -0
  5. package/dist/graph/edges/aliasResolution.test.d.ts +1 -0
  6. package/dist/graph/edges/aliasResolution.test.js +351 -0
  7. package/dist/graph/edges/callEdges.js +178 -18
  8. package/dist/graph/edges/callEdges.test.js +119 -0
  9. package/dist/graph/edges/callOrder.test.d.ts +1 -0
  10. package/dist/graph/edges/callOrder.test.js +227 -0
  11. package/dist/graph/edges/importEdges.js +124 -0
  12. package/dist/graph/edges/propEdges.js +6 -1
  13. package/dist/index.d.ts +1 -0
  14. package/dist/index.js +1 -0
  15. package/dist/parser/callFlow.d.ts +15 -0
  16. package/dist/parser/callFlow.js +302 -0
  17. package/dist/parser/callOrder.test.d.ts +1 -0
  18. package/dist/parser/callOrder.test.js +407 -0
  19. package/dist/parser/declarationIds.d.ts +23 -0
  20. package/dist/parser/declarationIds.js +123 -0
  21. package/dist/parser/exportsMap.js +1 -90
  22. package/dist/parser/extractors/components.js +18 -28
  23. package/dist/parser/extractors/functions.d.ts +21 -1
  24. package/dist/parser/extractors/functions.js +92 -60
  25. package/dist/parser/extractors/moduleScope.d.ts +8 -0
  26. package/dist/parser/extractors/moduleScope.js +80 -0
  27. package/dist/parser/index.js +12 -0
  28. package/dist/parser/moduleScope.test.d.ts +1 -0
  29. package/dist/parser/moduleScope.test.js +176 -0
  30. package/dist/summarizer/index.js +53 -4
  31. package/dist/summarizer/prompts.js +111 -50
  32. package/dist/summarizer/prompts.test.d.ts +1 -0
  33. package/dist/summarizer/prompts.test.js +112 -0
  34. package/dist/types.d.ts +63 -0
  35. package/dist/version.d.ts +1 -0
  36. package/dist/version.js +2 -0
  37. package/extractors/go/bin/darwin-amd64/devlens_go_extractor +0 -0
  38. package/extractors/go/bin/darwin-arm64/devlens_go_extractor +0 -0
  39. package/extractors/go/bin/linux-amd64/devlens_go_extractor +0 -0
  40. package/extractors/go/bin/linux-arm64/devlens_go_extractor +0 -0
  41. package/extractors/go/bin/windows-amd64/devlens_go_extractor.exe +0 -0
  42. package/extractors/go/calls.go +131 -10
  43. package/extractors/go/nodes.go +29 -11
  44. package/extractors/go/parser.go +376 -41
  45. package/extractors/java/devlens_java_extractor.jar +0 -0
  46. package/extractors/java/src/devlens/extractor/Extractor.java +52 -12
  47. package/extractors/java/src/devlens/extractor/LookupMaps.java +2 -0
  48. package/extractors/java/src/devlens/extractor/Parser.java +420 -1
  49. package/extractors/java/src/devlens/extractor/edges/Calls.java +105 -5
  50. package/extractors/python/devlens_extractors_python/edges/calls.py +199 -36
  51. package/extractors/python/devlens_extractors_python/edges/imports.py +21 -1
  52. package/extractors/python/devlens_extractors_python/lookup.py +9 -0
  53. package/extractors/python/devlens_extractors_python/parser/__init__.py +11 -1
  54. package/extractors/python/devlens_extractors_python/parser/functions.py +199 -42
  55. package/extractors/rust/bin/darwin-amd64/devlens_rust_extractor +0 -0
  56. package/extractors/rust/bin/darwin-arm64/devlens_rust_extractor +0 -0
  57. package/extractors/rust/bin/linux-amd64/devlens_rust_extractor +0 -0
  58. package/extractors/rust/bin/linux-arm64/devlens_rust_extractor +0 -0
  59. package/extractors/rust/bin/windows-amd64/devlens_rust_extractor.exe +0 -0
  60. package/extractors/rust/src/calls.rs +114 -8
  61. package/extractors/rust/src/lookup.rs +66 -0
  62. package/extractors/rust/src/nodes.rs +29 -0
  63. package/extractors/rust/src/parser.rs +362 -27
  64. package/package.json +77 -73
@@ -5,9 +5,16 @@ Consumes the shared LookupMaps (lookup.py). Resolution ladder:
5
5
  ClassName.method → same-file dotted lookup
6
6
  alias.member → lazy [pip]/pkg::member node
7
7
  module-alias.walk → submodule walk via module_map
8
- plain name → global nodes_by_name → import alias refinement
9
- Unknown/builtin names resolve to nothing (no edge) — metadata.calls keeps
10
- them for LLM context.
8
+ plain name → own file → import binding → global name
9
+
10
+ Aliasing (added 2026-10): a name at a call site is not always the name of a
11
+ declaration. `from .http import data as httpResponse` and a barrel that only
12
+ re-exports (`__init__.py: from .http import data`) mean the caller writes
13
+ `httpResponse` while the node is `http.py::data`. Python has no compiler symbol
14
+ table, so the chain is walked here by `_resolve_in_module()`: it asks a module
15
+ for a name, and when the module only *binds* that name from somewhere else, it
16
+ follows the binding — cycle-guarded, depth-capped, memo-free (chains are short
17
+ and every hop is an O(1) dict hit).
11
18
 
12
19
  Overload-aware tiebreak (mirrors src/graph/edges/callEdges.ts): when a lookup
13
20
  returns multiple same-name candidates, the call site's argument shape picks
@@ -16,9 +23,22 @@ legacy closest-by-path heuristic. The edge records matchedBy.
16
23
  """
17
24
  from __future__ import annotations
18
25
 
26
+ from dataclasses import dataclass, field
27
+
19
28
  from ..lookup import LookupMaps, closest_by_path, module_name
20
29
  from ..third_party import ThirdPartyRegistry
21
30
 
31
+ # Re-export chains are short in practice; the cap exists so a pathological
32
+ # barrel ring cannot loop. Cycles are also caught by `seen`.
33
+ MAX_ALIAS_HOPS = 24
34
+
35
+
36
+ @dataclass
37
+ class _Scoped:
38
+ """Result of resolving a name against one module's export surface."""
39
+ candidates: list[tuple[str, str]] = field(default_factory=list) # (node_id, rel)
40
+ chain: list[str] = field(default_factory=list) # file::name hops
41
+
22
42
 
23
43
  def _find_in_file(lookup: LookupMaps, rel: str, name: str) -> str | None:
24
44
  return lookup.nodes_by_file.get(rel, {}).get(name)
@@ -30,6 +50,69 @@ def _find_all_in_file(lookup: LookupMaps, rel: str, name: str) -> list[tuple[str
30
50
  return [(node_id, rel) for node_id in ids]
31
51
 
32
52
 
53
+ def _resolve_in_module(lookup: LookupMaps, rel: str, name: str,
54
+ seen: set[tuple[str, str]] | None = None) -> _Scoped:
55
+ """Resolve `name` against the EXPORT SURFACE of module `rel`.
56
+
57
+ In Python a module's namespace is its declarations PLUS everything it
58
+ imported, so `from pkg import name` works whenever `name` is a module-level
59
+ attribute of `pkg` — including names `pkg` itself imported from elsewhere.
60
+ That is exactly how a package re-exports a symbol (`__init__.py`), and it is
61
+ the phenomenon this resolver models:
62
+
63
+ 1. declared here → the node
64
+ 2. `Alias.member` where Alias is bound → resolve Alias, then the member
65
+ 3. bound by an import → recurse into the binding's target
66
+ 4. `from .x import *` sources → recurse with the same name
67
+ """
68
+ seen = seen if seen is not None else set()
69
+ key = (rel, name)
70
+ if key in seen or len(seen) >= MAX_ALIAS_HOPS:
71
+ return _Scoped()
72
+ seen.add(key)
73
+
74
+ # 1. a declaration in this module (dotted names included: "Class.method")
75
+ declared = _find_all_in_file(lookup, rel, name)
76
+ if declared:
77
+ return _Scoped(declared, [f"{rel}::{name}"])
78
+
79
+ symbols = lookup.symbol_maps.get(rel, {})
80
+ names = lookup.symbol_names.get(rel, {})
81
+
82
+ # 2. member access on a bound name: `US.get` → resolve `US`
83
+ if "." in name:
84
+ root, suffix = name.split(".", 1)
85
+ binding = symbols.get(root)
86
+ if binding and binding.startswith("file::"):
87
+ original = names.get(root, root)
88
+ deeper = _resolve_in_module(lookup, binding[len("file::"):],
89
+ f"{original}.{suffix}", seen)
90
+ if deeper.candidates:
91
+ return _Scoped(deeper.candidates, [f"{rel}::{name}"] + deeper.chain)
92
+ return _Scoped()
93
+
94
+ # 3. a module-level binding created by an import — the re-export hop
95
+ binding = symbols.get(name)
96
+ if binding:
97
+ original = names.get(name, name)
98
+ if binding.startswith("file::"):
99
+ deeper = _resolve_in_module(lookup, binding[len("file::"):], original, seen)
100
+ if deeper.candidates:
101
+ return _Scoped(deeper.candidates, [f"{rel}::{name}"] + deeper.chain)
102
+ return _Scoped()
103
+ # third-party node id or a direct node id — nothing to walk
104
+ origin_rel = lookup.node_by_id.get(binding, {}).get("filePath", rel)
105
+ return _Scoped([(binding, origin_rel)], [f"{rel}::{name}"])
106
+
107
+ # 4. star imports copy public names into this namespace
108
+ for star_rel in lookup.star_imports.get(rel, []):
109
+ deeper = _resolve_in_module(lookup, star_rel, name, seen)
110
+ if deeper.candidates:
111
+ return _Scoped(deeper.candidates, [f"{rel}::{name}"] + deeper.chain)
112
+
113
+ return _Scoped()
114
+
115
+
33
116
  def _bound_params(node: dict) -> tuple[list, list]:
34
117
  """(effective_params, effective_parameters) for arity/type matching —
35
118
  bound methods hide self/cls from the call site's argument count."""
@@ -114,9 +197,22 @@ def _pick(candidates: list[tuple[str, str]], node: dict, call_site: dict | None,
114
197
  return closest_by_path(pool, rel), "name"
115
198
 
116
199
 
117
- def _walk_module(lookup: LookupMaps, alias_target: str, rest: str) -> list[tuple[str, str]]:
200
+ def _pick3(candidates: list[tuple[str, str]], node: dict, call_site: dict | None,
201
+ lookup: LookupMaps, rel: str, chain: list[str]) -> tuple[str | None, str, list[str]]:
202
+ """_pick() plus the alias chain — the shape _resolve() returns."""
203
+ target, matched_by = _pick(candidates, node, call_site, lookup, rel)
204
+ return target, matched_by, chain
205
+
206
+
207
+ def _walk_module(lookup: LookupMaps, alias_target: str, rest: str,
208
+ root_hint: str | None = None) -> _Scoped:
118
209
  """'user.User' with alias → file::models/__init__.py: consume submodule
119
- segments via module_map, then look up the symbol in the final file."""
210
+ segments via module_map, then resolve the symbol in the final module's
211
+ export surface (which may itself re-export it).
212
+
213
+ `root_hint` is what the alias was called at the source
214
+ (`from .services import UserService as US` → "UserService"), so a member
215
+ call `US.get()` resolves to the dotted node `UserService.get`."""
120
216
  current_rel = alias_target[len("file::"):]
121
217
  current_module = module_name(current_rel)
122
218
  segments = rest.split(".")
@@ -130,21 +226,29 @@ def _walk_module(lookup: LookupMaps, alias_target: str, rest: str) -> list[tuple
130
226
  current_rel, current_module = nxt, candidate
131
227
  consumed += 1
132
228
 
133
- return _find_all_in_file(lookup, current_rel, ".".join(segments[consumed:]))
229
+ tail = ".".join(segments[consumed:])
230
+ if root_hint and consumed == 0 and tail:
231
+ scoped = _resolve_in_module(lookup, current_rel, f"{root_hint}.{tail}")
232
+ if scoped.candidates:
233
+ return scoped
234
+ return _resolve_in_module(lookup, current_rel, tail)
134
235
 
135
236
 
136
237
  def _resolve(called: str, node: dict, lookup: LookupMaps,
137
- registry: ThirdPartyRegistry, call_site: dict | None) -> tuple[str | None, str]:
238
+ registry: ThirdPartyRegistry,
239
+ call_site: dict | None) -> tuple[str | None, str, list[str]]:
138
240
  rel = node["filePath"]
139
241
  symbols = lookup.symbol_maps.get(rel, {})
242
+ symbol_names = lookup.symbol_names.get(rel, {})
140
243
 
141
244
  # ── 1. self.x() / cls.x() → method of the enclosing class ──
142
245
  if called.startswith(("self.", "cls.")):
143
246
  parent_class = node["metadata"].get("parentClass")
144
247
  if parent_class:
145
- return _pick(_find_all_in_file(lookup, rel, f"{parent_class}.{called.split('.', 1)[1]}"),
146
- node, call_site, lookup, rel)
147
- return None, "name"
248
+ return _pick3(_find_all_in_file(lookup, rel,
249
+ f"{parent_class}.{called.split('.', 1)[1]}"),
250
+ node, call_site, lookup, rel, [])
251
+ return None, "name", []
148
252
 
149
253
  # ── 2. dotted name ──
150
254
  if "." in called:
@@ -152,40 +256,63 @@ def _resolve(called: str, node: dict, lookup: LookupMaps,
152
256
 
153
257
  # 2a. ClassName.method defined in the same file
154
258
  if root in lookup.nodes_by_file.get(rel, {}):
155
- return _pick(_find_all_in_file(lookup, rel, called),
156
- node, call_site, lookup, rel)
259
+ return _pick3(_find_all_in_file(lookup, rel, called),
260
+ node, call_site, lookup, rel, [])
157
261
 
158
- # 2b. member access through an import alias
159
262
  alias_target = symbols.get(root)
160
263
  if not alias_target:
161
- return None, "name"
264
+ # 2c. the root itself may be re-exported into THIS module
265
+ scoped = _resolve_in_module(lookup, rel, called)
266
+ if scoped.candidates:
267
+ return _pick3(scoped.candidates, node, call_site, lookup, rel, scoped.chain)
268
+ return None, "name", []
269
+
162
270
  if alias_target.startswith("[pip]/"):
163
271
  # third-party chain: requests.get → lazily create [pip]/requests::get
164
272
  pkg = alias_target.split("/", 1)[1]
165
273
  if "::" in pkg:
166
274
  # chain root is already a named import — current_app.logger.info
167
275
  # → [pip]/flask::current_app (the meaningful hop)
168
- return alias_target, "name"
276
+ return alias_target, "name", []
169
277
  member = registry.method_node(pkg, rest.split(".")[0])
170
- return (member["id"] if member else None), "name"
171
- if alias_target.startswith("file::"):
172
- return _pick(_walk_module(lookup, alias_target, rest),
173
- node, call_site, lookup, rel)
174
- return None, "name"
175
-
176
- # ── 3. plain name — global lookup, overload ladder on collision ──
177
- candidates = lookup.nodes_by_name.get(called)
178
- if candidates:
179
- return _pick(candidates, node, call_site, lookup, rel)
278
+ return (member["id"] if member else None), "name", []
180
279
 
181
- # ── 4. import alias — refine file targets to the actual symbol ──
280
+ if alias_target.startswith("file::"):
281
+ # 2b. member access through an import alias — resolve against the
282
+ # target module's export surface (follows re-export chains)
283
+ scoped = _walk_module(lookup, alias_target, rest, symbol_names.get(root))
284
+ if scoped.candidates:
285
+ return _pick3(scoped.candidates, node, call_site, lookup, rel, scoped.chain)
286
+ return None, "name", []
287
+
288
+ # ── 3. plain name ──
289
+ # 3a. declared in the caller's own file (exact, no guessing)
290
+ local = _find_all_in_file(lookup, rel, called)
291
+ if local:
292
+ return _pick3(local, node, call_site, lookup, rel, [])
293
+
294
+ # 3b. imported into this file → the target module's export surface
182
295
  alias_target = symbols.get(called)
183
296
  if alias_target:
184
297
  if alias_target.startswith("file::"):
185
- return _pick(_find_all_in_file(lookup, alias_target[len("file::"):], called),
186
- node, call_site, lookup, rel)
187
- return alias_target, "name" # "[pip]/..." or "path.py::Symbol"
188
- return None, "name"
298
+ scoped = _resolve_in_module(lookup, alias_target[len("file::"):], called)
299
+ if scoped.candidates:
300
+ return _pick3(scoped.candidates, node, call_site, lookup, rel, scoped.chain)
301
+ return None, "name", []
302
+ # direct node id ("path.py::Symbol" or a third-party id, e.g. decorators)
303
+ return alias_target, "name", []
304
+
305
+ # 3c. global name — overload ladder on collision
306
+ candidates = lookup.nodes_by_name.get(called)
307
+ if candidates:
308
+ return _pick3(candidates, node, call_site, lookup, rel, [])
309
+
310
+ # 3d. copied into this namespace by `from .x import *`
311
+ scoped = _resolve_in_module(lookup, rel, called)
312
+ if scoped.candidates:
313
+ return _pick3(scoped.candidates, node, call_site, lookup, rel, scoped.chain)
314
+
315
+ return None, "name", []
189
316
 
190
317
 
191
318
  def resolve_calls(lookup: LookupMaps, registry: ThirdPartyRegistry) -> list[dict]:
@@ -196,18 +323,54 @@ def resolve_calls(lookup: LookupMaps, registry: ThirdPartyRegistry) -> list[dict
196
323
  edges: list[dict] = []
197
324
 
198
325
  for node in lookup.node_by_id.values():
199
- if node["type"] not in ("FUNCTION", "METHOD"):
326
+ # FILE nodes are callers for module-scope execution (calls run at
327
+ # import time, attached by parser/__init__.py). TEST leaves excluded.
328
+ if node["type"] not in ("FUNCTION", "METHOD", "FILE"):
200
329
  continue
201
330
  metadata = node["metadata"]
202
331
  sites = metadata.get("callSites") or [{"name": c} for c in metadata.get("calls", [])]
203
- resolved: list[dict] = []
332
+ # One record per target, first-seen order, shaped exactly like ResolvedCall
333
+ # in src/types.ts: name is the DECLARATION name, firstOrder the first
334
+ # position that reached it, orders carries the repeat positions.
335
+ resolved: dict[str, dict] = {}
336
+ orders_by_target: dict[str, list[int]] = {}
204
337
  for site in sites:
205
338
  called = site["name"]
206
- target, matched_by = _resolve(called, node, lookup, registry, site)
339
+ target, matched_by, chain = _resolve(called, node, lookup, registry, site)
207
340
  if target and target != node["id"]:
341
+ edge_meta = {"calledName": called, "matchedBy": matched_by}
342
+ origin = lookup.node_by_id.get(target, {})
343
+ origin_name = origin.get("name")
344
+ if origin_name and origin_name != called:
345
+ # what the graph edge actually points at (alias → origin)
346
+ edge_meta["resolvedName"] = origin_name
347
+ edge_meta["aliased"] = True
348
+ if chain and len(chain) > 1:
349
+ edge_meta["aliasChain"] = chain
350
+ if node["type"] == "FILE":
351
+ edge_meta["scope"] = "module"
208
352
  edges.append({"from": node["id"], "to": target, "type": "CALLS",
209
- "metadata": {"calledName": called, "matchedBy": matched_by}})
210
- resolved.append({"name": called, "nodeId": target})
211
- metadata["resolvedCalls"] = resolved
353
+ "metadata": edge_meta})
354
+
355
+ order = site.get("order")
356
+ if isinstance(order, int):
357
+ orders_by_target.setdefault(target, []).append(order)
358
+ if target not in resolved:
359
+ record = {"name": origin_name or called, "nodeId": target}
360
+ if isinstance(order, int):
361
+ record["firstOrder"] = order
362
+ line = site.get("line")
363
+ if isinstance(line, int):
364
+ record["line"] = line
365
+ for marker in ("defer", "deferDetail", "awaited", "conc", "repeat", "maybe"):
366
+ value = site.get(marker)
367
+ if value:
368
+ record[marker] = value
369
+ resolved[target] = record
370
+ for target, orders in orders_by_target.items():
371
+ unique = sorted(set(orders))
372
+ if len(unique) > 1:
373
+ resolved[target]["orders"] = unique
374
+ metadata["resolvedCalls"] = list(resolved.values())
212
375
 
213
376
  return edges
@@ -81,6 +81,14 @@ def resolve_file_imports(parsed: ParsedFile, lookup: LookupMaps,
81
81
  rel = parsed.rel_path
82
82
  file_id = parsed.file_node["id"]
83
83
  file_symbols: dict[str, str] = {}
84
+ # local alias → the name it was imported AS in the source module
85
+ # (`from .http import data as httpResponse` → {"httpResponse": "data"}).
86
+ # Without it a re-export chain cannot be followed: symbol_maps only knows
87
+ # the destination file, not what to look for once we get there.
88
+ file_names: dict[str, str] = {}
89
+ # `from .x import *` sources — Python copies public names into the module
90
+ # namespace, so these participate in the export surface.
91
+ star_sources: list[str] = []
84
92
  edges: list[dict] = []
85
93
  imported_paths: list[str] = []
86
94
  module_map = lookup.module_map
@@ -101,6 +109,7 @@ def resolve_file_imports(parsed: ParsedFile, lookup: LookupMaps,
101
109
  sub = module_map.get(f"{module}.{item.name}")
102
110
  if sub:
103
111
  file_symbols[item.alias] = f"file::{sub}"
112
+ file_names[item.alias] = item.alias
104
113
  imported_paths.append(sub)
105
114
  edges.append({"from": file_id, "to": f"file::{sub}", "type": "IMPORTS",
106
115
  "metadata": {"importPath": module, "importedName": item.name}})
@@ -113,7 +122,10 @@ def resolve_file_imports(parsed: ParsedFile, lookup: LookupMaps,
113
122
  imported_paths.append(target_rel)
114
123
 
115
124
  if item.is_star:
116
- # Can't know which names — edge to the module file, tag ambiguous
125
+ # Can't know which names — edge to the module file, tag ambiguous.
126
+ # The source is recorded so name resolution can still fall
127
+ # through to it (Python copies public names into the namespace).
128
+ star_sources.append(target_rel)
117
129
  edges.append({"from": file_id, "to": target_file_id, "type": "IMPORTS",
118
130
  "metadata": {"importPath": module, "isStarImport": True}})
119
131
  continue
@@ -126,6 +138,10 @@ def resolve_file_imports(parsed: ParsedFile, lookup: LookupMaps,
126
138
  imported_paths.append(sub)
127
139
 
128
140
  file_symbols[item.alias] = target_file_id
141
+ # What this binding is called inside the target module — the next
142
+ # link of a re-export chain (`from .index import httpResponse`
143
+ # where index.py did `from .http import data as httpResponse`).
144
+ file_names[item.alias] = item.name or item.alias
129
145
  edges.append({"from": file_id, "to": target_file_id, "type": "IMPORTS",
130
146
  "metadata": {"importPath": module,
131
147
  "importedName": item.name}})
@@ -152,4 +168,8 @@ def resolve_file_imports(parsed: ParsedFile, lookup: LookupMaps,
152
168
  "importedName": item.name}})
153
169
 
154
170
  symbol_map[rel] = file_symbols
171
+ if file_names:
172
+ lookup.symbol_names[rel] = file_names
173
+ if star_sources:
174
+ lookup.star_imports[rel] = star_sources
155
175
  return edges, sorted(set(imported_paths))
@@ -29,6 +29,15 @@ class LookupMaps:
29
29
  file_nodes_by_path: dict[str, dict] = field(default_factory=dict)
30
30
  # rel_path → {local alias → target id} — import precision (edges.imports writes)
31
31
  symbol_maps: dict[str, dict[str, str]] = field(default_factory=dict)
32
+ # rel_path → {local alias → ORIGINAL imported name}. `symbol_maps` says
33
+ # WHERE a name came from; this says WHAT it was called there, which is what
34
+ # makes `from .http import data as httpResponse` chains resolvable
35
+ # (edges.imports writes).
36
+ symbol_names: dict[str, dict[str, str]] = field(default_factory=dict)
37
+ # rel_path → [rel_path] for `from .x import *` sources. Python's star import
38
+ # copies public names into the module namespace, so a barrel that only does
39
+ # `from .inner import *` still re-exports (edges.imports writes).
40
+ star_imports: dict[str, list[str]] = field(default_factory=dict)
32
41
  # dotted module name → rel path (imports.build_module_map builds)
33
42
  module_map: dict[str, str] = field(default_factory=dict)
34
43
 
@@ -12,7 +12,7 @@ from pathlib import Path
12
12
 
13
13
  from ..contract import code_hash, file_node
14
14
  from .classes import extract_class
15
- from .functions import extract_function
15
+ from .functions import extract_function, extract_calls_with_sites
16
16
  from .overloads import apply_overload_disambiguation
17
17
  from .walker import is_test_file, walk_python_files
18
18
 
@@ -70,6 +70,16 @@ def parse_file(repo_path: str, rel_path: str) -> ParsedFile:
70
70
  else:
71
71
  file_node_["metadata"]["nodeCount"] = len(children)
72
72
  file_node_["metadata"]["childNodeIds"] = [c["id"] for c in children]
73
+
74
+ # Module-scope calls (executed at import time) belong to the FILE node.
75
+ # The walk already refuses to descend into defs/classes/lambdas, so
76
+ # running it on the module body yields exactly the top-level calls;
77
+ # module_scope marks their callOrder/v1 scope as "module".
78
+ module_calls, module_sites = extract_calls_with_sites(tree.body, module_scope=True)
79
+ if module_sites:
80
+ file_node_["metadata"]["calls"] = module_calls
81
+ file_node_["metadata"]["callSites"] = module_sites
82
+
73
83
  joined = "\n".join(c.get("rawCode", "") for c in children)
74
84
  if joined.strip():
75
85
  file_node_["codeHash"] = code_hash(joined)