依赖分析工具

dependency-buster是一个通用的代码库依赖分析工具,支持多种编程语言,提供依赖跟踪、安全审计、许可证合规等功能,适用于开发效率提升和安全合规检查。

  • by Kedson
  • HTML
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 Kedson/dependency-buster

使用说明

依赖性克星

适用于任何代码库的通用依赖性分析器•TypeScript、Go和Rust中的MCP Server实现

最新版本: v1.1.1 -文档渲染修复(TypeScript和Go)

📖 文档:


特性

  • 通用语言支持 -分析PHP、JavaScript、TypeScript、Python、Go、Rust、Java、Ruby、C#等
  • 相关性分析 -使用版本解析进行生产和开发依赖性跟踪
  • 安全审计 -跨包生态系统的漏洞检测
  • 许可证合规性 -跟踪和验证依赖许可证是否符合法律要求
  • 命名空间检测 -代码结构和模块分析
  • 三重实施 -选择TypeScript(简单)、Go(快速)或Rust(最快)
  • 漂亮的仪表板 -受包豪斯启发的图表和树木可视化
  • CLI报告 -用于CI/CD管道的ASCII风格终端输出

快速开始

1.克隆和构建

git clone https://github.com/your-username/dependency-buster.git
cd dependency-buster

# Build all implementations
./build-all.sh

存储库选择:

构建脚本将提示您选择测试存储库:

# Interactive mode (will prompt)
./build-all.sh
# Enter repository URL or press Enter for default (AzuraCast)

# Non-interactive mode (uses environment variable)
TEST_REPO_URL=https://github.com/myorg/myproject.git ./build-all.sh

# Non-interactive mode (uses default)
echo "" | ./build-all.sh  # Pipes empty input to auto-select default

或者单独构建:

# TypeScript
cd dpb-mcp-typescript && npm install && npm run build

# Go
cd dpb-mcp-go && make build

# Rust  
cd dpb-mcp-rust && cargo build --release

2.运行分析

# Analyze current directory
cd your-project
/path/to/dependency-buster/dpb-benchmark/scripts/run-benchmark.sh .

# Analyze specific project
/path/to/dependency-buster/dpb-benchmark/scripts/run-benchmark.sh /path/to/project

3.查看结果

# Open the generated dashboard
open dpb-benchmark/dashboard/index.html

# Or view terminal report (generated automatically)

实现

实施 速度 大小 最适合
TypeScript ★★★ 0.01 MB 快速设置,熟悉的生态系统
去 ★★★★★ 6 MB 生产工作负载,Go shops
锈 ★★★★★ 2.6 MB 最高性能,内存安全

性能基准

度量 TypeScript Go Rust
启动时间 ~430ms ~177ms ~176ms
相关性分析 ~570ms ~164ms ~140ms
命名空间检测 ~1160毫秒 ~389毫秒 ~381毫秒
安全审计 ~709毫秒 ~206毫秒 ~191毫秒

IDE集成

依赖关系清除器适用于任何与MCP兼容的IDE或工具:

光标IDE

{
  "mcpServers": {
    "dependency-buster": {
      "command": "node",
      "args": ["/path/to/dpb-mcp-typescript/build/server.js"]
    }
  }
}

Claude 代码命令行界面

{
  "dependency-buster": {
    "command": "/path/to/dpb-mcp-go/build/dpb-mcp"
  }
}

临床扩展

{
  "mcpServers": {
    "dependency-buster": {
      "command": "/path/to/dpb-mcp-rust/target/release/dpb-mcp"
    }
  }
}

看 IDE_INTEGRATION.md 有关完整的设置说明


可用工具(共15个)

岩心分析工具

# 工具 说明
1 analyze_dependencies 具有生产/开发细分和树可视化的全面依赖性分析
2 analyze_psr4 PSR-4自动加载分析和命名空间合规性验证
3 detect_namespaces 检测代码库中的所有命名空间和模块结构
4 analyze_namespace_usage 分析整个代码库中特定命名空间的使用情况
5 generate_dependency_graph 生成依存关系的Mermaid图
6 audit_security 审计安全漏洞和过时软件包的依赖关系
7 analyze_licenses 分析跨依赖关系的许可证分发和兼容性
8 find_circular_dependencies 在包图中查找循环依赖链
9 analyze_multi_repo 分析多个存储库之间的依赖关系
10 generate_comprehensive_docs 为存储库生成全面的markdown文档
11 generate_mkdocs_docs 生成具有多文件结构、导航和更改日志的MkDocs兼容文档网站

