gitnexus-refactoring

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Refactoring with GitNexus

使用GitNexus进行代码重构

When to Use

适用场景

  • "Rename this function safely"
  • "Extract this into a module"
  • "Split this service"
  • "Move this to a new file"
  • Any task involving renaming, extracting, splitting, or restructuring code
  • "安全重命名此函数"
  • "将此代码提取为模块"
  • "拆分此服务"
  • "将此代码移动到新文件"
  • 任何涉及重命名、提取、拆分或重构代码结构的任务

Workflow

工作流程

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
If "Index is stale" → run
npx gitnexus analyze
in terminal.
1. gitnexus_impact({target: "X", direction: "upstream"})  → 映射所有依赖项
2. gitnexus_query({query: "X"})                            → 查找涉及X的执行流程
3. gitnexus_context({name: "X"})                           → 查看所有传入/传出引用
4. 规划更新顺序:接口 → 实现 → 调用方 → 测试
如果提示“Index is stale”(索引已过期)→ 在终端中运行
npx gitnexus analyze

Checklists

检查清单

Rename Symbol

重命名符号

- [ ] 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_rename({symbol_name: "oldName", new_name: "newName", dry_run: true}) — 预览所有编辑内容
- [ ] 审查图编辑(高可信度)和ast_search编辑(需仔细审查)
- [ ] 若满意:gitnexus_rename({..., dry_run: false}) — 应用编辑
- [ ] gitnexus_detect_changes() — 验证仅预期文件被修改
- [ ] 运行受影响流程的测试

Extract Module

提取模块

- [ ] 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}) — 查看所有传入/传出引用
- [ ] gitnexus_impact({target, direction: "upstream"}) — 查找所有外部调用方
- [ ] 定义新模块接口
- [ ] 提取代码,更新导入语句
- [ ] gitnexus_detect_changes() — 验证受影响范围
- [ ] 运行受影响流程的测试

Split Function/Service

拆分函数/服务

- [ ] 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_context({name: target}) — 了解所有被调用方
- [ ] 按职责对被调用方进行分组
- [ ] gitnexus_impact({target, direction: "upstream"}) — 映射需要更新的调用方
- [ ] 创建新的函数/服务
- [ ] 更新调用方
- [ ] gitnexus_detect_changes() — 验证受影响范围
- [ ] 运行受影响流程的测试

Tools

工具

gitnexus_rename — automated multi-file 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 — map all dependents first:
gitnexus_impact({target: "validateUser", direction: "upstream"})
→ d=1: loginHandler, apiMiddleware, testUtils
→ Affected Processes: LoginFlow, TokenRefresh
gitnexus_detect_changes — verify your changes after refactoring:
gitnexus_detect_changes({scope: "all"})
→ Changed: 8 files, 12 symbols
→ Affected processes: LoginFlow, TokenRefresh
→ Risk: MEDIUM
gitnexus_cypher — custom reference queries:
cypher
MATCH (caller)-[:CodeRelation {type: 'CALLS'}]->(f:Function {name: "validateUser"})
RETURN caller.name, caller.filePath ORDER BY caller.filePath
gitnexus_rename — 自动化多文件重命名:
gitnexus_rename({symbol_name: "validateUser", new_name: "authenticateUser", dry_run: true})
→ 8个文件中共有12处编辑
→ 10处图编辑(高可信度),2处ast_search编辑(需审查)
→ 变更内容: [{file_path, edits: [{line, old_text, new_text, confidence}]}]
gitnexus_impact — 先映射所有依赖项:
gitnexus_impact({target: "validateUser", direction: "upstream"})
→ d=1: loginHandler, apiMiddleware, testUtils
→ 受影响流程: LoginFlow, TokenRefresh
gitnexus_detect_changes — 重构后验证你的变更:
gitnexus_detect_changes({scope: "all"})
→ 已变更: 8个文件,12个符号
→ 受影响流程: LoginFlow, TokenRefresh
→ 风险等级: MEDIUM
gitnexus_cypher — 自定义引用查询:
cypher
MATCH (caller)-[:CodeRelation {type: 'CALLS'}]->(f:Function {name: "validateUser"})
RETURN caller.name, caller.filePath ORDER BY caller.filePath

Risk Rules

风险规则

Risk FactorMitigation
Many callers (>5)Use gitnexus_rename for automated updates
Cross-area refsUse detect_changes after to verify scope
String/dynamic refsgitnexus_query to find them
External/public APIVersion and deprecate properly
风险因素缓解措施
调用方数量多(>5个)使用gitnexus_rename进行自动化更新
跨区域引用重构后使用detect_changes验证范围
字符串/动态引用使用gitnexus_query查找这些引用
外部/公开API正确进行版本控制并标记弃用

Example: Rename
validateUser
to
authenticateUser

示例:将
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
1. gitnexus_rename({symbol_name: "validateUser", new_name: "authenticateUser", dry_run: true})
   → 12处编辑:10处图编辑(安全),2处ast_search编辑(需审查)
   → 文件: validator.ts, login.ts, middleware.ts, config.json...

2. 审查ast_search编辑(config.json: 动态引用!)

3. gitnexus_rename({symbol_name: "validateUser", new_name: "authenticateUser", dry_run: false})
   → 在8个文件中应用了12处编辑

4. gitnexus_detect_changes({scope: "all"})
   → 受影响: LoginFlow, TokenRefresh
   → 风险等级: MEDIUM — 运行这些流程的测试