mcpField
G
gitnexus-refactoring

gitnexus-refactoring

github.com/mindfold-ai开发15.1k87 次安装6 周前更新
代码仓库

关于 gitnexus-refactoring

gitnexus-refactoring 是面向开发者的 GitNexus 重构技能,适用于调整代码结构。它指导分析依赖和引用、执行多文件重命名,并验证变更范围。

主要功能

  1. 01梳理依赖项与执行流程
  2. 02检查输入和输出引用
  3. 03预览并应用多文件重命名
  4. 04验证变更文件及受影响流程

适用场景

  1. 01跨代码库重命名符号
  2. 02将代码提取到模块
  3. 03拆分函数或服务
  4. 04检查重构变更范围

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/mindfold-ai/trellis --skill gitnexus-refactoring

安装后在 Claude Code 中输入/gitnexus-refactoring确认已加载。

详细介绍

使用 GitNexus 重构

适用场景

  • “安全地重命名此函数”
  • “将此内容提取到一个模块中”
  • “拆分此服务”
  • “将此内容移到新文件中”
  • 任何涉及重命名、提取、拆分或重构代码结构的任务

工作流

1. impact({target: "X", direction: "upstream"})  → Map all dependents
2. query({query: "X"})                            → Find execution flows involving X
3. context({name: "X"})                           → See all incoming/outgoing refs
4. Plan update order: interfaces → implementations → callers → tests

如果出现“索引已过时”,请在终端中运行 node .gitnexus/run.cjs analyze。

检查清单

重命名符号
- [ ] 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: rename({..., dry_run: false}) — apply edits
- [ ] detect_changes() — verify only expected files changed
- [ ] Run tests for affected processes
提取模块
- [ ] context({name: target}) — see all incoming/outgoing refs
- [ ] impact({target, direction: "upstream"}) — find all external callers
- [ ] Define new module interface
- [ ] Extract code, update imports
- [ ] detect_changes() — verify affected scope
- [ ] Run tests for affected processes
拆分函数/服务
- [ ] context({name: target}) — understand all callees
- [ ] Group callees by responsibility
- [ ] impact({target, direction: "upstream"}) — map callers to update
- [ ] Create new functions/services
- [ ] Update callers
- [ ] detect_changes() — verify affected scope
- [ ] Run tests for affected processes

工具

rename — 自动重命名多个文件中的内容:

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}]}]

impact — 先映射所有依赖项:

impact({target: "validateUser", direction: "upstream"})
→ d=1: loginHandler, apiMiddleware, testUtils
→ Affected Processes: LoginFlow, TokenRefresh

detect_changes — 重构后验证更改:

detect_changes({scope: "all"})
→ Changed: 8 files, 12 symbols
→ Affected processes: LoginFlow, TokenRefresh
→ Risk: MEDIUM

cypher — 自定义引用查询:

MATCH (caller)-[:CodeRelation {type: 'CALLS'}]->(f:Function {name: "validateUser"})
RETURN caller.name, caller.filePath ORDER BY caller.filePath

风险规则

风险因素缓解措施
调用方很多(>5)使用 rename 自动更新
跨区域引用之后使用 detect_changes 验证范围
字符串/动态引用使用 query 查找
外部/公共 API正确地进行版本管理和弃用

示例:将 validateUser 重命名为 authenticateUser

1. 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. rename({symbol_name: "validateUser", new_name: "authenticateUser", dry_run: false})
   → Applied 12 edits across 8 files

4. detect_changes({scope: "all"})
   → Affected: LoginFlow, TokenRefresh
   → Risk: MEDIUM — run tests for these flows

评论

支持 Markdown