跟踪和AI代理工具

# 工具 说明
11 track_dependencies 创建带有时间戳的依赖关系快照,以跟踪随时间的变化
12 get_dependency_history 获取包含时间戳、最近添加/更新和过时包的依赖关系历史记录
13 check_compliance 检查合规性问题的依赖关系(许可证、过时、已弃用)
14 get_agent_suggestions 为AI代理(Cursor、Cline、Claude Code)获取有关依赖性问题的结构化建议

MCP工具注释

所有工具都包括企业注释:

{
  readOnlyHint: true,      // Doesn't modify files
  idempotentHint: true,    // Same result on repeated calls
  cacheTtlSeconds: 300,    // Cache results for 5 minutes
  tags: ["analysis", "dependencies", "security"]
}

建筑

dependency-buster/
├── dpb-mcp-typescript/    # TypeScript implementation
│   ├── src/
│   │   ├── server.ts               # MCP server entry
│   │   ├── tools/                  # Analysis tools
│   │   ├── errors.ts               # Typed errors
│   │   ├── annotations.ts          # Tool annotations
│   │   └── auth.ts                 # Authentication
│   └── build/
│
├── dpb-mcp-go/          # Go implementation
│   ├── cmd/server/main.go
│   └── pkg/
│       ├── mcp/                    # MCP protocol
│       └── analyzer/               # Analysis tools
│
├── dpb-mcp-rust/        # Rust implementation
│   └── src/
│       ├── main.rs
│       ├── mcp/                    # MCP protocol
│       └── analyzer/               # Analysis tools
│
└── dpb-benchmark/              # Benchmark suite
    ├── scripts/run-benchmark.sh    # Main runner
    ├── dashboard/index.html        # Visualization
    └── results/                    # Generated reports

企业功能

所有实现都支持:

特性 描述
键入错误 NotFoundError、ValidationError、AuthenticationError
认证 静态令牌通过 MCP_TOKEN 环境变量
HTTP传输 SSE流媒体用于远程访问
请求上下文 凭据和请求跟踪
工具注释 缓存、只读提示、标签

配置

# Enable authentication
export MCP_AUTH_ENABLED=true
export MCP_TOKEN=your-secret-token

# Use HTTP transport
export MCP_TRANSPORT=http
export MCP_HTTP_PORT=3000

# Run server
./build/dpb-mcp

仪表盘

基准套件生成了一个美丽的包豪斯风格的仪表板:

  • 性能指标 -启动时间、二进制大小、工具执行时间
  • 依赖关系树 -交互式D3.js可视化
  • 安全摘要 -按严重程度细分的漏洞
  • 许可证矩阵 -跨软件包的许可证分发
  • 命名空间映射 -代码结构可视化
  • 冒烟测试 -直接从仪表板运行测试

本地仪表板服务器

一个轻量级的Go服务器,具有热重载功能,可用于本地开发:

# Build and serve (opens browser automatically)
cd dpb-benchmark
make serve

# Development mode with Air hot-reload
make dev

# Install Air (first time only)
make install-air

服务器运行在 http://localhost:8080 默认情况下。

检查服务器是否正在运行:

# Check port 8080
lsof -ti:8080 && echo "Server is running" || echo "Server is not running"

# Or check process
ps aux | grep dashboard-server

文档生成

这 generate_mkdocs_docs 该工具根据您的依赖性分析数据创建全面的文档。

手动使用

通过Cursor IDE(推荐):

@dependency-buster generate_mkdocs_docs repo_path=/path/to/repo

使用选项:

@dependency-buster generate_mkdocs_docs repo_path=/path/to/repo output_dir=./docs include_changelog=true format=mkdocs site_name="My Project" site_description="Project Documentation"

通过命令行(TypeScript):

echo '{"jsonrpc":"2.0","method":"tools/call","params":{"name":"generate_mkdocs_docs","arguments":{"repo_path":"/path/to/repo","output_dir":"./docs","include_changelog":true,"format":"mkdocs"}},"id":1}' | node dpb-mcp-typescript/build/server.js

通过命令行(Go):

