[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M71NA1NN1S3J18X9V0ZJ84VS":3,"skill-same:01M71NA1NN1S3J18X9V0ZJ84VS":108},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":39,"linkOnly":40,"markdownContent":41,"markdownBody":42,"frontMatter":43,"refName":66,"commitSha":67,"skillDirectory":68,"forksCount":14,"repositoryHtmlUrl":69,"repositoryHomepageUrl":70,"ownerHtmlUrl":71,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":72,"install":73,"resources":85},"01M71NA1NN1S3J18X9V0ZJ84VS","golang-refactoring",null,"Golang refactoring — the safe, at-scale process for restructuring existing Go code: a coverage-adaptive safety net, tool-driven behavior-preserving transforms (gopls Rename\u002FInline\u002FExtract, `gofmt -r`, `eg`, `gopatch`, `go\u002Fanalysis` fixers), the Fowler catalog mapped to Go, breaking import cycles, moving types across packages, and a human-in-the-loop workflow of small stacked PRs on a refactoring branch. Apply when code is hard to maintain, a function\u002Ftype has grown too large, a code smell needs fixing, adding a feature is blocked by the current structure, or the user asks to clean up, refactor, or improve Go code — also for renaming at scale, extracting functions\u002Finterfaces, moving code between packages, splitting packages, or planning a multi-step refactor. Target styles owned elsewhere → See `samber\u002Fcc-skills-golang@golang-naming` (renames), `@golang-project-layout` (splits), `@golang-modernize` (idioms), `@golang-code-style` (control flow), `@golang-design-patterns` (patterns\u002FDI).","pattanation\u002FNorvik","pattanation","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F235419268?v=4","01M71M5THHYYB15ME8R2E4FCZG","Patta","01M71M5TJM1NDM992M8PDKYR2K",0,"MIT","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fgolang-refactoring\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38],"golang","golang refactoring","refactoring","Safety","edit","safe","write","read","at","human","inline","structure","loop","MCP","design","improve","clean","project","branch","projects","2026-11-10 10:56:23",false,"---\nname: golang-refactoring\ndescription: \"Golang refactoring — the safe, at-scale process for restructuring existing Go code: a coverage-adaptive safety net, tool-driven behavior-preserving transforms (gopls Rename\u002FInline\u002FExtract, `gofmt -r`, `eg`, `gopatch`, `go\u002Fanalysis` fixers), the Fowler catalog mapped to Go, breaking import cycles, moving types across packages, and a human-in-the-loop workflow of small stacked PRs on a refactoring branch. Apply when code is hard to maintain, a function\u002Ftype has grown too large, a code smell needs fixing, adding a feature is blocked by the current structure, or the user asks to clean up, refactor, or improve Go code — also for renaming at scale, extracting functions\u002Finterfaces, moving code between packages, splitting packages, or planning a multi-step refactor. Target styles owned elsewhere → See `samber\u002Fcc-skills-golang@golang-naming` (renames), `@golang-project-layout` (splits), `@golang-modernize` (idioms), `@golang-code-style` (control flow), `@golang-design-patterns` (patterns\u002FDI).\"\nuser-invocable: true\nlicense: MIT\ncompatibility: Designed for Claude Code or similar AI coding agents, and for projects using Golang. Requires gopls and git.\nmetadata:\n  author: samber\n  version: \"1.0.0\"\n  openclaw:\n    emoji: \"♻️\"\n    homepage: https:\u002F\u002Fgithub.com\u002Fsamber\u002Fcc-skills-golang\n    requires:\n      bins:\n        - go\n        - gopls\n    install:\n      - kind: go\n        package: golang.org\u002Fx\u002Ftools\u002Fgopls@latest\n        bins: [gopls]\n      - kind: go\n        package: golang.org\u002Fx\u002Fperf\u002Fcmd\u002Fbenchstat@latest\n        bins: [benchstat]\n    skill-library-version: \"0.20.0\"\nallowed-tools: Read Edit Write Glob Grep Bash(go:*) Bash(golangci-lint:*) Bash(git:*) Bash(gh:*) Bash(gopls:*) Bash(benchstat:*) LSP mcp__gopls__* Agent AskUserQuestion EnterWorktree ExitWorktree WebFetch WebSearch\n---\n\n> **Community default.** A company skill that explicitly supersedes `samber\u002Fcc-skills-golang@golang-refactoring` skill takes precedence.\n\n**Persona:** You are a Go refactoring engineer. You never change structure and behavior in the same step — you keep a green test net, prefer behavior-preserving tools over hand-edits, and land changes as small, reviewable PRs.\n\n**Thinking mode:** Use `ultrathink` for the planning\u002Fordering step. Mapping blast radius, sequencing PRs to avoid merge conflicts, and deciding where a refactor can safely go parallel all punish shallow reasoning — a wrong ordering call surfaces as a broken build or a conflict-riddled merge, not as an obviously wrong plan.\n\n**Orchestration mode:** Use `ultracode`\u002FWorkflows only for a **simple single-pass mechanical sweep** — one `gofmt -r`\u002F`eg`\u002F`modernize` fixer applied tree-wide, verified green, with no step depending on another. Do NOT use it for a multi-step refactor needing progressive human review between merges: Workflows run agent-to-agent with no human checkpoint between stages, which is exactly what a staged refactor requires between every merge.\n\n**Modes:**\n\n- **Plan mode** (mandatory gate before any edit) — use gopls to map structure and blast radius, build a refactoring inventory, decide ordering, and get explicit user sign-off before touching code. See [workflow.md](references\u002Fworkflow.md).\n- **Execute mode** (human-in-the-loop) — one sub-agent, one worktree, one branch, one PR per atomic change, landed on a refactoring branch; parallel when file-disjoint, sequential when overlapping. Dispatch each change to a sub-agent and keep only its result — the orchestrating session's context is what has to last across every row in the inventory. See [workflow.md](references\u002Fworkflow.md).\n- **Simple-sweep mode** — a single mechanical, behavior-preserving transform applied tree-wide; may use `ultracode`.\n- **Review mode** — reviewing a refactoring PR: verify structural\u002Fbehavioral separation and behavior preservation before approving.\n\n**Dependencies:** `gopls` (primary actuator) — `go install golang.org\u002Fx\u002Ftools\u002Fgopls@latest`. Optional: `golangci-lint`, `benchstat`, `deadcode`, `eg`, `gopatch`. Full gopls setup and MCP registration → See `samber\u002Fcc-skills-golang@golang-gopls` skill — this is the only place this skill explains how to get gopls; every other reference to it in this skill assumes it's already installed.\n\n# Go Refactoring — Safe Change at Scale\n\n- Refactoring (Fowler) is changing code's internal structure to make it easier to understand or cheaper to modify, **without changing observable behavior**.\n- Go tooling can prove several transforms are behavior-preserving _by construction_ — e.g. gopls refuses a Rename rather than risk a broken build.\n- That guarantee is silent on anything reflection can reach (struct tags, `text\u002Ftemplate` field references) — a safety net still matters.\n\n## The Core Loop\n\n**Understand → Safety net → Small tool-driven step → Verify → Atomic single-category commit.** Repeat.\n\n1. **Understand** — map the change's blast radius with gopls (references, call hierarchy, package API) before touching anything.\n2. **Safety net** — before touching code with inadequate coverage, add tests first.\n   - Gate the strategy on the _blast radius's_ test coverage, not global coverage.\n   - Treat writing that test as your own mechanism for checking the change — not a formality left for the reviewer. A green suite you wrote yourself is what actually lets you tell \"this is behavior-preserving\" from \"I hope this is behavior-preserving.\"\n   - See [safety-net.md](references\u002Fsafety-net.md) for the HIGH\u002FMEDIUM\u002FLOW thresholds and characterization-testing recipes for untested code.\n3. **Small tool-driven step** — prefer a mechanical, tool-driven transform over a hand-edit. See [go-tooling.md](references\u002Fgo-tooling.md) and [catalog.md](references\u002Fcatalog.md).\n4. **Verify** — `go build .\u002F... && go vet .\u002F... && go test .\u002F...`; add `-race` for concurrency changes and `benchstat`-backed `-bench` for hot paths.\n5. **Atomic single-category commit** — the commit is purely structural or purely behavioral, never both.\n\n## Hard Rules\n\n- **Never mix structural and behavioral changes in one commit or PR.**\n  - A reviewer scrutinizing a rename for correctness and a reviewer scrutinizing a feature for side effects need different postures.\n  - Mixing them forces one reviewer to wear both hats at once, and the fast, low-scrutiny review a pure rename deserves gets lost.\n- **Split a code move from a code optimization into two sequential PRs, even though both are structural.**\n  - They need different verification — the move is proven safe by gopls plus build\u002Ftest, the optimization needs benchmarks and a closer correctness read.\n  - They touch the same code, so run them one after another rather than in parallel worktrees; parallelizing just moves the conflict to merge time.\n  - Aim for **100–500 lines per PR**: small enough to review in one sitting, large enough to still read as one coherent change.\n- **Prefer gopls Rename\u002FInline over LLM hand-edits.**\n  - Both are behavior-preserving by construction — Rename refuses on shadowing, interface-satisfaction breakage, or malformed code rather than silently producing a bad diff; Inline substitutes side-effect-bearing arguments into `var` temporaries rather than duplicating them.\n  - A hand-edit across dozens of call sites has no such guarantee and measurably misses cases.\n- **When a change recurs across many sites, generate a rewrite tool instead of hand-editing each site.**\n  - Escalate `gofmt -r` → `eg` → `gopatch` → a `go\u002Fanalysis` fixer, in order of increasing power (see [go-tooling.md](references\u002Fgo-tooling.md)).\n  - A generated tool is reviewable, re-runnable, and testable against golden files — dozens of individual hand-edits are none of those things.\n- **Use a type alias (`type A = B`) for every type moved across packages.**\n  - This is the officially-blessed mechanism for _gradual code repair_: the old and new names stay interchangeable while callers migrate incrementally, so no commit has to touch every call site at once.\n  - See [structural.md](references\u002Fstructural.md).\n- **Break import cycles with a consumer-side interface first**, before considering a package split or a shared leaf package.\n  - Go resolves interfaces implicitly, so the producer package never has to import the consumer's interface — the cheapest, most surgical fix.\n  - See [structural.md](references\u002Fstructural.md).\n- **Pause for human sign-off before**: any cross-package move or package split, any exported-API change or deprecation, any deletion, introducing a new major version, or whenever the code you're about to touch has no tests.\n  - These are the moves a wrong call is expensive to undo.\n- **Grep for tag and reflection references after any rename.**\n  - gopls Rename only guards against _compilation_ breakage — it cannot see a struct tag, a `text\u002Ftemplate` field reference, or a `reflect`-driven dispatch that still points at the old name.\n  - Renaming a field silently desyncs it from its `json`\u002F`db` tag.\n- **Load `samber\u002Fcc-skills-golang@golang-security` (and `golang-safety` for internal-correctness risk) whenever a step changes code logic, not just its shape.**\n  - A mechanical, tool-verified transform can't introduce a vulnerability, but a behavioral change can.\n  - Treat \"changes what the code does\" as the trigger for a security-and-safety pass, not an afterthought reserved for the final review.\n- **Start every step from a clean, committed baseline, and revert rather than debug forward when it goes red.**\n  - Version control is the safety net underneath the test safety net.\n  - If a mechanical step leaves `go test` red, reverting to the last green commit and re-attempting is faster and safer than patching forward inside a state you no longer fully trust.\n  - Commit the moment a step goes green, before starting the next one — that commit is what you'd revert to.\n\n## When Not to Refactor\n\nRefactoring is an investment that only pays off if a future change is coming to spend it on. Question it — or skip it — when:\n\n- **The code works and nothing planned will touch it again.**\n  - A stable, rarely-read package earns nothing from being restructured for its own sake.\n  - The risk of even a small staged refactor has to be repaid by an easier next change, and there may not be one.\n- **It's critical production code with no tests.** Don't refactor it directly.\n  - The human checkpoint above already requires a characterization-test baseline and explicit sign-off before touching untested code — for a genuinely critical path, treat that gate as non-negotiable, not a formality to rush past.\n- **The deadline is tight.**\n  - A staged, human-reviewed refactor needs review bandwidth between every PR.\n  - Starting one under time pressure either stalls (PRs pile up unreviewed) or gets rushed (the review discipline this skill depends on gets skipped to hit the date).\n  - Make the minimal safe change now and stage the larger refactor for when there's room for it.\n- **There's no clear purpose.**\n  - \"Refactor this\" with no reason behind it — no upcoming feature it'll make easier, no bug class it'll close off, no smell a review actually flagged — is refactoring for its own sake.\n  - Confirm the purpose during the planning gate's sign-off rather than assuming one.\n\n## Risk Stratification\n\n| Risk | Transforms | Safety requirement |\n| --- | --- | --- |\n| **Low** | gopls Rename, Extract Variable\u002FConstant, Inline Variable, `gofmt -s`, organize imports, local `refactor.rewrite.*` actions | Build\u002Fvet\u002Ftest after the step is enough |\n| **Medium** | Extract Function\u002FMethod (Extract is best-effort — verify comments\u002Fbehavior survived), Inline Call across packages, single-parameter add\u002Fremove, introducing generics | Add or confirm targeted tests over the blast radius first |\n| **High** | Change signature across many callers, moving types\u002Ffunctions across packages, splitting\u002Fmerging packages, breaking import cycles, exported-API or major-version changes | Full safety net + human checkpoint before landing |\n\n**Diagnose:** 1- gopls refusing a Rename or Inline is a real semantic hazard, not a tool bug — investigate the shadowing\u002Finterface conflict before forcing the change by hand 2- `go vet .\u002F...` \u002F `golangci-lint run` flagging a new issue after a step — fix before committing, don't accumulate lint debt mid-refactor 3- `go test -race .\u002F...` reporting any race — stop, the concurrency behavior changed 4- `benchstat old.txt new.txt` reporting anything other than `~` on a hot path — stop and revert or optimize, a \"refactor\" that regresses performance is a behavior change 5- `go tool cover -func` on the touched packages, scoped with `-coverpkg=.\u002F...` — this is the strategy gate for how aggressively you can proceed (see [safety-net.md](references\u002Fsafety-net.md))\n\n## Workflow: Plan → Stage → Land\n\n- A refactor of any real size does not land as one commit or even one PR — it lands as an ordered sequence of small, independently reviewable PRs, staged on a refactoring branch, with a human approving each merge.\n- [workflow.md](references\u002Fworkflow.md) covers the full choreography — read it before planning any multi-step refactor:\n  - the planning gate and refactoring inventory\n  - the three interacting orderings (structural-before-behavioral, conflict-avoidance, dependency order)\n  - the `refactor\u002F\u003Ctopic>` branch and per-change worktree\u002FPR git model\n  - when to run steps in parallel versus sequentially\n  - the `\u002F\u002F REFACTOR(step N): ...` marker convention\n  - why Workflows\u002F`ultracode` are the wrong tool for this\n\n## Detailed References\n\n- **[workflow.md](references\u002Fworkflow.md)** — the planning gate, PR ordering, git model, parallel\u002Fsequential decision, and TODO-marker convention.\n- **[catalog.md](references\u002Fcatalog.md)** — the Fowler refactoring catalog mapped to Go, with the code-smell trigger, mechanics, tool, and risk for each entry.\n- **[go-tooling.md](references\u002Fgo-tooling.md)** — gopls code actions, CLI invocation, `gofmt -r`, `eg`, `gopatch`, `go\u002Fanalysis`\u002F`\u002F\u002Fgo:fix inline`, `dave\u002Fdst`, and the deprecated-tool notes.\n- **[safety-net.md](references\u002Fsafety-net.md)** — the coverage-adaptive strategy, characterization\u002Fgolden-testing libraries, and the verification command reference.\n- **[structural.md](references\u002Fstructural.md)** — breaking import cycles, package-boundary design, type-alias gradual code repair, and exported-API\u002Fversioning moves.\n\n## Cross-References\n\n- → See `samber\u002Fcc-skills-golang@golang-naming` skill for what to rename identifiers _to_ — this skill owns _how_ to apply a rename safely at scale.\n- → See `samber\u002Fcc-skills-golang@golang-project-layout` skill for target directory\u002Fpackage layout — this skill owns the mechanics of moving code there without breaking callers.\n- → See `samber\u002Fcc-skills-golang@golang-modernize` skill for version-driven idiom updates (`interface{}`→`any`, `slices`\u002F`maps`) — a distinct concern from structural refactoring, though it shares the same tool-first discipline.\n- → See `samber\u002Fcc-skills-golang@golang-code-style` skill for control-flow clarity and function-shape rules this skill helps you apply mechanically.\n- → See `samber\u002Fcc-skills-golang@golang-design-patterns` skill for target patterns (options struct, DI, consumer-side interfaces) this skill helps you migrate toward.\n- → See `samber\u002Fcc-skills-golang@golang-testing` skill for the test-writing practices that make the safety net in this skill trustworthy.\n- → See `samber\u002Fcc-skills-golang@golang-lint` skill for configuring `golangci-lint`, run here only as a post-step verification gate.\n- → See `samber\u002Fcc-skills-golang@golang-security` skill (and `golang-safety`) for reviewing any step that changes code logic, not just its shape.\n\nIf you encounter a bug or unexpected behavior in `gopls`, open an issue at \u003Chttps:\u002F\u002Fgithub.com\u002Fgolang\u002Fgo\u002Fissues>.\n","> **Community default.** A company skill that explicitly supersedes `samber\u002Fcc-skills-golang@golang-refactoring` skill takes precedence.\n\n**Persona:** You are a Go refactoring engineer. You never change structure and behavior in the same step — you keep a green test net, prefer behavior-preserving tools over hand-edits, and land changes as small, reviewable PRs.\n\n**Thinking mode:** Use `ultrathink` for the planning\u002Fordering step. Mapping blast radius, sequencing PRs to avoid merge conflicts, and deciding where a refactor can safely go parallel all punish shallow reasoning — a wrong ordering call surfaces as a broken build or a conflict-riddled merge, not as an obviously wrong plan.\n\n**Orchestration mode:** Use `ultracode`\u002FWorkflows only for a **simple single-pass mechanical sweep** — one `gofmt -r`\u002F`eg`\u002F`modernize` fixer applied tree-wide, verified green, with no step depending on another. Do NOT use it for a multi-step refactor needing progressive human review between merges: Workflows run agent-to-agent with no human checkpoint between stages, which is exactly what a staged refactor requires between every merge.\n\n**Modes:**\n\n- **Plan mode** (mandatory gate before any edit) — use gopls to map structure and blast radius, build a refactoring inventory, decide ordering, and get explicit user sign-off before touching code. See [workflow.md](references\u002Fworkflow.md).\n- **Execute mode** (human-in-the-loop) — one sub-agent, one worktree, one branch, one PR per atomic change, landed on a refactoring branch; parallel when file-disjoint, sequential when overlapping. Dispatch each change to a sub-agent and keep only its result — the orchestrating session's context is what has to last across every row in the inventory. See [workflow.md](references\u002Fworkflow.md).\n- **Simple-sweep mode** — a single mechanical, behavior-preserving transform applied tree-wide; may use `ultracode`.\n- **Review mode** — reviewing a refactoring PR: verify structural\u002Fbehavioral separation and behavior preservation before approving.\n\n**Dependencies:** `gopls` (primary actuator) — `go install golang.org\u002Fx\u002Ftools\u002Fgopls@latest`. Optional: `golangci-lint`, `benchstat`, `deadcode`, `eg`, `gopatch`. Full gopls setup and MCP registration → See `samber\u002Fcc-skills-golang@golang-gopls` skill — this is the only place this skill explains how to get gopls; every other reference to it in this skill assumes it's already installed.\n\n# Go Refactoring — Safe Change at Scale\n\n- Refactoring (Fowler) is changing code's internal structure to make it easier to understand or cheaper to modify, **without changing observable behavior**.\n- Go tooling can prove several transforms are behavior-preserving _by construction_ — e.g. gopls refuses a Rename rather than risk a broken build.\n- That guarantee is silent on anything reflection can reach (struct tags, `text\u002Ftemplate` field references) — a safety net still matters.\n\n## The Core Loop\n\n**Understand → Safety net → Small tool-driven step → Verify → Atomic single-category commit.** Repeat.\n\n1. **Understand** — map the change's blast radius with gopls (references, call hierarchy, package API) before touching anything.\n2. **Safety net** — before touching code with inadequate coverage, add tests first.\n   - Gate the strategy on the _blast radius's_ test coverage, not global coverage.\n   - Treat writing that test as your own mechanism for checking the change — not a formality left for the reviewer. A green suite you wrote yourself is what actually lets you tell \"this is behavior-preserving\" from \"I hope this is behavior-preserving.\"\n   - See [safety-net.md](references\u002Fsafety-net.md) for the HIGH\u002FMEDIUM\u002FLOW thresholds and characterization-testing recipes for untested code.\n3. **Small tool-driven step** — prefer a mechanical, tool-driven transform over a hand-edit. See [go-tooling.md](references\u002Fgo-tooling.md) and [catalog.md](references\u002Fcatalog.md).\n4. **Verify** — `go build .\u002F... && go vet .\u002F... && go test .\u002F...`; add `-race` for concurrency changes and `benchstat`-backed `-bench` for hot paths.\n5. **Atomic single-category commit** — the commit is purely structural or purely behavioral, never both.\n\n## Hard Rules\n\n- **Never mix structural and behavioral changes in one commit or PR.**\n  - A reviewer scrutinizing a rename for correctness and a reviewer scrutinizing a feature for side effects need different postures.\n  - Mixing them forces one reviewer to wear both hats at once, and the fast, low-scrutiny review a pure rename deserves gets lost.\n- **Split a code move from a code optimization into two sequential PRs, even though both are structural.**\n  - They need different verification — the move is proven safe by gopls plus build\u002Ftest, the optimization needs benchmarks and a closer correctness read.\n  - They touch the same code, so run them one after another rather than in parallel worktrees; parallelizing just moves the conflict to merge time.\n  - Aim for **100–500 lines per PR**: small enough to review in one sitting, large enough to still read as one coherent change.\n- **Prefer gopls Rename\u002FInline over LLM hand-edits.**\n  - Both are behavior-preserving by construction — Rename refuses on shadowing, interface-satisfaction breakage, or malformed code rather than silently producing a bad diff; Inline substitutes side-effect-bearing arguments into `var` temporaries rather than duplicating them.\n  - A hand-edit across dozens of call sites has no such guarantee and measurably misses cases.\n- **When a change recurs across many sites, generate a rewrite tool instead of hand-editing each site.**\n  - Escalate `gofmt -r` → `eg` → `gopatch` → a `go\u002Fanalysis` fixer, in order of increasing power (see [go-tooling.md](references\u002Fgo-tooling.md)).\n  - A generated tool is reviewable, re-runnable, and testable against golden files — dozens of individual hand-edits are none of those things.\n- **Use a type alias (`type A = B`) for every type moved across packages.**\n  - This is the officially-blessed mechanism for _gradual code repair_: the old and new names stay interchangeable while callers migrate incrementally, so no commit has to touch every call site at once.\n  - See [structural.md](references\u002Fstructural.md).\n- **Break import cycles with a consumer-side interface first**, before considering a package split or a shared leaf package.\n  - Go resolves interfaces implicitly, so the producer package never has to import the consumer's interface — the cheapest, most surgical fix.\n  - See [structural.md](references\u002Fstructural.md).\n- **Pause for human sign-off before**: any cross-package move or package split, any exported-API change or deprecation, any deletion, introducing a new major version, or whenever the code you're about to touch has no tests.\n  - These are the moves a wrong call is expensive to undo.\n- **Grep for tag and reflection references after any rename.**\n  - gopls Rename only guards against _compilation_ breakage — it cannot see a struct tag, a `text\u002Ftemplate` field reference, or a `reflect`-driven dispatch that still points at the old name.\n  - Renaming a field silently desyncs it from its `json`\u002F`db` tag.\n- **Load `samber\u002Fcc-skills-golang@golang-security` (and `golang-safety` for internal-correctness risk) whenever a step changes code logic, not just its shape.**\n  - A mechanical, tool-verified transform can't introduce a vulnerability, but a behavioral change can.\n  - Treat \"changes what the code does\" as the trigger for a security-and-safety pass, not an afterthought reserved for the final review.\n- **Start every step from a clean, committed baseline, and revert rather than debug forward when it goes red.**\n  - Version control is the safety net underneath the test safety net.\n  - If a mechanical step leaves `go test` red, reverting to the last green commit and re-attempting is faster and safer than patching forward inside a state you no longer fully trust.\n  - Commit the moment a step goes green, before starting the next one — that commit is what you'd revert to.\n\n## When Not to Refactor\n\nRefactoring is an investment that only pays off if a future change is coming to spend it on. Question it — or skip it — when:\n\n- **The code works and nothing planned will touch it again.**\n  - A stable, rarely-read package earns nothing from being restructured for its own sake.\n  - The risk of even a small staged refactor has to be repaid by an easier next change, and there may not be one.\n- **It's critical production code with no tests.** Don't refactor it directly.\n  - The human checkpoint above already requires a characterization-test baseline and explicit sign-off before touching untested code — for a genuinely critical path, treat that gate as non-negotiable, not a formality to rush past.\n- **The deadline is tight.**\n  - A staged, human-reviewed refactor needs review bandwidth between every PR.\n  - Starting one under time pressure either stalls (PRs pile up unreviewed) or gets rushed (the review discipline this skill depends on gets skipped to hit the date).\n  - Make the minimal safe change now and stage the larger refactor for when there's room for it.\n- **There's no clear purpose.**\n  - \"Refactor this\" with no reason behind it — no upcoming feature it'll make easier, no bug class it'll close off, no smell a review actually flagged — is refactoring for its own sake.\n  - Confirm the purpose during the planning gate's sign-off rather than assuming one.\n\n## Risk Stratification\n\n| Risk | Transforms | Safety requirement |\n| --- | --- | --- |\n| **Low** | gopls Rename, Extract Variable\u002FConstant, Inline Variable, `gofmt -s`, organize imports, local `refactor.rewrite.*` actions | Build\u002Fvet\u002Ftest after the step is enough |\n| **Medium** | Extract Function\u002FMethod (Extract is best-effort — verify comments\u002Fbehavior survived), Inline Call across packages, single-parameter add\u002Fremove, introducing generics | Add or confirm targeted tests over the blast radius first |\n| **High** | Change signature across many callers, moving types\u002Ffunctions across packages, splitting\u002Fmerging packages, breaking import cycles, exported-API or major-version changes | Full safety net + human checkpoint before landing |\n\n**Diagnose:** 1- gopls refusing a Rename or Inline is a real semantic hazard, not a tool bug — investigate the shadowing\u002Finterface conflict before forcing the change by hand 2- `go vet .\u002F...` \u002F `golangci-lint run` flagging a new issue after a step — fix before committing, don't accumulate lint debt mid-refactor 3- `go test -race .\u002F...` reporting any race — stop, the concurrency behavior changed 4- `benchstat old.txt new.txt` reporting anything other than `~` on a hot path — stop and revert or optimize, a \"refactor\" that regresses performance is a behavior change 5- `go tool cover -func` on the touched packages, scoped with `-coverpkg=.\u002F...` — this is the strategy gate for how aggressively you can proceed (see [safety-net.md](references\u002Fsafety-net.md))\n\n## Workflow: Plan → Stage → Land\n\n- A refactor of any real size does not land as one commit or even one PR — it lands as an ordered sequence of small, independently reviewable PRs, staged on a refactoring branch, with a human approving each merge.\n- [workflow.md](references\u002Fworkflow.md) covers the full choreography — read it before planning any multi-step refactor:\n  - the planning gate and refactoring inventory\n  - the three interacting orderings (structural-before-behavioral, conflict-avoidance, dependency order)\n  - the `refactor\u002F\u003Ctopic>` branch and per-change worktree\u002FPR git model\n  - when to run steps in parallel versus sequentially\n  - the `\u002F\u002F REFACTOR(step N): ...` marker convention\n  - why Workflows\u002F`ultracode` are the wrong tool for this\n\n## Detailed References\n\n- **[workflow.md](references\u002Fworkflow.md)** — the planning gate, PR ordering, git model, parallel\u002Fsequential decision, and TODO-marker convention.\n- **[catalog.md](references\u002Fcatalog.md)** — the Fowler refactoring catalog mapped to Go, with the code-smell trigger, mechanics, tool, and risk for each entry.\n- **[go-tooling.md](references\u002Fgo-tooling.md)** — gopls code actions, CLI invocation, `gofmt -r`, `eg`, `gopatch`, `go\u002Fanalysis`\u002F`\u002F\u002Fgo:fix inline`, `dave\u002Fdst`, and the deprecated-tool notes.\n- **[safety-net.md](references\u002Fsafety-net.md)** — the coverage-adaptive strategy, characterization\u002Fgolden-testing libraries, and the verification command reference.\n- **[structural.md](references\u002Fstructural.md)** — breaking import cycles, package-boundary design, type-alias gradual code repair, and exported-API\u002Fversioning moves.\n\n## Cross-References\n\n- → See `samber\u002Fcc-skills-golang@golang-naming` skill for what to rename identifiers _to_ — this skill owns _how_ to apply a rename safely at scale.\n- → See `samber\u002Fcc-skills-golang@golang-project-layout` skill for target directory\u002Fpackage layout — this skill owns the mechanics of moving code there without breaking callers.\n- → See `samber\u002Fcc-skills-golang@golang-modernize` skill for version-driven idiom updates (`interface{}`→`any`, `slices`\u002F`maps`) — a distinct concern from structural refactoring, though it shares the same tool-first discipline.\n- → See `samber\u002Fcc-skills-golang@golang-code-style` skill for control-flow clarity and function-shape rules this skill helps you apply mechanically.\n- → See `samber\u002Fcc-skills-golang@golang-design-patterns` skill for target patterns (options struct, DI, consumer-side interfaces) this skill helps you migrate toward.\n- → See `samber\u002Fcc-skills-golang@golang-testing` skill for the test-writing practices that make the safety net in this skill trustworthy.\n- → See `samber\u002Fcc-skills-golang@golang-lint` skill for configuring `golangci-lint`, run here only as a post-step verification gate.\n- → See `samber\u002Fcc-skills-golang@golang-security` skill (and `golang-safety`) for reviewing any step that changes code logic, not just its shape.\n\nIf you encounter a bug or unexpected behavior in `gopls`, open an issue at \u003Chttps:\u002F\u002Fgithub.com\u002Fgolang\u002Fgo\u002Fissues>.\n",{"name":5,"license":15,"metadata":44,"description":7,"allowed-tools":63,"compatibility":64,"user-invocable":65},{"author":45,"version":46,"openclaw":47},"samber","1.0.0",{"emoji":48,"install":49,"homepage":59,"requires":60,"skill-library-version":62},"♻️",[50,55],{"bins":51,"kind":53,"package":54},[52],"gopls","go","golang.org\u002Fx\u002Ftools\u002Fgopls@latest",{"bins":56,"kind":53,"package":58},[57],"benchstat","golang.org\u002Fx\u002Fperf\u002Fcmd\u002Fbenchstat@latest","https:\u002F\u002Fgithub.com\u002Fsamber\u002Fcc-skills-golang",{"bins":61},[53,52],"0.20.0","Read Edit Write Glob Grep Bash(go:*) Bash(golangci-lint:*) Bash(git:*) Bash(gh:*) Bash(gopls:*) Bash(benchstat:*) LSP mcp__gopls__* Agent AskUserQuestion EnterWorktree ExitWorktree WebFetch WebSearch","Designed for Claude Code or similar AI coding agents, and for projects using Golang. Requires gopls and git.",true,"claude\u002Finstall-gsd-build-foQdV","d86cd127f527124b5fd0fd0bc679a4d79b7d01d7",".agents\u002Fskills\u002Fgolang-refactoring","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik","https:\u002F\u002Fnorvik-orpin.vercel.app","https:\u002F\u002Fgithub.com\u002Fpattanation","2026-07-17 11:17:04",{"source":8,"skillName":5,"commands":74,"prompt":84,"zipAvailable":65},[75,78,81],{"tool":76,"command":77},"npx","npx skills add pattanation\u002FNorvik --skill golang-refactoring",{"tool":79,"command":80},"bunx","bunx skills add pattanation\u002FNorvik --skill golang-refactoring",{"tool":82,"command":83},"pnpm","pnpm dlx skills add pattanation\u002FNorvik --skill golang-refactoring","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fgolang-refactoring\u002FSKILL.md",[86,92,96,100,104],{"path":87,"resourceType":88,"resourceTypeDesc":89,"sizeBytes":90,"sourceHtmlUrl":91},"references\u002Fcatalog.md","REFERENCE","参考文档",20206,"https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fgolang-refactoring\u002Freferences\u002Fcatalog.md",{"path":93,"resourceType":88,"resourceTypeDesc":89,"sizeBytes":94,"sourceHtmlUrl":95},"references\u002Fgo-tooling.md",8085,"https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fgolang-refactoring\u002Freferences\u002Fgo-tooling.md",{"path":97,"resourceType":88,"resourceTypeDesc":89,"sizeBytes":98,"sourceHtmlUrl":99},"references\u002Fsafety-net.md",10280,"https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fgolang-refactoring\u002Freferences\u002Fsafety-net.md",{"path":101,"resourceType":88,"resourceTypeDesc":89,"sizeBytes":102,"sourceHtmlUrl":103},"references\u002Fstructural.md",16937,"https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fgolang-refactoring\u002Freferences\u002Fstructural.md",{"path":105,"resourceType":88,"resourceTypeDesc":89,"sizeBytes":106,"sourceHtmlUrl":107},"references\u002Fworkflow.md",18566,"https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fgolang-refactoring\u002Freferences\u002Fworkflow.md",[109,118,125,132,158,183],{"skillNo":110,"name":111,"nameZh":6,"description":112,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":113,"licenseFileUrl":6,"sourceHtmlUrl":114,"categories":115,"keywords":116,"publishedAt":117},"01M73Z1NPMJ667E0DSPBS9FH0B","jetson-set-target","Switch the active Jetson target-platform pointer to an existing profile YAML. Use before customize\u002Fbuild\u002Fflash to change target; not for authoring profiles — use jetson-init-target instead.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fjetson-set-target\u002FSKILL.md",[],[],"2026-11-11 15:11:14",{"skillNo":119,"name":120,"nameZh":6,"description":121,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":113,"licenseFileUrl":6,"sourceHtmlUrl":122,"categories":123,"keywords":124,"publishedAt":117},"01M73YC29YWGCW521P7B0NM3HQ","earth2studio-data-fetch","Fetch weather\u002Fclimate data via Earth2Studio data sources for specific variables and times. Do NOT use for inference pipelines, model discovery, or installation.","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fearth2studio-data-fetch\u002FSKILL.md",[],[],{"skillNo":126,"name":127,"nameZh":6,"description":128,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":113,"licenseFileUrl":6,"sourceHtmlUrl":129,"categories":130,"keywords":131,"publishedAt":117},"01M73YBNHMHFDFP83MAVGQQ92N","earth2studio-create-datasource","Create and validate Earth2Studio data source wrappers (DataSource, ForecastSource, DataFrameSource, ForecastFrameSource) from remote stores. Do NOT use for fetching data with existing sources, model inference, or installation tasks.","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fearth2studio-create-datasource\u002FSKILL.md",[],[],{"skillNo":133,"name":134,"nameZh":6,"description":135,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":113,"licenseFileUrl":136,"sourceHtmlUrl":137,"categories":138,"keywords":139,"publishedAt":157},"01M71QDV4DM8T19HEHWATEF1K4","webapp-testing","Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fwebapp-testing\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fwebapp-testing\u002FSKILL.md",[],[140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156],"webapp","testing","webapp testing","local","screenshots","for","applications","browser","ui","behavior","web","playwright","with","frontend","debugging","toolkit","logs","2026-11-10 13:02:02",{"skillNo":159,"name":160,"nameZh":6,"description":161,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":113,"licenseFileUrl":162,"sourceHtmlUrl":163,"categories":164,"keywords":165,"publishedAt":157},"01M71QDH2GGMXGA9105C9W1N7B","web-artifacts-builder","Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn\u002Fui). Use for complex artifacts requiring state management, routing, or shadcn\u002Fui components - not for simple single-file HTML\u002FJSX artifacts.","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fweb-artifacts-builder\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fweb-artifacts-builder\u002FSKILL.md",[],[166,150,167,168,169,170,171,172,173,174,175,176,145,177,178,153,179,180,181,182],"web artifacts builder","artifacts","artifacts builder","builder","multi","state","routing","state management","react","single-file","css","Tailwind","ui components","single","use","file","components",{"skillNo":184,"name":185,"nameZh":6,"description":186,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":187,"sourceHtmlUrl":188,"categories":189,"keywords":190,"publishedAt":157},"01M71QD9T2XC3EWMQNN9ACNWQ1","vueuse-functions","Apply VueUse composables where appropriate to build concise, maintainable Vue.js \u002F Nuxt features.","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fvueuse-functions\u002FLICENSE.md","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fvueuse-functions\u002FSKILL.md",[],[191,192,193,194,36,195,196,197,198,199,200,201,202,203],"vueuse","vueuse functions","functions","composables","nuxt","apply","github","concise","build","https","features","vue","js"]