| name | before-refactor |
| description | Safety check before refactoring - shows callers, callees, and impact analysis |
| allowed-tools | ["mcp__gitkb__kb_callers","mcp__gitkb__kb_callees","mcp__gitkb__kb_impact","mcp__gitkb__kb_symbols","mcp__gitkb__kb_symbol_refs"] |
/before-refactor
Safety check before modifying a function, method, or type. Shows all call sites that would need updates if you change the signature, plus impact analysis.
When to Use
- Before changing a function signature
- Before renaming a public symbol
- Before modifying an interface or type's fields
- Before any change that could break callers
Steps
-
Find the symbol and its location:
kb_symbols with search: "<symbol-name>"
-
Get all callers (who would break if you change the signature):
kb_callers with symbol: "<full-symbol-id>"
-
Get callees (what this function depends on):
kb_callees with symbol: "<full-symbol-id>"
-
Run impact analysis on the file:
kb_impact with file_path: "<file-path>"
-
Check for related documents:
kb_symbol_refs with symbol: "<full-symbol-id>"
Output Format
## Refactor Safety Check: `symbolName()`
### Location
- File: src/services/auth.ts:45-67
- Kind: function
- Signature: `async function symbolName(param: Type): Promise<Result>`
### Direct Callers (5)
These will break if you change the signature:
- src/routes/auth.ts:45 -> handleRequest()
- src/routes/auth.ts:89 -> handleRefresh()
- src/middleware/auth.ts:22 -> authenticate()
- tests/auth.test.ts:15 -> testLogin()
- tests/integration.test.ts:88 -> testFullFlow()
### Transitive Impact
- 12 symbols transitively depend on this
- Affects 4 files
### What This Calls
- src/db/users.ts::findUser()
- src/crypto/tokens.ts::generateToken()
### Related Documents
- tasks/my-task (Related Task)
### Recommendation
[LOW|MEDIUM|HIGH] impact refactor:
- LOW: 0-2 callers, all in same module
- MEDIUM: 3-10 callers, multiple modules
- HIGH: 10+ callers or public API surface
Files that need updates if signature changes:
1. src/routes/auth.ts
2. src/middleware/auth.ts
3. tests/auth.test.ts
4. tests/integration.test.ts
Example
Input: /before-refactor login
Output:
## Refactor Safety Check: `login()`
### Location
- File: src/services/auth.ts:45-67
- Kind: function
### Direct Callers (3)
These will break if you change the signature:
- src/routes/auth.ts:45 -> handleRequest()
- src/routes/auth.ts:89 -> handleRefresh()
- src/middleware/auth.ts:22 -> authenticate()
### Transitive Impact
- 8 symbols transitively depend on this
- Affects 3 files
### Recommendation
MEDIUM impact refactor.
Files that need updates if signature changes:
1. src/routes/auth.ts
2. src/middleware/auth.ts
Prerequisites
Code must be indexed first:
git kb index