echo '{"jsonrpc":"2.0","method":"tools/call","params":{"name":"generate_mkdocs_docs","arguments":{"repo_path":"/path/to/repo","output_dir":"./docs"}},"id":1}' | ./dpb-mcp-go/build/dpb-mcp

通过命令行(Rust):

echo '{"jsonrpc":"2.0","method":"tools/call","params":{"name":"generate_mkdocs_docs","arguments":{"repo_path":"/path/to/repo","output_dir":"./docs"}},"id":1}' | ./dpb-mcp-rust/target/release/dpb-mcp

参数

参数 类型 默认值 说明
repo_path 字符串 必需的 存储库的绝对路径
output_dir 字符串 docs/ 生成文档的输出目录
include_changelog 布尔值 true 包含基于快照的依赖关系更改日志
format 字符串 mkdocs 输出格式: mkdocs, html,或 markdown
site_name string 自动检测 mkdocs.yml的站点名称
site_description string 自动检测 mkdocs.yml的站点描述

查看生成的文档

选项1:MkDocs(推荐)

cd docs
pip install mkdocs mkdocs-material
mkdocs serve
# Opens at http://127.0.0.1:8000

选项2:直接查看Markdown

# Open in your editor
code docs/index.md

选项3:HTML输出

# Generate with format=html
# Then open docs/index.html in browser

生成文档时

自动生成(首次运行):

  • 当仪表板服务器首次启动时,会自动生成包含所有可用实现(TypeScript、Go、Rust)的文档
  • 这种情况只会发生一次——如果 docs/index.md 已存在,跳过自动生成
  • 所有三种实现的基准测试结果都显示在控制台中

手动生成: 使用 @dependency-buster generate_mkdocs_docs 每当需要重新生成文档时,都可以使用命令:

# Basic usage
@dependency-buster generate_mkdocs_docs repo_path=/path/to/repo

# With custom output directory
@dependency-buster generate_mkdocs_docs repo_path=/path/to/repo output_dir=./custom-docs

# Without changelog (faster)
@dependency-buster generate_mkdocs_docs repo_path=/path/to/repo include_changelog=false

# HTML format instead of MkDocs
@dependency-buster generate_mkdocs_docs repo_path=/path/to/repo format=html

CI/CD集成: 添加到您的GitHub操作/GitLab CI工作流中:

- name: Generate Documentation
  run: |
    # Call generate_mkdocs_docs tool
    echo '{"jsonrpc":"2.0","method":"tools/call","params":{"name":"generate_mkdocs_docs","arguments":{"repo_path":"${{ github.workspace }}"}},"id":1}' | node dpb-mcp-typescript/build/server.js
    # Commit docs/ directory to repository

备注:文档生成现在已包含在基准中。当你奔跑时 run-benchmark.sh,它将进行基准测试 generate_mkdocs_docs 对于所有三种实现。


CI/CD集成

GitHub操作

name: Dependency Analysis
on: [push]

jobs:
  analyze:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          
      - name: Run dependency-buster
        run: |
          git clone https://github.com/your-username/dependency-buster.git /tmp/dpb
          cd /tmp/dpb/dpb-mcp-typescript
          npm install && npm run build
          cd $GITHUB_WORKSPACE
          /tmp/dpb/dpb-benchmark/scripts/run-benchmark.sh .
          
      - name: Upload Dashboard
        uses: actions/upload-artifact@v4
        with:
          name: dependency-report
          path: /tmp/dpb/dpb-benchmark/dashboard/index.html

发展

先决条件

  • Node.js 18+(TypeScript)
  • 前进1.21+(前进)
  • 锈蚀1.70+(锈蚀)
  • jq(用于JSON处理)

运行测试

# TypeScript
cd dpb-mcp-typescript
npm test

# Go
cd dpb-mcp-go
go test ./...

# Rust
cd dpb-mcp-rust
cargo test

建筑全部

./build-all.sh

贡献

欢迎投稿!请阅读我们的 贡献指南 第一。

  1. 克隆该仓库
  2. 创建功能分支(git checkout -b feature/amazing-feature)
  3. 提交您的更改(git commit -m 'Add amazing feature')
  4. 推到分支(git push origin feature/amazing-feature)
  5. 打开拉取请求

许可证

MIT许可证-请参阅 许可证 了解详情。


致谢