详细分析 ▾
运行时依赖
安装命令
点击复制技能文档
安全变更 先看清“爆炸半径”再动手。Safe Change 会扫描任何代码变更的影响面——importers、API routes、测试覆盖率、ENV 变量、数据库迁移——给出风险分,等你 go/no-go 才跑 verify gate。它是深度调试的前置保镖:在 bug 上线前拦截,而不是事后救火。
速查表 情境 → 动作 准备改共享服务 → 先跑 scan-impact.mjs 目标文件 风险分 High → 停!读报告,明确 go/no-go 测试缺口 (gap: true) → 先写测试再改代码 发现近期迁移 → 部署前确认迁移兼容 全部通过 → 跑 verify-gate.sh 确认构建 风险分 Low 且测试全绿 → 继续,最后跑 verify gate
何时启用 只要满足以下任一条件:
- 重命名/抽取被多处引用的函数/类
- 修改服务方法签名
- 动 NestJS controller 或 Next.js API route
- 目标文件被 ≥3 个文件 import
- 改到读取 process.env 的代码
- migrations 文件夹存在未部署迁移
- 同事问“改 X 安全吗?”
别因“改动小”就跳过。多数线上事故都始于“小改动”。
工作原理——6 阶段 阶段1 探测栈:读根目录 package.json,识别 NestJS / Next.js / 纯 TS。 阶段2 构建影响图:执行 scripts/scan-impact.mjs <目标文件>,用正则静态分析收集:
- Importers:所有 .ts/.tsx 引用
- API Routes:NestJS @Controller 及动词装饰器;Next.js app/api//route.ts
- Tests:引用目标的 spec/test 文件;无则置 gap
- ENV:目标文件内 process.env.X
- DB 迁移:近 7 天修改的 migrations/ 文件
阶段3 风险分 Low:≤2 importers,无 route,有测试,无 ENV,无近期迁移 Medium:3–7 importers 或 1–2 routes 或测试缺口 或含 ENV High:≥8 importers 或 ≥3 routes 或(测试缺口+ENV+近期迁移)
阶段4 渲染报告:JSON → Markdown,顶部醒目标风险分。 阶段5 强制卡点: “风险分 [Low/Medium/High],是否继续?(yes/no/adjust scope)” 用户确认前绝不继续。
阶段6 验证门: 执行 scripts/verify-gate.sh,顺序跑: tsc --noEmit → lint → test → build 任一失败即停,彩色输出,非零退出。
输出示例
Safe Change Report — src/notifications/notifications.service.ts
Risk Score: MEDIUM Risk factors: 5 importers, 1 API route, test coverage existsImporters (5)
- src/users/users.service.ts
- src/appointments/appointments.service.ts
- src/billing/billing.service.ts
- src/reports/reports.service.ts
- src/audit/audit.service.ts
API Routes Affected
| Controller | Endpoints | |------------|-----------| | NotificationsController | POST /notifications, GET /notifications |Test Coverage
- src/notifications/notifications.service.spec.ts ✓
- Gap: no
ENV Variables Referenced
- SMTP_HOST
- SMTP_USER
- SMTP_PASS
Recent Migrations (last 7 days)
- None
限制 见 references/limitations.md。核心约束:
- 正则分析:无法识别动态 import(path)
- barrel re-export 可能少算 importers
- 自定义装饰器别名检测不到
- v0.1 仅支持 TypeScript,无 Python/Go/Rust 适配
配套技能
- deep-debugging:事故后深度排查
- self-improving-agent:若变更引发事故,将报告记入学习日志
脚本 scripts/scan-impact.mjs — 生成影响图 JSON scripts/verify-gate.sh — 顺序跑 tsc→lint→test→build
目录结构 safe-change/ ├── SKILL.md ├── README.md ├── package.json ├── scripts/ │ ├── scan-impact.mjs │ └── verify-gate.sh