Install
openclaw skills install @linkxzhou/code-refactor-allRefactor, rewrite, port, migrate, or modernize existing source code - read this skill FIRST, before searching files or planning, even if the named files are not in the workspace. Covers refactor (split a god module into a package, untangle circular imports, move modules, change a signature across callers, swap an internal API or library across a codebase step by step), rewrite (re-implement a component from scratch or on a new framework, e.g. JS to TS + NestJS), and port / translate code to another language (Python to Go or Rust, pyo3 extensions, TS to Go, Java to Kotlin, C to Rust behind an unchanged C header) with fixture parity. Triggers - refactor, restructure, split modules, rewrite, reimplement, port, convert to another language, migrate to a framework, modernize, 重构, 拆分模块, 重写, 代码迁移, 移植到 Rust, 把 Python 改成 Go. Not for tidying one function (simplify-code), type hints, bug fixes, features, perf, database/schema/cloud/infra migrations (e.g. Postgres RDS to Cloud SQL), dependency bumps, or prose translation.
openclaw skills install @linkxzhou/code-refactor-allChange the shape or the language of code while keeping what it does. The promise: every caller, test, and observable output behaves as before unless the user approved a difference. To keep it, pin behavior down before editing, move in green steps, and report evidence rather than confidence.
Local cleanup of one function or snippet belongs to simplify-code. If the request is that small, say so and hand it over.
Read this SKILL.md top to bottom before anything else, even when the workspace is empty or the files the user names are missing. A missing file is not a reason to skip the skill: pick the mode, say what is missing, and deliver what the mode allows (a plan, a contract, or a port of the code the user pasted).
brew install, apt, pip install toolchains, add rustup components, or download compilers/SDKs without the user's approval. If a toolchain is missing, write "Not run: unavailable ()", verify what you can with the tools present, and still deliver the code.Runs are time-limited; a correct port with no report counts as a failure.
PORTING.md (or the plan) with the current N/M result before running any generated/differential inputs. Every later milestone only updates it.| Signal in the request | Mode |
|---|---|
| Same language, structure is the problem (god module, tangled imports, wrong boundaries, widely used API needs a new shape) | refactor: existing code survives and moves in mechanical steps |
| Same language, existing code not worth evolving (unreadable legacy, dead framework, "rewrite / from scratch") | rewrite: the old implementation becomes the oracle |
| Target language differs | port: numbers, strings, errors, ordering, and concurrency semantics shift, so prove parity |
Rules of thumb:
State the chosen mode in one line before starting, with the reason.
The workflows below enforce seven gates:
references/safety-net.md);Never claim a check you did not run. "Not run: no Go toolchain available" is useful; a false "verified" is not.
/opt/homebrew/opt/openjdk@21), inside this workspace only. No installs (hard rule 2).PORTING.md, so the record survives an interrupted session.Run the steps in order, and start a step only when the previous step's Done when holds. At a Gate, stop and wait unless the user already told you to proceed. Every workflow starts after the mode line and ends with the "Output format" report.
Step 1 — Write the contract.
Step 2 — Record the baseline.
references/safety-net.md).Step 3 — Plan the target shape and path.
references/refactoring-catalog.md): parallel change (API with many callers), forwarding shim (move), branch by abstraction (swap a subsystem), consumer-owned interface (break a cycle). Order the steps: contracts/types → implementations → callers → tests → shim removal. Each step should be a single kind of move.references/templates.md) listing the steps in order.Step 4 — Execute one step at a time.
Step 5 — Remove scaffolding.
Step 6 — Verify and report.
Step 1 — Justify the rewrite and inventory the behavior.
references/rewrite-checklist.md).Step 2 — Turn the old code into an oracle.
Step 3 — Plan the seam and cutover.
references/templates.md).Step 4 — Build the new implementation behind the seam.
Step 5 — Differential run and triage.
Step 6 — Cut over, delete, report.
Target: the same behavior, written as a native of the target language would write it.
Step 1 — Write the parity contract.
references/port-playbook.md template: unit of parity (function, CLI call, HTTP response, file); must-match items (outputs, exit codes, error classes, numbers, relied-on ordering); allowed differences; how parity is measured; end state A (standalone replacement), B (permanent bindings), or C (temporary bindings).PORTING.md next to the new code.Step 2 — Inventory and choose the seam.
Step 3 — Characterize the source.
compare.py "<cmd>" that prints N/M.Step 4 — Map the constructs before translating.
references/port-pairs.md (Python↔Go, Python↔Rust, JS/TS↔Rust, TS↔Go, Java↔Kotlin, C↔Rust). For other pairs, use the generic procedure in references/port-playbook.md section 8.Step 5 — Translate module by module.
Step 6 — Prove parity.
Step 7 — Cut over and report.
Port anti-patterns: line-by-line transliteration, clone/unwrap/!!/any/interface{} added just to compile, porting class hierarchies instead of behavior, fixing source bugs mid-port, inventing tests instead of reproducing behavior (more in references/port-playbook.md).
Report in the user's language. Keep it short and evidence-based.
Mode: <refactor | rewrite | port (source → target)> — <one-line reason>
Summary: <what changed>; behavior/API <unchanged | changes listed under Needs approval>
Plan: <steps taken or proposed, in order; mark the current stop point if waiting for sign-off>
Changes:
- <step>: <what and why, one line>
Parity / verification:
- Baseline: <commands + results before>
- After: <same commands + results>
- Differential/fixtures: <N inputs compared, M differences, how triaged> (rewrite/port)
- Not run: <what and why>
Not changed: <tempting edits deliberately left out (scope, API, semantics)>
Needs approval: <proposed behavior/API differences with a concrete input that would differ> (omit if none)
Found, not fixed: <bugs discovered, with location and reproduction> (omit if none)
Follow-ups: <redesign ideas, cleanup left for later, shims still alive and why>
Then show the diff, the new files, or the plan. If the user only asked for a plan or assessment, edit and create nothing (no plan file unless asked), put the plan in the reply, and say so.
| File | Read when |
|---|---|
references/safety-net.md | Code is poorly tested; setting up characterization, golden, or differential tests |
references/refactoring-catalog.md | Planning a refactor: patterns, moves, codemod tools, risk |
references/rewrite-checklist.md | Rewrite: go/no-go, inventory, cutover, rollback |
references/port-playbook.md | Port: contract template, phases, semantic traps, anti-patterns |
references/port-pairs.md | Port: mapping for the specific language pair (read only that section) |
references/templates.md | Writing a plan or parity contract |
references/sources.md | The user asks where a practice comes from |