Skip to main content

6. Dependency Intelligence

Batho's dependency subsystem resolves and indexes third-party and standard-library dependencies across 34 languages and config formats (27 tree-sitter grammars plus 7 native format parsers). It populates the scope manager with resolved symbols, enabling cross-file reference resolution and external symbol entity creation. Stdlib symbol tables cover 28 languages and live introspection covers 20 package ecosystems with an offline install store — Python, npm, Cargo, Go, Maven, Gradle, Ruby gems, Composer, NuGet, Dart pub, Julia, CRAN, cabal, Swift SPM, zigmod, rebar3, opam, luarocks, CPAN, and Agda .agda-lib.

6.1 Indexing Pipeline​

The dependency indexer orchestrates a five-stage pipeline that transforms raw manifest files into a fully populated scope manager:

Figure 29: Dependency Indexing Pipeline — Five-stage flow from manifest discovery through scope manager population.

Per-Dependency Gate Chain​

Every unique declared dependency (manager, name, version_spec) passes through a pinned gate order and reaches exactly one terminal bucket:

① cache hit → deps_cached
② popular full_scan=false and not in popular DB → deps_gate_dropped
③ managers disabled by introspection.managers → deps_manager_disabled
â‘£ route no offline store (bash, verilog, c,
cpp, objc, agda) → deps_no_ecosystem
⑤ env skip_missing_env (default true) and
env not found → deps_skipped_no_env
⑥ introspect symbols found → deps_introspected
none found → deps_no_symbols

full_scan contract: true attempts every declared dep (subject to gates ③④⑤); false attempts only popular-DB members. full_scan is the only declared-dep bypass. Gate ② runs before ④, so a non-popular no-ecosystem dep counts as gate_dropped when full_scan=false and as no_ecosystem when full_scan=true.

Completeness invariant (asserted after every indexing run, log-only warning introspection_accounting_mismatch on violation):

deps_unique = deps_cached + deps_gate_dropped + deps_manager_disabled
+ deps_no_ecosystem + deps_skipped_no_env
+ deps_introspected + deps_no_symbols

Pipeline Statistics​

Pipeline statistics track metrics throughout the process:

MetricDescription
manifests_foundNumber of manifest files detected
deps_declaredTotal dependencies parsed from manifests (raw rows)
deps_uniqueUnique (manager, name, version_spec) dependency identities
deps_cachedDependencies resolved from cache (no introspection needed)
deps_introspectedDependencies resolved via live introspection
deps_gate_droppedDependencies dropped by the popular-DB gate (only when full_scan=false)
deps_manager_disabledDependencies rejected by per-manager config overrides
deps_skipped_no_envDependencies skipped because their env/store was not found (skip policy)
deps_no_symbolsDependencies attempted but yielding no symbols
deps_no_ecosystemDependencies on languages with no offline package store
symbols_indexedTotal symbols added to ScopeManager
stdlib_modules_indexedStandard library modules indexed
duration_msTotal pipeline execution time
errorsNon-fatal errors encountered

6.2 Manifest Parser​

The manifest parser detects and parses dependency manifest files across seven package ecosystems:

EcosystemManifest FilesPackage Manager
Pythonrequirements*.txt, pyproject.toml, Pipfilepip, poetry, setuptools
JavaScript/TypeScriptpackage.jsonnpm, yarn, pnpm
RustCargo.tomlcargo
Gogo.modgo modules
Java (JVM)build.gradle, pom.xmlgradle, maven

DependencySpec​

Each parsed dependency is returned as a structured specification:

FieldTypeExample
namestr"requests", "express", "tokio"
version_specstr">=2.28.0", "^1.2.3", "*"
managerPackageManagerPIP, NPM, CARGO, GO, GRADLE, MAVEN
languagestr"python", "javascript", "rust", "go", "java"
source_filestrRelative path to the manifest file

