gorefactor

command module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2026 License: MIT Imports: 5 Imported by: 0

README

gorefactor

AST-based Go refactoring tool for LLM agents.

Install

go install github.com/night-codes/gorefactor@latest

Commands

Project Overview
gorefactor project              # Structure and stats
gorefactor packages             # List all packages
gorefactor symbols ./pkg        # All symbols in package
gorefactor api ./pkg            # Public API only
gorefactor find <name> [dir]      # Find symbol (func, type, var, const, field)
Read Code
gorefactor read <name> [file]     # Read code of function or type
Modify Code
# Replace function
echo 'func ProcessOrder(ctx context.Context, id int) error {
    return nil
}' | gorefactor replace ProcessOrder

# Delete function
gorefactor delete OldHandler

# Add function to specific file
echo 'func NewHelper() {}' | gorefactor add helpers.go

# Move function between files
gorefactor move ProcessOrder newfile.go
Navigation (via gopls)
gorefactor definition UserService    # Where defined
gorefactor references ProcessOrder   # All usages
gorefactor implementations Reader    # Types implementing interface
gorefactor callers SaveUser          # Who calls this
Refactoring (via gopls)
gorefactor rename OldName NewName    # Rename globally
Validation
gorefactor check     # go build + go vet
gorefactor test      # Run tests

Output

All commands return JSON:

{
	"success": true,
	"name": "ProcessOrder",
	"file": "/path/to/service.go",
	"line": 42,
	"code": "func ProcessOrder(...) { ... }"
}

Why This Tool?

For LLM agents working with Go code:

Problem Solution
Read 500-line file to find one function read Name returns just that function
Text matching fails on whitespace AST-based, works by symbol name
Don't know which file has the code Auto-search across project
Replace function, match exact text replace Name — no text matching

Requirements

  • Go 1.21+
  • gopls (for navigation/rename commands)

License

MIT

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL