Module imports
Expand description
Architecture import-graph extraction.
Walks each Tier-1 source file at HEAD via tree-sitter, captures
every import statement as a raw (src_path, target, kind) row,
and bulk-inserts into the imports DuckDB table. Mirrors the
shape of crate::clones (per-language dispatch + iterative
cursor walker), so the next behavioural-signal addition can
follow the same module template.
The extractor leaves every row with resolved = false /
target_path = NULL. The companion per-language resolver maps
target → tracked repo path and upgrades those columns in
place. Downstream analyses (layered-architecture rules,
god-class detector, architecture force graph, module chord)
all read against this schema.
Structs§
- RawImport
- One captured import edge — pre-resolution.
Enums§
- Import
Kind - Coarse import semantics. Closed set so the schema’s
CHECKcan validate at INSERT time. - Import
Language - Tier-1 languages
CodeLoreextracts import edges from.
Functions§
- extract_
imports - Parse
sourceunderlang’s grammar and collect every import edge it carries. Returns an empty vec on parse error (logged at warn level) so a single malformed file doesn’t poison the ingest. - resolve_
by_ extension - Resolve an import
targetfromimporter_pathto a tracked path, dispatching to the per-language resolver by the importer’s file extension. ReturnsNonefor extensions without a resolver or for unresolvable targets. The single dispatch point shared by the HEAD ingest (resolve_imports_at_head) and the historical scan (architecture-trend), so language coverage — and which extensions route where — is defined in exactly one place. - resolve_
java - Resolve a Java
importFQN (com.foo.Bar) to a tracked.javafile by matching the package/class path as a unique repo-path suffix (com/foo/Bar.java— Java packages map directly to directories). The match must be unique (zero or more than one candidate yieldsNone) so an ambiguous suffix never fabricates an edge; JDK / third-party imports (java.util.List) have no tracked file and resolve toNone. Wildcard package imports (com.foo.*) name a directory, not a file, and are skipped. A static-member import (com.foo.Bar.baz) or a nested class (com.foo.Outer.Inner) resolves via a single strip-retry to the enclosing class file — the full path is probed first, so a real inner-class file wins before the strip. - resolve_
js_ relative - Resolve a JS/TS relative import target against the live-at-HEAD
path set. Returns the canonical repo-relative path if a match
exists, or
Nonefor unresolvable / external imports. - resolve_
python_ absolute - Resolve an absolute Python module path (
mypkg.utils,os) to a tracked file by matching the dotted path as a repo-path suffix (a/b/c.pyora/b/c/__init__.py) against the live-at-HEAD set — Python has no explicit import root, so the module may live under any source prefix. The match must be unique: zero or more than one candidate yieldsNone, so an ambiguous suffix never fabricates a false edge and stdlib / third-party modules (no tracked file) resolve toNone. - resolve_
python_ relative - Resolve a Python relative-import target (e.g.
.foo.bar,..pkg.x) against the live-at-HEAD path set. Handles bothfrom . import fooandfrom .foo import barshapes via the dot-prefix convention. External imports (no leading dot) returnNone. - resolve_
rust_ path - Resolve a Rust
usepath against the live-at-HEAD set. Handles the conventionalcrate::foo::bar→src/foo/bar.rs|src/foo/bar/mod.rsmapping.self::andsuper::resolve relative to the importer’s module directory (see [module_dir]), which is the siblingfoo/for a non-mod.rsfoo.rs; each leadingsuperclimbs one further level. External crates (anything not starting withcrate::/self::/super::) returnNone.