The parser uses pre-compiled regex patterns for each manifest format, ensuring high throughput on large monorepos with many manifest files.


6.3 Standard Library Symbol Tables​

Batho ships with curated, static symbol tables for standard libraries that ship with each language runtime. These are bundled directly with Batho and require no network access. As of v1.4.0, stdlib tables cover 27 languages.

LanguageModules CoveredExample Symbols
Pythonjson, os, os.path, pathlib, re, datetime, sys, typing, collections, math, time, threading, subprocess, loggingdumps, Path, compile, Thread
JavaScriptfs, path, http, https, crypto, stream, events, os, util, processreadFile, join, createServer
TypeScriptfs, path, http, crypto, stream, eventsreadFile, join, createServer
Gofmt, strings, io, net/http, encoding/json, os, timePrintln, Reader, HandleFunc
Ruststd::collections, std::io, std::fs, std::pathHashMap, Read, PathBuf
Cstdio, stdlib, string, math, timeprintf, malloc, strcpy
C++std::vector, std::string, std::map, std::iostream, std::algorithmvector, string, sort
Javajava.util, java.io, java.netList, InputStream, Socket
RubyEnumerable, File, Dir, JSON, Net::HTTPeach, open, parse
C#System, System.IO, System.Collections, System.NetConsole, File, List
PHPstdClass, array, string, json, curljson_encode, curl_init
Kotlinkotlin.collections, kotlin.io, kotlin.textlistOf, println, split
SwiftFoundation, Swift, Dispatch, CombineURL, Data, Task
Scalascala.collection, scala.io, scala.utilList, Map, Try
Dartdart:core, dart:io, dart:convert, dart:asyncList, File, jsonDecode
HaskellPrelude, Data.List, Data.Map, System.IOmap, filter, foldr
Luatable, string, math, io, osinsert, format, open
Rbase, stats, utils, graphicsc, mean, plot
Perlstrict, warnings, File::Spec, JSONbless, catfile
JuliaBase, Stdlib, LinearAlgebra, Datespush!, length, Date
Zigstd, std.mem, std.io, std.fsalloc, print, open
Bashbuiltin, test, read, echoecho, read, test
Objective-CFoundation, UIKit, CoreFoundationNSObject, NSString
Erlangerlang, lists, io, oslength, foreach, format
OCamlStdlib, List, Map, Stringmap, fold, length
HackHH\\Lib\\C, HH\\Lib\\Str, HH\\Lib\\Vecmap, filter, length
Verilog$display, $finish, $monitordisplay, finish

Languages with lighter stdlib coverage (e.g. Bash, Verilog) register their built-in functions and pragmas so that imports are tracked even when full module hierarchies are not applicable.


The popular packages database is a bundled catalog covering the top third-party packages across five ecosystems. It uses set-based lookup for O(1) performance and caches package name sets in memory.

  • Singleton pattern: Avoids reloading the catalog across multiple indexer invocations.
  • Configurable path: Can be overridden via the BATHO_POPULAR_PACKAGES_PATH environment variable.
  • Default location: Bundled with Batho's built-in data files.

When a declared dependency is found in the popular packages database, its symbols are loaded from the curated set without requiring live introspection, significantly reducing indexing time for common packages.


6.5 Third-Party Introspector​

The third-party introspector performs live introspection of installed third-party packages across every ecosystem with an offline install store. It is subprocess-isolated to maintain Batho's zero-code-execution guarantee on untrusted code — the introspected packages are the developer's own installed dependencies, not the analyzed source code.

Supported Ecosystems​

