ast-refactoring

Refactors Go code safely using AST-based tools like gorename and gofmt.

111|73|Updated Mar 20, 2026
One-click install
npx skills add https://github.com/autopus-ai/autopus-adk --skill ast-refactoring-autopus-ai
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: ast-refactoring
Source: https://github.com/autopus-ai/autopus-adk/tree/main/.omp/skills/ast-refactoring
Command: npx skills add https://github.com/autopus-ai/autopus-adk --skill ast-refactoring-autopus-ai

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Text-based find-and-replace with sed or regular expressions often produces false matches and partial replacements that silently break code. This Skill guides refactoring through Abstract Syntax Tree (AST) transformations that understand Go syntax, so symbol renames, pattern conversions, and package moves stay correct. ## Core Features & Use Cases - AST-Based Tooling: Uses gorename for safe symbol renaming, gofmt -r for pattern-based transformations, and gomv for package moves with automatic reference updates. - Refactoring Patterns: Provides concrete before/after examples for Extract Function and Extract Interface patterns to improve testability and single-responsibility design. - Safe Procedure: Enforces a test-first workflow — verify tests are GREEN, refactor, re-run tests, lint, then commit — and forbids mixing behavior changes with refactoring in one commit. - Use Case: When renaming a widely used Go function across a monorepo, apply gorename instead of sed so only true symbol references change, then confirm the test suite stays green. ## Quick Start Ask the agent to rename a Go function or extract an interface using AST-based refactoring while keeping all tests passing.

Frequently Asked Questions about ast-refactoring

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I safely rename a Go function across a codebase?▼

Use gorename with the fully qualified symbol path, for example gorename -from "github.com/org/pkg.OldName" -to NewName. It resolves actual symbol references through the type system, avoiding the false matches that sed or regex replacements produce.

What is the difference between AST-based refactoring and regex replacement?▼

Regex replacement matches raw text, so it can hit partial identifiers, comments, or strings. AST-based tools parse the Go syntax tree and transform only genuine code constructs, making renames and pattern conversions semantically correct.

How do I use gofmt -r for pattern-based code transformation?▼

Run gofmt -r 'a.Foo(b, c) -> a.Bar(b, c)' -w ./... to rewrite every matching call expression across the module. The pattern operates on parsed expressions, so formatting differences in the source do not affect matching.

Can I move a Go package and update all imports automatically?▼

Yes, use gomv with the old and new import paths, or trigger an LSP rename through gopls. Both approaches update every referencing import across the codebase rather than requiring manual edits.

Why should tests pass before and after refactoring?▼

A green test suite before refactoring establishes a behavioral baseline, and the same green result afterward proves behavior was preserved. Mixing feature changes into a refactoring commit breaks this guarantee and makes regressions hard to isolate.