@bovinphang/frontend-craft 2.8.0 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/.claude-plugin/marketplace.json +3 -3
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +378 -339
  4. package/CHANGELOG.zh-CN.md +377 -338
  5. package/CONTRIBUTING.md +371 -361
  6. package/CONTRIBUTING.zh-CN.md +371 -361
  7. package/README.md +545 -493
  8. package/README.openclaw.md +359 -320
  9. package/README.openclaw.zh-CN.md +359 -320
  10. package/README.zh-CN.md +545 -493
  11. package/agents/fec-code-reviewer.md +24 -3
  12. package/agents/fec-debugger.md +1 -1
  13. package/agents/fec-doc-updater.md +1 -1
  14. package/agents/fec-e2e-runner.md +1 -1
  15. package/agents/fec-figma-implementer.md +1 -1
  16. package/agents/fec-performance-optimizer.md +1 -1
  17. package/agents/fec-refactor-cleaner.md +4 -1
  18. package/agents/fec-refactoring-expert.md +81 -0
  19. package/agents/fec-security-reviewer.md +17 -1
  20. package/agents/fec-test-planner.md +1 -1
  21. package/agents/fec-typescript-reviewer.md +24 -8
  22. package/agents/fec-ui-checker.md +11 -11
  23. package/commands/fec-debug.md +1 -1
  24. package/commands/fec-refactor-plan.md +17 -0
  25. package/commands/fec-refactor.md +18 -0
  26. package/commands/fec-review.md +40 -10
  27. package/commands/fec-scaffold.md +1 -1
  28. package/commands/fec-smell.md +17 -0
  29. package/commands/fec-tdd.md +6 -2
  30. package/dist/bin/frontend-craft.js +190 -38
  31. package/dist/hooks/fec-run-tests.js +5 -1
  32. package/dist/hooks/fec-session-start.js +1 -1
  33. package/docs/example-prompts.md +157 -140
  34. package/docs/ja-JP/README.md +534 -493
  35. package/docs/ko-KR/README.md +534 -493
  36. package/docs/project-structure.md +151 -131
  37. package/docs/refactoring/README.md +50 -0
  38. package/docs/refactoring/catalog.md +105 -0
  39. package/docs/refactoring/smell-refactoring-matrix.md +41 -0
  40. package/docs/review-and-diagram-workflows.md +39 -0
  41. package/docs/runtimes/antigravity.md +18 -10
  42. package/docs/runtimes/augment.md +18 -10
  43. package/docs/runtimes/claude.md +191 -177
  44. package/docs/runtimes/claude.zh-CN.md +189 -175
  45. package/docs/runtimes/cline.md +18 -10
  46. package/docs/runtimes/codebuddy.md +18 -10
  47. package/docs/runtimes/codex.md +18 -10
  48. package/docs/runtimes/compatibility.md +27 -0
  49. package/docs/runtimes/copilot.md +18 -10
  50. package/docs/runtimes/cursor.md +18 -10
  51. package/docs/runtimes/gemini.md +18 -10
  52. package/docs/runtimes/kilo.md +18 -10
  53. package/docs/runtimes/openclaw.md +18 -10
  54. package/docs/runtimes/opencode.md +18 -10
  55. package/docs/runtimes/qoder.md +18 -19
  56. package/docs/runtimes/trae.md +18 -10
  57. package/docs/runtimes/windsurf.md +18 -10
  58. package/docs/superpowers/plans/2026-09-26-content-integrity.md +145 -0
  59. package/docs/superpowers/plans/2026-09-26-diagram-quality.md +170 -0
  60. package/docs/superpowers/specs/2026-09-26-diagram-quality-design.md +77 -0
  61. package/docs/superpowers/specs/2026-09-26-project-optimization-design.md +95 -0
  62. package/docs/zh-CN/example-prompts.md +157 -140
  63. package/docs/zh-CN/project-structure.md +148 -128
  64. package/docs/zh-CN/review-and-diagram-workflows.md +39 -0
  65. package/docs/zh-TW/README.md +534 -493
  66. package/localized/zh-CN/agents/fec-code-reviewer.md +22 -3
  67. package/localized/zh-CN/agents/fec-refactor-cleaner.md +3 -0
  68. package/localized/zh-CN/agents/fec-refactoring-expert.md +53 -0
  69. package/localized/zh-CN/agents/fec-security-reviewer.md +16 -0
  70. package/localized/zh-CN/agents/fec-typescript-reviewer.md +23 -7
  71. package/localized/zh-CN/commands/fec-refactor-plan.md +15 -0
  72. package/localized/zh-CN/commands/fec-refactor.md +14 -0
  73. package/localized/zh-CN/commands/fec-review.md +40 -9
  74. package/localized/zh-CN/commands/fec-smell.md +13 -0
  75. package/localized/zh-CN/commands/fec-tdd.md +4 -0
  76. package/localized/zh-CN/skills/eval_queries.json +244 -0
  77. package/localized/zh-CN/skills/fec-code-review/SKILL.md +20 -1
  78. package/localized/zh-CN/skills/fec-code-review/references/report-template.md +11 -1
  79. package/localized/zh-CN/skills/fec-code-smells/SKILL.md +33 -0
  80. package/localized/zh-CN/skills/fec-code-smells/references/detection-guide.md +25 -0
  81. package/localized/zh-CN/skills/fec-code-smells/references/smell-catalog.md +817 -0
  82. package/localized/zh-CN/skills/fec-code-smells/references/smell-to-refactoring-map.md +265 -0
  83. package/localized/zh-CN/skills/fec-image-generation/SKILL.md +31 -1
  84. package/localized/zh-CN/skills/fec-image-generation/assets/quality-examples/README.md +14 -0
  85. package/localized/zh-CN/skills/fec-image-generation/assets/quality-examples/architecture.json +121 -0
  86. package/localized/zh-CN/skills/fec-image-generation/assets/quality-examples/invalid-explicit.json +41 -0
  87. package/localized/zh-CN/skills/fec-image-generation/assets/quality-examples/sequence.json +53 -0
  88. package/localized/zh-CN/skills/fec-image-generation/assets/quality-examples/sequence.mmd +21 -0
  89. package/localized/zh-CN/skills/fec-image-generation/assets/quality-examples/workflow.json +98 -0
  90. package/localized/zh-CN/skills/fec-image-generation/assets/quality-examples/workflow.mmd +7 -0
  91. package/localized/zh-CN/skills/fec-image-generation/references/diagram-workflows.md +10 -3
  92. package/localized/zh-CN/skills/fec-image-generation/references/html-technical-diagrams.md +8 -1
  93. package/localized/zh-CN/skills/fec-image-generation/references/png-qa-autofix.md +9 -2
  94. package/localized/zh-CN/skills/fec-image-generation/scripts/diagram-browser.mjs +90 -0
  95. package/localized/zh-CN/skills/fec-image-generation/scripts/diagram-layout.mjs +176 -0
  96. package/localized/zh-CN/skills/fec-image-generation/scripts/export-diagram.mjs +48 -80
  97. package/localized/zh-CN/skills/fec-image-generation/scripts/mermaid-render.mjs +64 -0
  98. package/localized/zh-CN/skills/fec-image-generation/scripts/png-qa.mjs +35 -4
  99. package/localized/zh-CN/skills/fec-image-generation/scripts/tech-diagram-render.mjs +193 -53
  100. package/localized/zh-CN/skills/fec-refactor-clean/SKILL.md +3 -0
  101. package/localized/zh-CN/skills/fec-refactoring/SKILL.md +83 -0
  102. package/localized/zh-CN/skills/fec-refactoring/references/principles.md +43 -0
  103. package/localized/zh-CN/skills/fec-refactoring/references/refactoring-vs-feature-change.md +25 -0
  104. package/localized/zh-CN/skills/fec-refactoring/references/when-to-refactor.md +17 -0
  105. package/localized/zh-CN/skills/fec-refactoring/references/workflow.md +59 -0
  106. package/localized/zh-CN/skills/fec-refactoring-api/SKILL.md +25 -0
  107. package/localized/zh-CN/skills/fec-refactoring-api/references/api-refactorings.md +496 -0
  108. package/localized/zh-CN/skills/fec-refactoring-catalog/SKILL.md +21 -0
  109. package/localized/zh-CN/skills/fec-refactoring-catalog/references/catalog-index.md +99 -0
  110. package/localized/zh-CN/skills/fec-refactoring-catalog/references/composition-guide.md +49 -0
  111. package/localized/zh-CN/skills/fec-refactoring-catalog/references/selection-guide.md +41 -0
  112. package/localized/zh-CN/skills/fec-refactoring-control/SKILL.md +25 -0
  113. package/localized/zh-CN/skills/fec-refactoring-control/references/conditional-refactorings.md +299 -0
  114. package/localized/zh-CN/skills/fec-refactoring-data/SKILL.md +25 -0
  115. package/localized/zh-CN/skills/fec-refactoring-data/references/data-refactorings.md +248 -0
  116. package/localized/zh-CN/skills/fec-refactoring-encapsulation/SKILL.md +25 -0
  117. package/localized/zh-CN/skills/fec-refactoring-encapsulation/references/encapsulation-refactorings.md +452 -0
  118. package/localized/zh-CN/skills/fec-refactoring-functions/SKILL.md +25 -0
  119. package/localized/zh-CN/skills/fec-refactoring-functions/references/function-refactorings.md +567 -0
  120. package/localized/zh-CN/skills/fec-refactoring-inheritance/SKILL.md +25 -0
  121. package/localized/zh-CN/skills/fec-refactoring-inheritance/references/inheritance-refactorings.md +550 -0
  122. package/localized/zh-CN/skills/fec-refactoring-move-features/SKILL.md +25 -0
  123. package/localized/zh-CN/skills/fec-refactoring-move-features/references/moving-refactorings.md +453 -0
  124. package/localized/zh-CN/skills/fec-refactoring-validation/SKILL.md +52 -0
  125. package/localized/zh-CN/skills/fec-refactoring-validation/references/behavior-preservation.md +15 -0
  126. package/localized/zh-CN/skills/fec-refactoring-validation/references/refactoring-test-checklist.md +25 -0
  127. package/localized/zh-CN/skills/fec-security-review/SKILL.md +16 -0
  128. package/localized/zh-CN/skills/fec-security-review/references/report-template.md +10 -0
  129. package/localized/zh-CN/skills/fec-tdd-workflow/SKILL.md +3 -0
  130. package/localized/zh-CN/skills/metadata.json +408 -50
  131. package/localized/zh-CN/skills/relations.json +271 -3
  132. package/localized/zh-CN/templates/shared/rules/fec-agent-workflow.md +1 -0
  133. package/openclaw.plugin.json +2 -3
  134. package/package.json +27 -17
  135. package/skills/eval_queries.json +244 -0
  136. package/skills/fec-code-review/SKILL.md +20 -1
  137. package/skills/fec-code-review/references/report-template.md +11 -1
  138. package/skills/fec-code-smells/SKILL.md +33 -0
  139. package/skills/fec-code-smells/references/detection-guide.md +25 -0
  140. package/skills/fec-code-smells/references/smell-catalog.md +861 -0
  141. package/skills/fec-code-smells/references/smell-to-refactoring-map.md +265 -0
  142. package/skills/fec-data-fetching/SKILL.md +1 -1
  143. package/skills/fec-image-generation/SKILL.md +31 -1
  144. package/skills/fec-image-generation/assets/quality-examples/README.md +14 -0
  145. package/skills/fec-image-generation/assets/quality-examples/architecture.json +121 -0
  146. package/skills/fec-image-generation/assets/quality-examples/invalid-explicit.json +41 -0
  147. package/skills/fec-image-generation/assets/quality-examples/sequence.json +53 -0
  148. package/skills/fec-image-generation/assets/quality-examples/sequence.mmd +21 -0
  149. package/skills/fec-image-generation/assets/quality-examples/workflow.json +98 -0
  150. package/skills/fec-image-generation/assets/quality-examples/workflow.mmd +7 -0
  151. package/skills/fec-image-generation/references/diagram-workflows.md +10 -3
  152. package/skills/fec-image-generation/references/html-technical-diagrams.md +8 -1
  153. package/skills/fec-image-generation/references/png-qa-autofix.md +9 -2
  154. package/skills/fec-image-generation/scripts/diagram-browser.mjs +90 -0
  155. package/skills/fec-image-generation/scripts/diagram-layout.mjs +176 -0
  156. package/skills/fec-image-generation/scripts/export-diagram.mjs +48 -80
  157. package/skills/fec-image-generation/scripts/mermaid-render.mjs +64 -0
  158. package/skills/fec-image-generation/scripts/png-qa.mjs +35 -4
  159. package/skills/fec-image-generation/scripts/tech-diagram-render.mjs +193 -53
  160. package/skills/fec-legacy-web-standard/SKILL.md +1 -1
  161. package/skills/fec-refactor-clean/SKILL.md +3 -0
  162. package/skills/fec-refactoring/SKILL.md +83 -0
  163. package/skills/fec-refactoring/references/principles.md +60 -0
  164. package/skills/fec-refactoring/references/refactoring-vs-feature-change.md +27 -0
  165. package/skills/fec-refactoring/references/when-to-refactor.md +31 -0
  166. package/skills/fec-refactoring/references/workflow.md +90 -0
  167. package/skills/fec-refactoring-api/SKILL.md +25 -0
  168. package/skills/fec-refactoring-api/references/api-refactorings.md +496 -0
  169. package/skills/fec-refactoring-catalog/SKILL.md +28 -0
  170. package/skills/fec-refactoring-catalog/references/catalog-index.md +99 -0
  171. package/skills/fec-refactoring-catalog/references/composition-guide.md +49 -0
  172. package/skills/fec-refactoring-catalog/references/selection-guide.md +47 -0
  173. package/skills/fec-refactoring-control/SKILL.md +25 -0
  174. package/skills/fec-refactoring-control/references/conditional-refactorings.md +299 -0
  175. package/skills/fec-refactoring-data/SKILL.md +25 -0
  176. package/skills/fec-refactoring-data/references/data-refactorings.md +248 -0
  177. package/skills/fec-refactoring-encapsulation/SKILL.md +25 -0
  178. package/skills/fec-refactoring-encapsulation/references/encapsulation-refactorings.md +452 -0
  179. package/skills/fec-refactoring-functions/SKILL.md +25 -0
  180. package/skills/fec-refactoring-functions/references/function-refactorings.md +567 -0
  181. package/skills/fec-refactoring-inheritance/SKILL.md +25 -0
  182. package/skills/fec-refactoring-inheritance/references/inheritance-refactorings.md +550 -0
  183. package/skills/fec-refactoring-move-features/SKILL.md +25 -0
  184. package/skills/fec-refactoring-move-features/references/moving-refactorings.md +453 -0
  185. package/skills/fec-refactoring-validation/SKILL.md +59 -0
  186. package/skills/fec-refactoring-validation/references/behavior-preservation.md +53 -0
  187. package/skills/fec-refactoring-validation/references/refactoring-test-checklist.md +42 -0
  188. package/skills/fec-security-review/SKILL.md +16 -0
  189. package/skills/fec-security-review/references/report-template.md +10 -0
  190. package/skills/fec-tdd-workflow/SKILL.md +5 -1
  191. package/skills/metadata.json +434 -71
  192. package/skills/relations.json +264 -0
  193. package/templates/shared/rules/fec-agent-workflow.md +1 -0
  194. package/docs/superpowers/plans/2026-05-29-fec-debug.md +0 -491
  195. package/docs/superpowers/specs/2026-05-29-fec-debug-design.md +0 -340
