dependency-audit — Smart Dependency Health Check
Detect your package manager, run security audits, find outdated and unused dependencies, and generate a prioritized update plan.
Steps
1. Detect Package Manager
Check for these files in the project root:
| File | Ecosystem | Audit Command |
|---|
| INLINECODE0 | Node.js (npm/yarn/pnpm) | INLINECODE1 |
INLINECODE2 / pyproject.toml / INLINECODE4 |
Python |
pip audit |
|
Cargo.toml | Rust |
cargo audit |
|
go.mod | Go |
govulncheck ./... |
|
Gemfile | Ruby |
bundle audit check |
If multiple are found, audit all of them. If none found, stop and inform the user.
2. Run Security Audit
Node.js:
CODEBLOCK0
Python:
CODEBLOCK1
Rust:
CODEBLOCK2
3. Check for Outdated Packages
Node.js:
CODEBLOCK3
Python:
CODEBLOCK4
Rust:
CODEBLOCK5
4. Identify Unused Dependencies
Node.js — use depcheck:
npx depcheck --json 2>/dev/null
This reports unused dependencies and missing dependencies. If
npx fails, scan source files manually:
CODEBLOCK7
Python: Scan imports vs installed packages:
CODEBLOCK8
5. Generate Prioritized Update Plan
Organize findings into priority tiers:
CODEBLOCK9
6. Provide Safe Update Commands
For batch updates, generate copy-pasteable commands:
CODEBLOCK10
For Python:
CODEBLOCK11
7. Output Summary
CODEBLOCK12
Edge Cases
- - Lock file conflicts: If
package-lock.json is out of sync, run npm install first - Private registries:
npm audit may fail — suggest INLINECODE16 - Monorepo: Check each workspace. For npm: INLINECODE17
- No internet: Report that audit requires network access
- Audit tool not installed: Provide install command (e.g.,
pip install pip-audit)
Error Handling
| Error | Resolution |
|---|
| INLINECODE19 returns non-zero | Normal — means vulnerabilities found, parse the output |
| INLINECODE20 not found |
pip install pip-audit then retry |
|
cargo audit not found |
cargo install cargo-audit then retry |
| Network error | Check connectivity; suggest
--offline if available |
| Permission denied | Suggest running without
sudo; check file ownership |
Built by Clawb (SOVEREIGN) — more skills at [coming soon]
dependency-audit — 智能依赖健康检查
检测你的包管理器,运行安全审计,发现过时和未使用的依赖,并生成优先级更新计划。
步骤
1. 检测包管理器
在项目根目录检查以下文件:
| 文件 | 生态系统 | 审计命令 |
|---|
| package.json | Node.js (npm/yarn/pnpm) | npm audit |
| requirements.txt / pyproject.toml / Pipfile |
Python | pip audit |
| Cargo.toml | Rust | cargo audit |
| go.mod | Go | govulncheck ./... |
| Gemfile | Ruby | bundle audit check |
如果发现多个,则全部审计。如果未发现任何文件,则停止并通知用户。
2. 运行安全审计
Node.js:
bash
npm audit --json 2>/dev/null
解析:公告、严重性(严重/高/中/低)、受影响的包、可用修复
Python:
bash
pip audit --format=json 2>/dev/null || pip audit 2>/dev/null
如果未安装 pip-audit:pip install pip-audit
Rust:
bash
cargo audit --json 2>/dev/null
如果未安装:cargo install cargo-audit
3. 检查过时的包
Node.js:
bash
npm outdated --json 2>/dev/null
显示:当前版本、期望版本(语义化版本兼容)、最新版本
Python:
bash
pip list --outdated --format=json 2>/dev/null
Rust:
bash
cargo outdated -R 2>/dev/null
如果未安装:cargo install cargo-outdated
4. 识别未使用的依赖
Node.js — 使用 depcheck:
bash
npx depcheck --json 2>/dev/null
这会报告未使用的依赖和缺失的依赖。如果 npx 失败,手动扫描源文件:
bash
从 package.json 列出所有依赖,然后 grep 查找导入
标记任何在 .js/.ts/.jsx/.tsx 文件中未找到的依赖
Python: 扫描导入与已安装包对比:
bash
从 .py 文件中提取导入
grep -rh ^import \|^from --include=*.py . | sort -u
与 requirements.txt 条目对比
5. 生成优先级更新计划
将发现结果组织成优先级层级:
markdown
🔴 严重 — 安全漏洞
| 包 | 严重性 | 当前版本 | 修复版本 | 命令 |
|---|
| lodash | 严重 | 4.17.19 | 4.17.21 | npm install lodash@4.17.21 |
🟠 高 — 有破坏性更新可用
| 包 | 当前版本 | 最新版本 | 破坏性变更 |
|---|
| express | 4.18.2 | 5.0.0 | 新的路由 API |
🟡 中 — 次要/补丁更新
| 包 | 当前版本 | 最新版本 | 命令 |
|---|
| axios | 1.5.0 | 1.6.2 | npm install axios@1.6.2 |
🟢 低 — 未使用的依赖
| 包 | 操作 |
|---|
| moment | npm uninstall moment |
6. 提供安全更新命令
对于批量更新,生成可复制粘贴的命令:
bash
安全修复(安全 — 仅补丁更新)
npm audit fix
所有兼容更新(非破坏性)
npm update
特定破坏性更新(彻底测试)
npm install express@5.0.0
对于 Python:
bash
pip install --upgrade package_name
7. 输出摘要
markdown
依赖健康报告 — [项目名称]
日期: 2025-02-15 |
生态系统: Node.js (npm)
3 |
| 🟡 次要/补丁更新 | 8 |
| 🟢 未使用的依赖 | 1 |
| ✅ 已是最新 | 42 |
边界情况
- - 锁定文件冲突:如果 package-lock.json 不同步,先运行 npm install
- 私有注册表:npm audit 可能失败 — 建议使用 --registry=https://registry.npmjs.org
- 单体仓库:检查每个工作区。对于 npm:npm audit --workspaces
- 无网络:报告审计需要网络访问
- 审计工具未安装:提供安装命令(例如 pip install pip-audit)
错误处理
| 错误 | 解决方案 |
|---|
| npm audit 返回非零 | 正常 — 表示发现漏洞,解析输出 |
| 未找到 pip-audit |
pip install pip-audit 然后重试 |
| 未找到 cargo audit | cargo install cargo-audit 然后重试 |
| 网络错误 | 检查连接;如果可用建议使用 --offline |
| 权限被拒绝 | 建议不要使用 sudo 运行;检查文件所有权 |
由 Clawb (SOVEREIGN) 构建 — 更多技能即将推出