template-refactoring · git:20260524.1029201 · 2026-05-24 · sha256 760804f745fbf09a

template-refactoring git:20260524.1029201A

Immutable. This exact content is served forever at /api/v1/blob/760804f745fbf09a.

---
name: template-refactoring
description: |
  Clean-break refactors with migration for the Research Project Template — move logic to src/,
  split modules, rename APIs with test updates. USE WHEN restructuring code, extracting
  modules, removing duplication, or migration without behavior change.
---

# Refactoring

## Natural invoke

- "Extract analysis logic from scripts/ into src/"
- "Split infrastructure/validation monolith into smaller modules"
- "Rename public API with all call sites updated"

## Inputs to confirm

- **Scope** — paths/modules affected.
- **Behavior** — preserve externally observable behavior unless user requests breaking change.

## Workflow

1. **Baseline** — run tests on scope; record coverage.

2. **Move logic** — from scripts to `src/` or `infrastructure/`; keep orchestrators thin.

3. **Update imports** — repo-wide grep; fix tests and docs.

4. **Migration** — if breaking, document in project/infrastructure AGENTS.md; no silent API removal.

5. **Verify** — pytest + ruff/mypy on public scope paths; pipeline smoke if project scripts moved.

## Deliverables

- Before/after structure summary
- Test command output showing pass + coverage maintained

## Verification commands

```bash
uv run pytest <affected-test-path> -v
uv run python -m infrastructure.project.public_scope source-paths | xargs uvx ruff check
uv run python scripts/01_run_tests.py --project <project>  # when project scope
```

## When NOT to use

- **New capability** → [feature-addition](../feature-addition/SKILL.md)
- **Docs-only restructure** → [documentation-creation](../documentation-creation/SKILL.md)

## References

- [`docs/core/architecture.md`](../../core/architecture.md)
- Module line-count gate: `uv run python scripts/gates/module_line_count_check.py`