EcosystemIntrospectorEnvironmentMethod
Pythonintrospect_pythonProject venv (.venv/venv/env)dir() + inspect in subprocess
npmintrospect_npmnode_modules/ (walk-up)Parse package.json exports + .d.ts
Cargointrospect_crateCARGO_HOME → ~/.cargo/registry/Parse pub items from crate source
Gointrospect_go_moduleGOPATH → ~/go/pkg/mod/Parse exported declarations
Mavenintrospect_jar~/.m2/repository/Parse -sources.jar / binary jar entries
Gradleintrospect_jarGRADLE_USER_HOME → ~/.gradle/caches/modules-2Same jar parsing (covers Kotlin/Scala)
Ruby gemsintrospect_gemGEM_HOME/BUNDLE_PATH → ~/.gem → gem env gemdirParse module/class/def from lib/**/*.rb
Composer (PHP/Hack)introspect_composervendor/ (walk-up)PSR-4 + namespace-qualified class extraction
NuGet (C#)introspect_nugetNUGET_PACKAGES → ~/.nuget/packagesXML doc T: members; .nuspec fallback
Dart pubintrospect_pub.dart_tool/package_config.json → PUB_CACHEParse lib/**/*.dart declarations
Juliaintrospect_juliaJULIA_DEPOT_PATH → ~/.juliaexport lists (explicit API) + defs
R (CRAN)introspect_cranrenv library → R_LIBS_USER → platform defaultNAMESPACE export() directives
Haskell (cabal)introspect_cabal~/.cabalexposed-modules:; ghc-pkg fallback
Swift SPMintrospect_spm.build/checkouts (walk-up)public/open declarations
Zig (zigmod)introspect_zigmod.zigmod/deps → zig global cachepub declarations; zon .name matching
Erlang (rebar3)introspect_rebar3_build/default/lib (walk-up)-export([...]). lists + -module
OCaml (opam)introspect_opamOPAMROOT → ~/.opam.mli interfaces (val/type/module)
Lua (luarocks)introspect_luarocksLUAROCKS → ~/.luarocksfunction M.f-style module tables
Perl (cpan)introspect_cpanPERL5LIB → ~/perl5/lib/perl5package + sub from .pm files

Languages without an offline package store (bash, verilog, c, cpp, objc, agda) have no introspector by design — the bundled stdlib tables are their coverage story, and their deps are classified as no_ecosystem rather than stubbed.

Skip-When-Env-Missing Policy​

When a dependency's environment cannot be resolved (no venv, no node_modules, no user package store), the dependency is skipped:

  • No introspection attempt is made (the env check happens before thread-pool submission).
  • No fallback {name: [name]} stub symbols are registered — stubs inflate resolution metrics with unresolvable package-name symbols.
  • The resolution cache is never written for skipped deps.
  • The build stats expose skipped_no_env, and one warning per manager is logged with a hint.

This policy is controlled by dependency.introspection.skip_missing_env (default true). Python specifically never falls back to Batho's own interpreter (sys.executable) — introspecting the wrong environment produces symbols that cannot resolve and is worse than no symbols.

Python Introspection Modes​

ModeBehaviorUse Case
shallowLists public symbols via dir() + inspectFast indexing, default mode
deepRecursively inspects classes and module hierarchyComprehensive symbol extraction

Safety guarantees:

  • Runs in a subprocess with a timeout (default: 5 seconds).
  • Uses a pre-compiled script template injected with the package name.
  • Extracts only public symbols (filters _-prefixed names).
  • All package/module/crate names are validated with _is_safe_dependency_name before any filesystem path is constructed, preventing traversal attacks outside the package cache.
  • Reports failures as non-fatal errors; unresolved packages are tagged as unresolved: in the graph.

6.6 Resolution Cache​

The resolution cache provides a flat-file msgpack cache for indexed dependency symbols, avoiding redundant introspection on subsequent builds.

PropertyValue
KeySHA-256 hash of (package_name, version, manager)
Formatmsgpack flat-file under .batho/cache/dep/
Indexdep_manifests.idx — manifest-level metadata index
Thread safetyRLock for concurrent access
TTL90 days (configurable)

The cache is checked before live introspection. On cache hit, symbols are loaded directly from the msgpack file, reducing indexing time by 80–95% for repositories with stable dependencies.