@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,49 @@
1
+ # Refactoring Composition Guide
2
+
3
+ Relationships here are conditional. Apply an edge only when its enabling condition exists and verify every intermediate state.
4
+
5
+ ## Inverse / Trade-off Pairs
6
+ - `RF-EXTRACT-FUNCTION` ↔ `RF-INLINE-FUNCTION`: introduce a meaningful boundary or remove an indirection that no longer pays for itself.
7
+ - `RF-EXTRACT-VARIABLE` ↔ `RF-INLINE-VARIABLE`: name an important expression or remove a name that obscures rather than clarifies.
8
+ - `RF-PULL-UP-METHOD` ↔ `RF-PUSH-DOWN-METHOD`: move behavior toward the level where it is truly shared or specialized.
9
+ - `RF-PULL-UP-FIELD` ↔ `RF-PUSH-DOWN-FIELD`: place data at the narrowest hierarchy level that accurately owns it.
10
+ - `RF-HIDE-DELEGATE` ↔ `RF-REMOVE-MIDDLE-MAN`: trade client coupling against excessive pass-through indirection.
11
+
12
+ ## Common Conditional Sequences
13
+ ### Extraction enables ownership movement
14
+ `RF-EXTRACT-FUNCTION` → `RF-MOVE-FUNCTION`
15
+
16
+ Use when only part of a larger function is dominated by another module’s data. Extract a coherent unit first, then move that unit to the better owner.
17
+
18
+ ### Query extraction enables function extraction
19
+ `RF-REPLACE-TEMP-WITH-QUERY` → `RF-EXTRACT-FUNCTION`
20
+
21
+ Use when local temporaries make the desired function boundary carry awkward state. Confirm the query is safe to recompute or cache appropriately.
22
+
23
+ ### Type separation enables variant dispatch
24
+ `RF-REPLACE-TYPE-CODE-WITH-SUBCLASSES` → `RF-REPLACE-CONDITIONAL-WITH-POLYMORPHISM`
25
+
26
+ Use in genuine OO/domain hierarchies. In frontend code, a discriminated union plus strategy/component map may express the same intent without subclasses.
27
+
28
+ ### Regroup then re-extract
29
+ `RF-INLINE-FUNCTION` / `RF-INLINE-CLASS` → regroup scattered logic → `RF-EXTRACT-FUNCTION` / `RF-EXTRACT-CLASS`
30
+
31
+ Use for Shotgun Surgery caused by poorly placed tiny abstractions. The larger intermediate unit must remain verified.
32
+
33
+ ### Split a process, then place responsibilities
34
+ `RF-SPLIT-PHASE` → `RF-EXTRACT-FUNCTION` → `RF-MOVE-FUNCTION`
35
+
36
+ Use when a process has separable stages and a stage has a clearer owner after extraction.
37
+
38
+ ### Control a global before changing its representation
39
+ `RF-ENCAPSULATE-VARIABLE` → `RF-RENAME-VARIABLE` / `RF-MOVE-FUNCTION`
40
+
41
+ Use when a shared variable needs an access seam before changing naming or ownership.
42
+
43
+ ### Encapsulate structured data before its collections
44
+ `RF-ENCAPSULATE-RECORD` → `RF-ENCAPSULATE-COLLECTION`
45
+
46
+ Use when callers currently manipulate raw record fields and raw collection mutation at the same boundary.
47
+
48
+ ## Stop Conditions
49
+ Do not continue a sequence when the current step fails verification, exceeds its diff budget, changes a public contract unexpectedly, or removes the precondition for the next edge.
@@ -0,0 +1,47 @@
1
+ # Refactoring Selection Guide
2
+
3
+ Choose by observed cause. The same smell can require different transformations.
4
+
5
+ ## Long Function
6
+ - **Mixed named intentions** → `RF-EXTRACT-FUNCTION`; require a coherent slice and stable inputs/outputs.
7
+ - **Temporaries obstruct extraction** → `RF-REPLACE-TEMP-WITH-QUERY`; avoid when repeated computation is materially expensive or effectful.
8
+ - **Several inputs travel as one concept** → `RF-INTRODUCE-PARAMETER-OBJECT` or `RF-PRESERVE-WHOLE-OBJECT`.
9
+ - **Large conditional varies by type/variant** → first consider `RF-DECOMPOSE-CONDITIONAL`; use `RF-REPLACE-CONDITIONAL-WITH-POLYMORPHISM` only when repeated variant behavior warrants dispatch.
10
+ - **One loop performs unrelated jobs** → `RF-SPLIT-LOOP` when separate passes preserve ordering/performance constraints.
11
+ - **Risk/verification:** preserve exceptions, side effects, event order, hook dependencies, state transitions, and async sequencing.
12
+
13
+ ## Long Parameter List
14
+ - **A value can be derived from another parameter or stable receiver** → `RF-REPLACE-PARAMETER-WITH-QUERY`.
15
+ - **Callers unpack one existing object** → `RF-PRESERVE-WHOLE-OBJECT`.
16
+ - **Values repeatedly travel together as a concept** → `RF-INTRODUCE-PARAMETER-OBJECT`.
17
+ - **A boolean/enum selects behavior** → `RF-REMOVE-FLAG-ARGUMENT`; not for ordinary domain data.
18
+ - **Several functions share the same data context** → `RF-COMBINE-FUNCTIONS-INTO-CLASS`, interpreted as class/module/hook/composable/service according to the codebase.
19
+ - **Risk/verification:** public signatures and callback/component contracts raise compatibility risk.
20
+
21
+ ## Mutable Data
22
+ - **Uncontrolled shared write access** → `RF-ENCAPSULATE-VARIABLE`.
23
+ - **One variable serves multiple meanings** → `RF-SPLIT-VARIABLE`.
24
+ - **A read operation also mutates** → `RF-SEPARATE-QUERY-FROM-MODIFIER`.
25
+ - **Stored derived data drifts** → `RF-REPLACE-DERIVED-VARIABLE-WITH-QUERY`; evaluate recomputation cost and memoization semantics.
26
+ - **Identity is unnecessary and mutation leaks** → consider `RF-CHANGE-REFERENCE-TO-VALUE`.
27
+ - **Risk/verification:** React/Vue identity, reactivity, memoization, subscriptions, and persistence are part of behavior.
28
+
29
+ ## Divergent Change
30
+ - **One function has sequential concerns** → `RF-SPLIT-PHASE` or `RF-EXTRACT-FUNCTION`.
31
+ - **Behavior primarily belongs with another data owner** → `RF-MOVE-FUNCTION`.
32
+ - **A responsibility cluster has its own state and rules** → `RF-EXTRACT-CLASS`, including a frontend module/service/hook/composable equivalent.
33
+ - **Risk/verification:** do not split merely by technical layer if the business responsibility is cohesive.
34
+
35
+ ## Shotgun Surgery
36
+ - **Behavior/data belonging together is scattered** → `RF-MOVE-FUNCTION` / `RF-MOVE-FIELD`.
37
+ - **Many functions share one context** → `RF-COMBINE-FUNCTIONS-INTO-CLASS` or `RF-COMBINE-FUNCTIONS-INTO-TRANSFORM`.
38
+ - **A pipeline has separable stages** → `RF-SPLIT-PHASE`.
39
+ - **Premature tiny abstractions caused scattering** → `RF-INLINE-FUNCTION` / `RF-INLINE-CLASS` may first regroup logic, followed by a better extraction.
40
+ - **Risk/verification:** keep each regrouping step independently behavior-preserving; temporary larger units are acceptable if verified.
41
+
42
+ ## Primitive Obsession
43
+ - **A primitive carries invariants/formatting/domain behavior** → `RF-REPLACE-PRIMITIVE-WITH-OBJECT`; a TypeScript alias alone does not encapsulate runtime behavior.
44
+ - **A type code drives repeated variant behavior** → consider `RF-REPLACE-TYPE-CODE-WITH-SUBCLASSES` or a discriminated-union/strategy equivalent.
45
+ - **Repeated conditional variation is the real problem** → `RF-REPLACE-CONDITIONAL-WITH-POLYMORPHISM` using the most idiomatic dispatch form.
46
+ - **Several primitives form one concept** → `RF-EXTRACT-CLASS` or `RF-INTRODUCE-PARAMETER-OBJECT`.
47
+ - **Risk/verification:** serialized DTOs, URL values, storage, validation, and API payload shape may be public contracts.
@@ -0,0 +1,25 @@
1
+ ---
2
+ name: fec-refactoring-control
3
+ description: Use when behavior-preserving frontend refactoring focuses on conditional complexity, repeated branches, guards, special cases, or internal invariants, and the selected technique needs family-specific mechanics, risks, and JavaScript/TypeScript/React/Vue adaptation.
4
+ ---
5
+
6
+ # Conditional Logic 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 [Conditional Logic Refactorings](references/conditional-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 6 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.
@@ -0,0 +1,299 @@
1
+ # Conditional Logic Refactorings
2
+
3
+ These cards transform the supplied standard catalog into concise operational guidance for frontend agents. Standard IDs/names are preserved; examples and framework adaptations are original.
4
+
5
+ ## RF-DECOMPOSE-CONDITIONAL — Decompose Conditional
6
+
7
+ ### Intent
8
+ Extract a complex condition and its branches into named operations that explain why each path exists.
9
+
10
+ ### Typical Signals
11
+ - A conditional mixes domain predicates with substantial branch calculations.
12
+
13
+ ### Avoid When
14
+ - Do not scatter tiny helpers when the condition is already simple and self-explanatory.
15
+
16
+ ### Preconditions
17
+ - Current observable behavior and affected callers are understood.
18
+ - The target scope is inside a declared diff budget and can be verified after this one primary transformation.
19
+
20
+ ### Mechanics
21
+ 1. Extract/name the predicate.
22
+ 2. Extract the then branch if it has a distinct purpose.
23
+ 3. Extract the else branch if useful.
24
+ 4. Verify short-circuiting, side effects, and branch results.
25
+
26
+ ### Behavior-Preservation Checkpoints
27
+ - Compare inputs, outputs, exceptions, side effects, ordering, and public contracts before/after the step.
28
+ - For frontend code, also check UI state, events, focus, network behavior, lifecycle/state transitions, and relevant identity semantics.
29
+
30
+ ### Related Code Smells
31
+ - `SMELL-LONG-FUNCTION`
32
+
33
+ ### Composes Well With
34
+ - Combine only with a separately justified next transformation; no fixed sequence is required.
35
+
36
+ ### JavaScript Notes
37
+ - Preserve short-circuiting, exception timing, side-effect order, and default/fallthrough behavior.
38
+
39
+ ### TypeScript Notes
40
+ - Use discriminated unions and `never` exhaustiveness when they clarify variants; assertions are not a substitute for runtime validation.
41
+
42
+ ### React Notes
43
+ - Guard clauses must not skip loading cleanup or effect teardown; strategy/component registries often fit variant rendering better than classes.
44
+
45
+ ### Vue Notes
46
+ - Preserve `finally`, pending/error state, watcher/effect behavior, and component branch lifecycle.
47
+
48
+ ### Frontend-Craft Adaptation
49
+ - “Polymorphism” includes strategies, discriminated-union dispatch, handler/component registries, and delegation; use class hierarchies only when natural.
50
+
51
+ ### Example Transformation
52
+ Before: a compose permission `if` embeds tenant/date/quota checks and actions. After: use `canSendNow()` plus named branch functions.
53
+
54
+ ## RF-CONSOLIDATE-CONDITIONAL-EXPRESSION — Consolidate Conditional Expression
55
+
56
+ ### Intent
57
+ Combine separate checks that produce the same outcome into one named condition.
58
+
59
+ ### Typical Signals
60
+ - Several adjacent conditions return/assign the same result for one conceptual reason.
61
+
62
+ ### Avoid When
63
+ - Keep conditions separate when they represent different outcomes, logging, or error reasons users must distinguish.
64
+
65
+ ### Preconditions
66
+ - Current observable behavior and affected callers are understood.
67
+ - The target scope is inside a declared diff budget and can be verified after this one primary transformation.
68
+
69
+ ### Mechanics
70
+ 1. Confirm branches truly have the same effect.
71
+ 2. Combine predicates without changing short-circuit order.
72
+ 3. Extract a named predicate when it clarifies purpose.
73
+ 4. Verify side effects and error distinctions.
74
+
75
+ ### Behavior-Preservation Checkpoints
76
+ - Compare inputs, outputs, exceptions, side effects, ordering, and public contracts before/after the step.
77
+ - For frontend code, also check UI state, events, focus, network behavior, lifecycle/state transitions, and relevant identity semantics.
78
+
79
+ ### Related Code Smells
80
+ - No single code smell required; select from concrete structural evidence.
81
+
82
+ ### Composes Well With
83
+ - Combine only with a separately justified next transformation; no fixed sequence is required.
84
+
85
+ ### JavaScript Notes
86
+ - Preserve short-circuiting, exception timing, side-effect order, and default/fallthrough behavior.
87
+
88
+ ### TypeScript Notes
89
+ - Use discriminated unions and `never` exhaustiveness when they clarify variants; assertions are not a substitute for runtime validation.
90
+
91
+ ### React Notes
92
+ - Guard clauses must not skip loading cleanup or effect teardown; strategy/component registries often fit variant rendering better than classes.
93
+
94
+ ### Vue Notes
95
+ - Preserve `finally`, pending/error state, watcher/effect behavior, and component branch lifecycle.
96
+
97
+ ### Frontend-Craft Adaptation
98
+ - “Polymorphism” includes strategies, discriminated-union dispatch, handler/component registries, and delegation; use class hierarchies only when natural.
99
+
100
+ ### Example Transformation
101
+ Before: three separate guards all disable Send for the same “draft not sendable” outcome. After: combine only if individual user-facing reasons are not lost.
102
+
103
+ ## RF-REPLACE-NESTED-CONDITIONAL-WITH-GUARD-CLAUSES — Replace Nested Conditional with Guard Clauses
104
+
105
+ ### Intent
106
+ Flatten exceptional or early-exit cases so the main path is visible.
107
+
108
+ ### Typical Signals
109
+ - Nested `if/else` primarily checks invalid/special cases before normal work.
110
+
111
+ ### Avoid When
112
+ - Do not return early before required cleanup, `finally`, loading-state reset, or transaction completion.
113
+
114
+ ### Preconditions
115
+ - Current observable behavior and affected callers are understood.
116
+ - The target scope is inside a declared diff budget and can be verified after this one primary transformation.
117
+
118
+ ### Mechanics
119
+ 1. Identify cases that can return/throw early.
120
+ 2. Convert the outermost special case to a guard.
121
+ 3. Repeat one nesting level at a time.
122
+ 4. Verify cleanup, loading state, and finally semantics.
123
+
124
+ ### Behavior-Preservation Checkpoints
125
+ - Compare inputs, outputs, exceptions, side effects, ordering, and public contracts before/after the step.
126
+ - For frontend code, also check UI state, events, focus, network behavior, lifecycle/state transitions, and relevant identity semantics.
127
+
128
+ ### Related Code Smells
129
+ - No single code smell required; select from concrete structural evidence.
130
+
131
+ ### Composes Well With
132
+ - Combine only with a separately justified next transformation; no fixed sequence is required.
133
+
134
+ ### JavaScript Notes
135
+ - Preserve short-circuiting, exception timing, side-effect order, and default/fallthrough behavior.
136
+
137
+ ### TypeScript Notes
138
+ - Use discriminated unions and `never` exhaustiveness when they clarify variants; assertions are not a substitute for runtime validation.
139
+
140
+ ### React Notes
141
+ - Guard clauses must not skip loading cleanup or effect teardown; strategy/component registries often fit variant rendering better than classes.
142
+
143
+ ### Vue Notes
144
+ - Preserve `finally`, pending/error state, watcher/effect behavior, and component branch lifecycle.
145
+
146
+ ### Frontend-Craft Adaptation
147
+ - “Polymorphism” includes strategies, discriminated-union dispatch, handler/component registries, and delegation; use class hierarchies only when natural.
148
+
149
+ ### Example Transformation
150
+ Before: a submit handler nests auth → draft → recipients → send. After: guard invalid states early while preserving `finally { setLoading(false) }`.
151
+
152
+ ## RF-REPLACE-CONDITIONAL-WITH-POLYMORPHISM — Replace Conditional with Polymorphism
153
+
154
+ ### Intent
155
+ Move repeated variant-specific behavior behind a dispatch boundary so each variant owns its behavior.
156
+
157
+ ### Typical Signals
158
+ - The same type/status discriminator drives behavior in several locations.
159
+
160
+ ### Avoid When
161
+ - Do not replace a single clear conditional with a class hierarchy; frontend dispatch may be simpler as a strategy map or discriminated union.
162
+
163
+ ### Preconditions
164
+ - Current observable behavior and affected callers are understood.
165
+ - The target scope is inside a declared diff budget and can be verified after this one primary transformation.
166
+
167
+ ### Mechanics
168
+ 1. Identify the stable discriminator and variant behaviors.
169
+ 2. Choose an idiomatic dispatch form: strategy map, discriminated union, handler/component registry, delegation, or class hierarchy.
170
+ 3. Move one behavior into the dispatch boundary.
171
+ 4. Verify exhaustiveness and default/error behavior.
172
+
173
+ ### Behavior-Preservation Checkpoints
174
+ - Compare inputs, outputs, exceptions, side effects, ordering, and public contracts before/after the step.
175
+ - For frontend code, also check UI state, events, focus, network behavior, lifecycle/state transitions, and relevant identity semantics.
176
+
177
+ ### Related Code Smells
178
+ - `SMELL-LONG-FUNCTION`
179
+ - `SMELL-PRIMITIVE-OBSESSION`
180
+ - `SMELL-REPEATED-SWITCHES`
181
+
182
+ ### Composes Well With
183
+ - Combine only with a separately justified next transformation; no fixed sequence is required.
184
+
185
+ ### JavaScript Notes
186
+ - Preserve short-circuiting, exception timing, side-effect order, and default/fallthrough behavior.
187
+
188
+ ### TypeScript Notes
189
+ - Use discriminated unions and `never` exhaustiveness when they clarify variants; assertions are not a substitute for runtime validation.
190
+
191
+ ### React Notes
192
+ - Guard clauses must not skip loading cleanup or effect teardown; strategy/component registries often fit variant rendering better than classes.
193
+
194
+ ### Vue Notes
195
+ - Preserve `finally`, pending/error state, watcher/effect behavior, and component branch lifecycle.
196
+
197
+ ### Frontend-Craft Adaptation
198
+ - “Polymorphism” includes strategies, discriminated-union dispatch, handler/component registries, and delegation; use class hierarchies only when natural.
199
+
200
+ ### Example Transformation
201
+ Before: message type switches appear in rendering and actions. After: a typed handler/component registry dispatches by discriminant; no subclass hierarchy is required.
202
+
203
+ ## RF-INTRODUCE-SPECIAL-CASE — Introduce Special Case
204
+
205
+ ### Intent
206
+ Represent a recurring exceptional value with an object/value that supplies common behavior, reducing repeated checks.
207
+
208
+ ### Typical Signals
209
+ - Many callers repeat the same null/unknown/sentinel handling.
210
+
211
+ ### Avoid When
212
+ - Avoid when special-case behavior varies by caller or hiding absence would obscure an error.
213
+
214
+ ### Preconditions
215
+ - Current observable behavior and affected callers are understood.
216
+ - The target scope is inside a declared diff budget and can be verified after this one primary transformation.
217
+
218
+ ### Mechanics
219
+ 1. List repeated checks and common behavior.
220
+ 2. Create the special-case representation.
221
+ 3. Return it from one boundary and migrate consumers.
222
+ 4. Remove duplicated checks only after behavior is equivalent.
223
+
224
+ ### Behavior-Preservation Checkpoints
225
+ - Compare inputs, outputs, exceptions, side effects, ordering, and public contracts before/after the step.
226
+ - For frontend code, also check UI state, events, focus, network behavior, lifecycle/state transitions, and relevant identity semantics.
227
+
228
+ ### Related Code Smells
229
+ - `SMELL-TEMPORARY-FIELD`
230
+
231
+ ### Composes Well With
232
+ - Combine only with a separately justified next transformation; no fixed sequence is required.
233
+
234
+ ### JavaScript Notes
235
+ - Preserve short-circuiting, exception timing, side-effect order, and default/fallthrough behavior.
236
+
237
+ ### TypeScript Notes
238
+ - Use discriminated unions and `never` exhaustiveness when they clarify variants; assertions are not a substitute for runtime validation.
239
+
240
+ ### React Notes
241
+ - Guard clauses must not skip loading cleanup or effect teardown; strategy/component registries often fit variant rendering better than classes.
242
+
243
+ ### Vue Notes
244
+ - Preserve `finally`, pending/error state, watcher/effect behavior, and component branch lifecycle.
245
+
246
+ ### Frontend-Craft Adaptation
247
+ - “Polymorphism” includes strategies, discriminated-union dispatch, handler/component registries, and delegation; use class hierarchies only when natural.
248
+
249
+ ### Example Transformation
250
+ Before: every recipient display checks `contact == null`. After: a stable `UnknownContact`/fallback view model supplies the shared display behavior.
251
+
252
+ ## RF-INTRODUCE-ASSERTION — Introduce Assertion
253
+
254
+ ### Intent
255
+ Make an internal invariant executable where violating it indicates a programming error.
256
+
257
+ ### Typical Signals
258
+ - Code relies on a condition that is assumed but not expressed.
259
+
260
+ ### Avoid When
261
+ - Assertions do not replace user-input validation, network error handling, permissions, or recoverable business errors.
262
+
263
+ ### Preconditions
264
+ - Current observable behavior and affected callers are understood.
265
+ - The target scope is inside a declared diff budget and can be verified after this one primary transformation.
266
+
267
+ ### Mechanics
268
+ 1. State the invariant precisely.
269
+ 2. Place the assertion at the boundary where the assumption must hold.
270
+ 3. Ensure production/runtime assertion policy is understood.
271
+ 4. Keep normal validation for expected invalid inputs.
272
+
273
+ ### Behavior-Preservation Checkpoints
274
+ - Compare inputs, outputs, exceptions, side effects, ordering, and public contracts before/after the step.
275
+ - For frontend code, also check UI state, events, focus, network behavior, lifecycle/state transitions, and relevant identity semantics.
276
+
277
+ ### Related Code Smells
278
+ - `SMELL-COMMENTS`
279
+
280
+ ### Composes Well With
281
+ - Combine only with a separately justified next transformation; no fixed sequence is required.
282
+
283
+ ### JavaScript Notes
284
+ - Preserve short-circuiting, exception timing, side-effect order, and default/fallthrough behavior.
285
+
286
+ ### TypeScript Notes
287
+ - Use discriminated unions and `never` exhaustiveness when they clarify variants; assertions are not a substitute for runtime validation.
288
+
289
+ ### React Notes
290
+ - Guard clauses must not skip loading cleanup or effect teardown; strategy/component registries often fit variant rendering better than classes.
291
+
292
+ ### Vue Notes
293
+ - Preserve `finally`, pending/error state, watcher/effect behavior, and component branch lifecycle.
294
+
295
+ ### Frontend-Craft Adaptation
296
+ - “Polymorphism” includes strategies, discriminated-union dispatch, handler/component registries, and delegation; use class hierarchies only when natural.
297
+
298
+ ### Example Transformation
299
+ Before: an internal normalized draft silently assumes at least one recipient. After: assert that invariant after validated construction, not at raw user input.
@@ -0,0 +1,25 @@
1
+ ---
2
+ name: fec-refactoring-data
3
+ description: Use when behavior-preserving frontend refactoring focuses on variable meaning, field naming, derived state, or reference/value identity, and the selected technique needs family-specific mechanics, risks, and JavaScript/TypeScript/React/Vue adaptation.
4
+ ---
5
+
6
+ # Data 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 [Data Refactorings](references/data-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 5 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.