关于 gitnexus-refactoring
这是一个用于规划代码重构的 GitNexus 技能,涵盖符号重命名、模块提取和服务拆分。它通过依赖关系与执行流分析指导修改,并检查变更范围。
主要功能
- 01映射依赖项与执行流
- 02检查传入和传出的引用
- 03预览并应用多文件重命名
- 04检查变更文件及受影响流程
适用场景
- 01安全重命名函数或符号
- 02将代码提取到模块
- 03拆分函数或服务
- 04移动代码并更新调用方
MCP 相关
该技能指导使用 GitNexus 工具进行重构,包括影响分析、查询、上下文检查、重命名和变更检测。
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ tony363/ superclaude --skill gitnexus-refactoring安装后在 Claude Code 中输入/gitnexus-refactoring确认已加载。
详细介绍
使用 GitNexus 重构
适用场景
- “安全地重命名此函数”
- “将此内容提取到模块中”
- “拆分此服务”
- “将此内容移至新文件”
- 涉及重命名、提取、拆分或重构代码的任何任务
工作流
1. gitnexus_impact({target: "X", direction: "upstream"}) → Map all dependents
2. gitnexus_query({query: "X"}) → Find execution flows involving X
3. gitnexus_context({name: "X"}) → See all incoming/outgoing refs
4. Plan update order: interfaces → implementations → callers → tests
如果出现“索引已过期”,请在终端中运行
npx gitnexus analyze。
检查清单
重命名符号
- [ ] gitnexus_rename({symbol_name: "oldName", new_name: "newName", dry_run: true}) — preview all edits
- [ ] Review graph edits (high confidence) and ast_search edits (review carefully)
- [ ] If satisfied: gitnexus_rename({..., dry_run: false}) — apply edits
- [ ] gitnexus_detect_changes() — verify only expected files changed
- [ ] Run tests for affected processes
提取模块
- [ ] gitnexus_context({name: target}) — see all incoming/outgoing refs
- [ ] gitnexus_impact({target, direction: "upstream"}) — find all external callers
- [ ] Define new module interface
- [ ] Extract code, update imports
- [ ] gitnexus_detect_changes() — verify affected scope
- [ ] Run tests for affected processes
拆分函数/服务
- [ ] gitnexus_context({name: target}) — understand all callees
- [ ] Group callees by responsibility
- [ ] gitnexus_impact({target, direction: "upstream"}) — map callers to update
- [ ] Create new functions/services
- [ ] Update callers
- [ ] gitnexus_detect_changes() — verify affected scope
- [ ] Run tests for affected processes
工具
gitnexus_rename — 自动重命名多个文件:
gitnexus_rename({symbol_name: "validateUser", new_name: "authenticateUser", dry_run: true})
→ 12 edits across 8 files
→ 10 graph edits (high confidence), 2 ast_search edits (review)
→ Changes: [{file_path, edits: [{line, old_text, new_text, confidence}]}]
gitnexus_impact — 先映射所有依赖项:
gitnexus_impact({target: "validateUser", direction: "upstream"})
→ d=1: loginHandler, apiMiddleware, testUtils
→ Affected Processes: LoginFlow, TokenRefresh
gitnexus_detect_changes — 重构后验证更改:
gitnexus_detect_changes({scope: "all"})
→ Changed: 8 files, 12 symbols
→ Affected processes: LoginFlow, TokenRefresh
→ Risk: MEDIUM
gitnexus_cypher — 自定义引用查询:
MATCH (caller)-[:CodeRelation {type: 'CALLS'}]->(f:Function {name: "validateUser"})
RETURN caller.name, caller.filePath ORDER BY caller.filePath
风险规则
| 风险因素 | 缓解措施 |
|---|---|
| 调用方较多(>5) | 使用 gitnexus_rename 自动更新 |
| 跨区域引用 | 之后使用 detect_changes 验证范围 |
| 字符串/动态引用 | 使用 gitnexus_query 查找 |
| 外部/公共 API | 正确管理版本并弃用 |
示例:将 validateUser 重命名为 authenticateUser
1. gitnexus_rename({symbol_name: "validateUser", new_name: "authenticateUser", dry_run: true})
→ 12 edits: 10 graph (safe), 2 ast_search (review)
→ Files: validator.ts, login.ts, middleware.ts, config.json...
2. Review ast_search edits (config.json: dynamic reference!)
3. gitnexus_rename({symbol_name: "validateUser", new_name: "authenticateUser", dry_run: false})
→ Applied 12 edits across 8 files
4. gitnexus_detect_changes({scope: "all"})
→ Affected: LoginFlow, TokenRefresh
→ Risk: MEDIUM — run tests for these flows
评论
支持 Markdown