Skip to content

feat: add tilth_deps — file-level dependency analysis#19

Merged
jahala merged 5 commits into
mainfrom
feat/deps-analysis
Mar 7, 2026
Merged

feat: add tilth_deps — file-level dependency analysis#19
jahala merged 5 commits into
mainfrom
feat/deps-analysis

Conversation

@jahala

@jahala jahala commented Mar 6, 2026

Copy link
Copy Markdown
Owner

Summary

New MCP tool tilth_deps for blast-radius checks before breaking changes. One call shows what a file imports and what imports it, replacing 5-10 separate tilth_search kind:callers queries.

  • Uses (local): files this file imports, with which symbols are used from each
  • Uses (external): third-party packages (stdlib filtered out)
  • Used by: downstream files that call this file's exports, with path:line Type.method → symbol format
  • Budget-aware truncation: trims Used by → externals → local symbols → header only

Closes #17

Changes

File What
src/search/deps.rs New: core analyze_deps() + format_deps() with line numbers in used-by
src/mcp.rs Register tilth_deps tool + dispatch + instructions
src/search/mod.rs Add pub mod deps
src/read/imports.rs Make is_external, is_import_line pub(crate)
src/search/callers.rs Make find_callers_batch pub(crate), qualify caller names with enclosing type
Cargo.toml / npm/package.json Bump to 0.4.9

Example output

# Deps: src/session.rs — 0 local, 0 external, 14 dependents

## Used by
src/cache.rs:25                default              → new
src/cache.rs:33                new                  → default
src/mcp.rs:97                  run                  → new, new, new, new
src/mcp.rs:276                 tool_read            → record_read, record_read
src/index/bloom.rs:378         tests.test_basic_membership → new
src/search/deps.rs:178         analyze_deps         → find_callers_batch

[~795 tokens]

Test plan

  • cargo clippy — zero warnings
  • cargo test — all tests pass
  • Tested on core file (callers.rs) — correct local/external/dependents
  • Tested on leaf file — 0 dependents shown correctly
  • Tested barrel file detection (bloom.rs) — cap + note shown
  • Self-references filtered (canonicalized path comparison)
  • Stdlib imports filtered (std::, core::, alloc::)
  • String literal garbage filtered (is_valid_module_path)
  • Type-qualified caller names (e.g. tests.test_basic_membership)
  • Line numbers in used-by output (e.g. src/cache.rs:25)
  • MCP anti-overuse language in tool description and instructions

🤖 Generated with Claude Code

@jahala jahala mentioned this pull request Mar 6, 2026
jahala and others added 2 commits March 6, 2026 23:35
New MCP tool for blast-radius checks before breaking changes.
Shows what a file imports (local + external) and what other files
call its exports, with symbol-level detail. One call replaces
5-10 separate callers searches.

- Add src/search/deps.rs with analyze_deps() and format_deps()
- Wire tilth_deps into MCP dispatch and tool definitions
- Make is_external, is_import_line, find_callers_batch pub(crate)
- Filter stdlib imports and invalid module paths from externals
- Budget-aware truncation (Used by → externals → local symbols)
- Test file grouping (separate "Used by (tests)" section)
- Barrel file detection (cap at 25 symbols with note)
- Bump version to 0.4.8

Closes #17

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Track total_dependents before MAX_DEPENDENTS truncation
- Header now shows real total, not truncated count
- Show "... and N more dependents" when list is capped
- Fix budget Level 3: strip symbols from local deps (was re-joining full lines)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jahala jahala force-pushed the feat/deps-analysis branch from d27f882 to acecf9e Compare March 6, 2026 22:37
jahala and others added 3 commits March 6, 2026 23:58
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Format used-by section as `path:line  Type.method → symbol` instead of
bare function names without location. Carries CallerMatch.line through
Dependent and resolves enclosing type (class, impl, struct) in
find_enclosing_function.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jahala jahala merged commit 48a8460 into main Mar 7, 2026
1 check passed
@jahala jahala deleted the feat/deps-analysis branch March 7, 2026 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: --deps

1 participant