@@ -0,0 +1,83 @@
1
+ ---
2
+ name: fec-refactoring
3
+ description: Use when restructuring existing frontend code while preserving observable behavior, including responsibility extraction, module movement, conditional simplification, API cleanup, or data organization. Do not use for new feature behavior, behavior-changing bug fixes, dependency or framework migrations, or proven dead-code cleanup.
4
+ ---
5
+
6
+ # Skill: Behavior-Preserving Refactoring
7
+
8
+ ## Purpose
9
+
10
+ Restructure live frontend code in small, evidence-backed steps while preserving the behavior users, callers, tests, routes, and integrations can observe.
11
+
12
+ ## Core Contract
13
+
14
+ Every execution follows these rules:
15
+
16
+ 1. **Behavior Preservation** — pure refactoring intentionally changes structure, not observable behavior.
17
+ 2. **Green Baseline First** — record available verification before editing.
18
+ 3. **One Refactoring at a Time** — one primary structural intent per step.
19
+ 4. **Verify Every Step** — run the narrowest meaningful check immediately after each step.
20
+ 5. **Revert Before Repairing** — if a new regression appears, revert that step before widening the edit.
21
+ 6. **Separate Refactoring from Feature Work** — behavior changes belong in a different workflow.
22
+ 7. **Smallest Safe Refactoring First** — prefer the narrowest transformation that fits the evidence.
23
+ 8. **Stay Within the Diff Budget** — stop when actual scope materially exceeds the planned scope.
24
+
25
+ Pure refactoring uses **GREEN → REFACTOR → GREEN**. Do not manufacture a failing behavioral test merely to make a structural change look like feature TDD.
26
+
27
+ ## Procedure
28
+
29
+ 1. **Classify the request.** Confirm that the intended result is structural and behavior-preserving.
30
+ 2. **Discover context.** Read project configuration, affected modules, public exports, routes, state boundaries, tests, and current diff.
31
+ 3. **Record observable contracts.** Capture inputs, outputs, errors, side effects, UI states, events, network calls, state transitions, routes, and public APIs that matter.
32
+ 4. **Establish the baseline.** Run existing narrow checks first; record pre-existing failures rather than attributing them to later edits.
33
+ 5. **Diagnose structural evidence.** Identify the concrete smell or responsibility problem and check likely false positives.
34
+ 6. **Build the safety net.** Reuse relevant tests; add characterization coverage only when needed to preserve existing behavior.
35
+ 7. **Plan ordered micro-refactorings.** For each step record technique, rationale, prerequisites, risk, Diff Budget, verification, and rollback boundary.
36
+ 8. **Apply exactly one primary transformation.** Avoid opportunistic cleanup, formatting churn, or unrelated redesign.
37
+ 9. **Verify immediately.** Compare actual scope with the Diff Budget and run targeted checks.
38
+ 10. **Handle regression.** Revert the current step, confirm the prior baseline, shrink or reorder the transformation, then retry only with evidence.
39
+ 11. **Run broad final validation.** Escalate from targeted checks to typecheck, tests, build, E2E, accessibility, or specialty checks when relevant.
40
+ 12. **Report proof strength.** Use PASS, PARTIAL, or NOT PROVEN and state remaining risk.
41
+
42
+ ## Risk Classification
43
+
44
+ | Risk | Typical scope | Default action |
45
+ | --- | --- | --- |
46
+ | `SAFE` | Local/private code, stable contracts, easy rollback | Execute with step-level verification |
47
+ | `CAUTION` | Cross-module movement, shared state, imports, hooks/composables, lifecycle | Execute only with adequate safety evidence |
48
+ | `DANGER` | Public API, routes, persistence, network contracts, auth, SSR/hydration, broad state or inheritance redesign | Plan and stop for explicit approval unless already authorized |
49
+
50
+ Risk is contextual. A technique name alone never proves that a change is safe.
51
+
52
+ ## Diff Budget
53
+
54
+ Before each executable step record:
55
+
56
+ ```text
57
+ Expected files: N
58
+ Expected functions/components: N
59
+ Expected public API changes: 0
60
+ Expected behavior changes: 0
61
+ ```
62
+
63
+ If the actual diff materially exceeds that budget, stop and reassess instead of silently expanding into redesign.
64
+
65
+ ## References
66
+
67
+ - Load [principles.md](references/principles.md) for the safety rules, evidence model, and risk language.
68
+ - Load [workflow.md](references/workflow.md) for the state machine, baseline handling, rollback, and reporting contract.
69
+ - Load [when-to-refactor.md](references/when-to-refactor.md) when deciding whether restructuring is timely or should be deferred.
70
+ - Load [refactoring-vs-feature-change.md](references/refactoring-vs-feature-change.md) when ownership overlaps feature work, debugging, cleanup, migration, or review.
71
+
72
+ ## Constraints
73
+
74
+ - Do not alter tests merely to accept behavior changed by the refactoring.
75
+ - Do not label auth, permission, routing, persistence, protocol, or public package changes `SAFE` without specific evidence.
76
+ - Do not stack additional structural edits after a newly introduced failure.
77
+ - Do not install a new test framework automatically when the project has none.
78
+ - Do not treat line count, complexity metrics, comments, a switch, or chaining as sufficient proof of a code smell.
79
+ - Do not perform remote Git writes by default.
80
+
81
+ ## Expected Output
82
+
83
+ A small-step refactoring plan or implementation with explicit evidence, risk, Diff Budget, per-step verification, rollback history when applicable, and a final PASS/PARTIAL/NOT PROVEN behavior-preservation verdict.
@@ -0,0 +1,60 @@
1
+ # Refactoring Principles
2
+
3
+ ## Definition
4
+
5
+ Refactoring changes the internal organization of existing code without intentionally changing its observable behavior. The purpose is to make future change safer and easier, not to smuggle new behavior into a structural patch.
6
+
7
+ ## Eight Hard Rules
8
+
9
+ 1. **Behavior Preservation:** define the relevant observable contract before substantial edits.
10
+ 2. **Green Baseline First:** distinguish pre-existing failures from regressions introduced by the current step.
11
+ 3. **One Refactoring at a Time:** keep each step attributable to one structural intent.
12
+ 4. **Verify Every Step:** use feedback at the smallest useful scope before continuing.
13
+ 5. **Revert Before Repairing:** a new regression invalidates the current step; restore the previous state before redesigning it.
14
+ 6. **Separate Feature Work:** new outcomes, changed rules, or changed error behavior are not pure refactoring.
15
+ 7. **Smallest Safe Refactoring First:** prefer a reversible local change over a speculative redesign.
16
+ 8. **Stay Within the Diff Budget:** scope growth is a stop signal, not permission to keep expanding.
17
+
18
+ ## Observable Behavior
19
+
20
+ Depending on the code, preservation can include:
21
+
22
+ - return values, thrown errors, and error mapping;
23
+ - side effects and their ordering when order is semantically significant;
24
+ - requests, payloads, retries, cancellation, and authentication behavior;
25
+ - state transitions, persistence, cache identity, and memoization-sensitive object identity;
26
+ - rendered DOM, loading/error/empty states, focus, keyboard behavior, and emitted events;
27
+ - props, emits, slots, hook/composable contracts, package exports, routes, and URLs.
28
+
29
+ ## Evidence Model
30
+
31
+ Use concrete evidence before choosing a technique:
32
+
33
+ - call sites and dependency direction;
34
+ - ownership of the data being read or mutated;
35
+ - change history or repeated edit locations when available;
36
+ - tests and documented public contracts;
37
+ - runtime registration points, dynamic imports, route tables, i18n keys, Storybook stories, and generated templates;
38
+ - framework lifecycle semantics and state identity.
39
+
40
+ Metrics may indicate where to look, but they do not independently prove the diagnosis.
41
+
42
+ ## Risk Model
43
+
44
+ ### SAFE
45
+
46
+ Local/private scope, no public contract, no subtle lifecycle or persistence semantics, strong rollback path, and relevant verification available.
47
+
48
+ ### CAUTION
49
+
50
+ Cross-file or cross-component restructuring, shared helpers, state ownership changes, lifecycle-sensitive code, dynamic references, or incomplete behavioral coverage.
51
+
52
+ ### DANGER
53
+
54
+ Public APIs, routes, storage schemas, backend contracts, authentication or permissions, SSR/hydration, critical calculations, broad inheritance replacement, or architecture-wide state movement.
55
+
56
+ Do not assign permanent risk to a catalog technique. The same rename can be SAFE for a local variable and DANGER for a serialized field.
57
+
58
+ ## Characterization Before Risky Change
59
+
60
+ When important current behavior is not directly tested, add characterization coverage that describes what the code already does. Such a test can start green; its purpose is to lock existing behavior, not to invent a new requirement.
@@ -0,0 +1,27 @@
1
+ # Refactoring Boundaries
2
+
3
+ ## Pure Refactoring
4
+
5
+ Use the behavior-preserving lane when the requested outcome is structural: clearer responsibilities, smaller functions, better names, safer encapsulation, moved behavior, simplified conditionals, cleaner API shape, or improved data organization without an intentional change to what callers or users observe.
6
+
7
+ Verification model: **GREEN -> REFACTOR -> GREEN**.
8
+
9
+ ## Feature or Behavior-Changing Defect Work
10
+
11
+ A request is not pure refactoring when it adds a capability, changes a business rule, changes accepted input, changes visible output, changes an error outcome, or intentionally changes side effects. Establish the new desired behavior with a failing behavioral test before implementation.
12
+
13
+ ## Debugging
14
+
15
+ When the failure cause is unknown, diagnose root cause before choosing structural changes. A refactoring may become part of a later fix, but it is not a substitute for evidence about the defect.
16
+
17
+ ## Dead-Code Cleanup
18
+
19
+ Proven unused code, stale exports, unused dependencies, obsolete routes, and similar removal work require specialized reference discovery because dynamic imports, configuration, templates, routes, Storybook, CSS, and generated keys can create false positives. Keep cleanup separate from broad restructuring of live code.
20
+
21
+ ## Migration
22
+
23
+ Framework, dependency, router, build-system, state-library, or architecture migrations intentionally alter compatibility boundaries and should be planned as migrations even when they also improve design.
24
+
25
+ ## General Review
26
+
27
+ A merge-readiness review may identify structural findings, but review remains report-first. Diagnosis or a refactoring plan should be an explicit follow-up rather than silent source rewriting during review.
@@ -0,0 +1,31 @@
1
+ # When to Refactor
2
+
3
+ ## Refactor Now
4
+
5
+ Refactor when a structural problem directly increases the cost or risk of the work currently in front of you and the intended behavior can be kept stable. Strong situations include:
6
+
7
+ - a change is difficult because one responsibility is tangled with unrelated work;
8
+ - the same concept must be edited in several places;
9
+ - a public-looking API is difficult to use safely and a compatibility path exists;
10
+ - duplicated decisions are already drifting;
11
+ - state or data ownership is obscuring reliable reasoning;
12
+ - tests are hard to target because responsibilities are fused.
13
+
14
+ ## Record and Defer
15
+
16
+ Defer when the smell is real but unrelated to the current goal, the safety net is insufficient for a risky transformation, or the required compatibility work is larger than the immediate value. Record evidence and a candidate sequence instead of starting an opportunistic redesign.
17
+
18
+ ## Stop Refactoring
19
+
20
+ Stop when:
21
+
22
+ - the structural objective has been met;
23
+ - the next step changes observable behavior;
24
+ - the next step crosses a public contract without an explicit compatibility plan;
25
+ - the Diff Budget is expanding materially;
26
+ - verification can no longer distinguish a regression from the baseline;
27
+ - the remaining motivation is aesthetic preference rather than change cost or correctness risk.
28
+
29
+ ## Practical Heuristic
30
+
31
+ A useful refactoring makes the next meaningful change easier to understand, localize, verify, or reverse. If it does not improve one of those properties, require stronger evidence before continuing.
@@ -0,0 +1,90 @@
1
+ # Refactoring Workflow
2
+
3
+ ## State Machine
4
+
5
+ ```text
6
+ CLASSIFY REQUEST
7
+ -> DISCOVER CONTEXT
8
+ -> ESTABLISH BASELINE
9
+ -> DIAGNOSE STRUCTURAL EVIDENCE
10
+ -> ESTABLISH SAFETY
11
+ -> BUILD ORDERED PLAN
12
+ -> RISK CHECK
13
+ -> EXECUTE ONE STEP
14
+ -> VERIFY STEP
15
+ PASS -> inspect diff -> next step
16
+ FAIL -> revert current step -> confirm baseline -> shrink/replan
17
+ -> FINAL VALIDATION
18
+ -> REPORT
19
+ ```
20
+
21
+ ## Context Discovery
22
+
23
+ Read only what is needed to establish facts:
24
+
25
+ - `package.json`, workspace manifests, TypeScript and lint configuration;
26
+ - test configuration and scripts;
27
+ - affected modules, callers, imports, barrel exports, routes, and registration points;
28
+ - state/store ownership and persistence boundaries;
29
+ - framework conventions, lifecycle-sensitive code, async effects, and current Git diff.
30
+
31
+ ## Baseline Handling
32
+
33
+ If the baseline is green, any newly failing relevant check after a step is presumptive evidence that the step regressed behavior or structure.
34
+
35
+ If the baseline is already red:
36
+
37
+ 1. record exact failing commands and symptoms;
38
+ 2. do not claim later failures are caused by refactoring without comparison evidence;
39
+ 3. avoid risky restructuring unless the preserved contract remains credible;
40
+ 4. separate unexplained failure diagnosis from structural change.
41
+
42
+ ## Plan Step Contract
43
+
44
+ Each executable step records:
45
+
46
+ ```text
47
+ Target:
48
+ Technique:
49
+ Intent:
50
+ Prerequisites:
51
+ Risk: SAFE | CAUTION | DANGER
52
+ Expected files:
53
+ Expected functions/components:
54
+ Expected public API changes: 0
55
+ Expected behavior changes: 0
56
+ Verification:
57
+ Rollback boundary:
58
+ ```
59
+
60
+ Order prerequisites before larger moves. For example, expose a stable query before extracting logic that depends on it, or isolate a conditional before replacing its dispatch mechanism.
61
+
62
+ ## Step Failure Protocol
63
+
64
+ When a previously green check becomes red:
65
+
66
+ 1. stop;
67
+ 2. revert only the current structural step;
68
+ 3. rerun the affected check to confirm restoration;
69
+ 4. identify whether the failed assumption was behavior, identity, lifecycle, ordering, typing, or dependency related;
70
+ 5. shrink the step or add a safer prerequisite;
71
+ 6. retry only after the plan is again evidence-backed.
72
+
73
+ Do not spread fixes across unrelated modules merely to make the suite green.
74
+
75
+ ## Final Validation
76
+
77
+ Use a narrow-to-broad ladder:
78
+
79
+ 1. nearest syntax/type/static check;
80
+ 2. targeted unit or component tests;
81
+ 3. affected package or integration tests;
82
+ 4. lint and full typecheck;
83
+ 5. broader test suite;
84
+ 6. build, SSR, E2E, visual, accessibility, performance, or specialty checks when affected.
85
+
86
+ ## Proof Verdict
87
+
88
+ - **PASS:** the relevant observable contract is adequately covered and required checks pass.
89
+ - **PARTIAL:** executed checks pass, but important behavior remains incompletely covered.
90
+ - **NOT PROVEN:** missing dependencies, environment limits, baseline failures, or insufficient safety evidence prevent a credible preservation claim.
@@ -0,0 +1,25 @@
1
+ ---
2
+ name: fec-refactoring-api
3
+ description: Use when behavior-preserving frontend refactoring focuses on function API shape, flags, dependencies, mutability, construction, or command/function trade-offs, and the selected technique needs family-specific mechanics, risks, and JavaScript/TypeScript/React/Vue adaptation.
4
+ ---
5
+
6
+ # API Refactorings
7
+
8
+ ## Overview
9
+ Use this family after evidence identifies a fitting structural transformation. Apply one primary technique at a time and verify immediately.
10
+
11
+ ## Procedure
12
+ 1. Confirm the selected technique and its preconditions in [API Refactorings](references/api-refactorings.md).
13
+ 2. Record affected behavior and a diff budget.
14
+ 3. Apply only the selected technique's smallest viable step.
15
+ 4. Verify the step before composing another transformation.
16
+ 5. Stop and reassess when public contracts, lifecycle, state identity, or actual scope exceed expectations.
17
+
18
+ ## Quick Reference
19
+ The family reference contains 10 canonical techniques with intent, signals, avoid conditions, mechanics, preservation checkpoints, smell links, composition hints, JavaScript/TypeScript notes, React/Vue notes, adaptation guidance, and original frontend examples.
20
+
21
+ ## Common Mistakes
22
+ - Choosing a technique by name without checking its preconditions.
23
+ - Combining several structural intentions in one diff.
24
+ - Assuming a classical class-based form is mandatory in modern frontend code.
25
+ - Treating passing tests as proof when the relevant behavior is not covered.