Agent skill
refactor
Safely refactor code while maintaining all tests and type safety (Daniel Okoye's workflow)
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/refactor-g-zenr-relay-api
SKILL.md
Refactor: $ARGUMENTS
Follow Daniel Okoye's architecture standards:
-
Baseline: Run the test and type-check commands (see project config) BEFORE making any changes. If either fails, fix existing issues first — never refactor on a broken baseline.
-
Analyze: Read the code to be refactored and all its callers
- Map the dependency graph: who imports/calls this code?
- Identify the layer: Core → Service → API
- Check for test coverage of current behavior
-
Refactor rules:
- Preserve the public API — same function signatures, same return types
- If renaming, update ALL callers and tests in the same commit
- Maintain layer boundaries (see Layers in project config) — never reverse dependency flow
- Keep route handlers thin — if moving logic, move it INTO service layer, not out
- All service access still via DI injection (see stack concepts) — no direct imports in API layer
- Keep future annotations pattern in every file (see stack concepts)
- No new untyped/any types — use explicit types
-
If splitting files:
- Update
__init__.pyexports if needed - Ensure no circular imports between layers
- Each new file follows the future annotations pattern (see stack concepts)
- Update
-
If renaming:
- Search entire codebase for old name: source files, tests, config, docs
- Update project documentation if it references renamed items
- Update OpenAPI metadata (summary, description) if endpoints changed
-
Verify: Run the test and type-check commands again. All tests MUST still pass. No new type errors. No regressions.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?