@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,452 @@
1
+ # Encapsulation 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-ENCAPSULATE-RECORD — Encapsulate Record
6
+
7
+ ### Intent
8
+ Replace uncontrolled record access with a boundary that owns representation and allowed operations.
9
+
10
+ ### Typical Signals
11
+ - A raw record is widely read/written and representation changes leak to callers.
12
+
13
+ ### Avoid When
14
+ - Immutable DTOs at a clear transport boundary may not need behavioral wrapping.
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. Create an accessor/factory/object boundary around the record.
22
+ 2. Migrate reads first, then controlled writes.
23
+ 3. Keep external serialization shape explicit if it is a contract.
24
+ 4. Change internal representation only after access is controlled.
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-DATA-CLASS`
32
+
33
+ ### Composes Well With
34
+ - Combine only with a separately justified next transformation; no fixed sequence is required.
35
+
36
+ ### JavaScript Notes
37
+ - Watch object identity, property descriptors, iteration order, mutability, and serialization.
38
+
39
+ ### TypeScript Notes
40
+ - Use `readonly`, narrow interfaces, branded/value types only when they model real invariants; keep DTO translations explicit.
41
+
42
+ ### React Notes
43
+ - Preserve props/state identity expectations, memoization, context boundaries, and controlled/uncontrolled contracts.
44
+
45
+ ### Vue Notes
46
+ - Preserve reactive proxy identity, computed tracking, store actions, props/emits, and serialization boundaries.
47
+
48
+ ### Frontend-Craft Adaptation
49
+ - Encapsulation can be a module API, service, hook/composable, store slice, domain object, or value abstraction; class syntax is optional.
50
+
51
+ ### Example Transformation
52
+ Before: UI modules mutate a raw preferences object. After: a preferences model/module exposes named reads and updates while preserving serialized JSON.
53
+
54
+ ## RF-ENCAPSULATE-COLLECTION — Encapsulate Collection
55
+
56
+ ### Intent
57
+ Prevent callers from mutating a collection through an uncontrolled reference.
58
+
59
+ ### Typical Signals
60
+ - A getter exposes a mutable array/set and callers push/splice/delete directly.
61
+
62
+ ### Avoid When
63
+ - Avoid copying or wrapping when the collection is intentionally immutable and ownership is already clear.
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. Hide the mutable collection behind an owner.
71
+ 2. Return a read-only view or copy as appropriate.
72
+ 3. Provide explicit add/remove operations.
73
+ 4. Migrate direct mutations and verify ordering/identity semantics.
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
+ - Watch object identity, property descriptors, iteration order, mutability, and serialization.
87
+
88
+ ### TypeScript Notes
89
+ - Use `readonly`, narrow interfaces, branded/value types only when they model real invariants; keep DTO translations explicit.
90
+
91
+ ### React Notes
92
+ - Preserve props/state identity expectations, memoization, context boundaries, and controlled/uncontrolled contracts.
93
+
94
+ ### Vue Notes
95
+ - Preserve reactive proxy identity, computed tracking, store actions, props/emits, and serialization boundaries.
96
+
97
+ ### Frontend-Craft Adaptation
98
+ - Encapsulation can be a module API, service, hook/composable, store slice, domain object, or value abstraction; class syntax is optional.
99
+
100
+ ### Example Transformation
101
+ Before: `store.items.push(x)` from components becomes `store.addItem(x)` while selectors expose read-only items.
102
+
103
+ ## RF-REPLACE-PRIMITIVE-WITH-OBJECT — Replace Primitive with Object
104
+
105
+ ### Intent
106
+ Represent a domain value with an abstraction that owns its formatting, validation, or invariants.
107
+
108
+ ### Typical Signals
109
+ - The same primitive is repeatedly validated, formatted, or compared by domain-specific rules.
110
+
111
+ ### Avoid When
112
+ - A TypeScript alias or wrapper with no behavior/invariant may add ceremony without value.
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 the domain behavior around the primitive.
120
+ 2. Create a small value abstraction with compatible conversion.
121
+ 3. Migrate creation and use sites incrementally.
122
+ 4. Keep transport serialization explicit at boundaries.
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
+ - `SMELL-PRIMITIVE-OBSESSION`
130
+
131
+ ### Composes Well With
132
+ - Combine only with a separately justified next transformation; no fixed sequence is required.
133
+
134
+ ### JavaScript Notes
135
+ - Watch object identity, property descriptors, iteration order, mutability, and serialization.
136
+
137
+ ### TypeScript Notes
138
+ - Use `readonly`, narrow interfaces, branded/value types only when they model real invariants; keep DTO translations explicit.
139
+
140
+ ### React Notes
141
+ - Preserve props/state identity expectations, memoization, context boundaries, and controlled/uncontrolled contracts.
142
+
143
+ ### Vue Notes
144
+ - Preserve reactive proxy identity, computed tracking, store actions, props/emits, and serialization boundaries.
145
+
146
+ ### Frontend-Craft Adaptation
147
+ - Encapsulation can be a module API, service, hook/composable, store slice, domain object, or value abstraction; class syntax is optional.
148
+
149
+ ### Example Transformation
150
+ Before: email addresses are raw strings with repeated normalization. After: an `EmailAddress` value abstraction owns normalization; API payloads still serialize strings.
151
+
152
+ ## RF-REPLACE-TEMP-WITH-QUERY — Replace Temp with Query
153
+
154
+ ### Intent
155
+ Turn a local derived temporary into a query so the calculation can be reused and extraction boundaries shrink.
156
+
157
+ ### Typical Signals
158
+ - A temporary repeats a derivable calculation or must be threaded into extracted functions.
159
+
160
+ ### Avoid When
161
+ - Avoid when recomputation is expensive, unstable, or effectful unless memoization/caching preserves semantics.
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. Confirm the initializer is pure/stable enough to query.
169
+ 2. Extract the calculation into a function/getter.
170
+ 3. Replace temporary reads with the query.
171
+ 4. Remove the temporary and verify evaluation count/performance.
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
+
180
+ ### Composes Well With
181
+ - Extract Function when its preconditions independently hold.
182
+
183
+ ### JavaScript Notes
184
+ - Watch object identity, property descriptors, iteration order, mutability, and serialization.
185
+
186
+ ### TypeScript Notes
187
+ - Use `readonly`, narrow interfaces, branded/value types only when they model real invariants; keep DTO translations explicit.
188
+
189
+ ### React Notes
190
+ - Preserve props/state identity expectations, memoization, context boundaries, and controlled/uncontrolled contracts.
191
+
192
+ ### Vue Notes
193
+ - Preserve reactive proxy identity, computed tracking, store actions, props/emits, and serialization boundaries.
194
+
195
+ ### Frontend-Craft Adaptation
196
+ - Encapsulation can be a module API, service, hook/composable, store slice, domain object, or value abstraction; class syntax is optional.
197
+
198
+ ### Example Transformation
199
+ Before: a handler stores `const normalized = normalizeDraft(draft)` only to pass it around. After: a query supplies the derived value where safe.
200
+
201
+ ## RF-EXTRACT-CLASS — Extract Class
202
+
203
+ ### Intent
204
+ Split a responsibility cluster with its own data and behavior into a separate owner.
205
+
206
+ ### Typical Signals
207
+ - A class/module/component owns fields and methods that form a distinct concept and change for different reasons.
208
+
209
+ ### Avoid When
210
+ - Avoid extracting a thin bag of functions that increases indirection without improving ownership.
211
+
212
+ ### Preconditions
213
+ - Current observable behavior and affected callers are understood.
214
+ - The target scope is inside a declared diff budget and can be verified after this one primary transformation.
215
+
216
+ ### Mechanics
217
+ 1. Identify the cohesive field/behavior cluster.
218
+ 2. Create the new owner and move data behind it.
219
+ 3. Move one behavior at a time.
220
+ 4. Reduce delegation after callers can use the better boundary.
221
+
222
+ ### Behavior-Preservation Checkpoints
223
+ - Compare inputs, outputs, exceptions, side effects, ordering, and public contracts before/after the step.
224
+ - For frontend code, also check UI state, events, focus, network behavior, lifecycle/state transitions, and relevant identity semantics.
225
+
226
+ ### Related Code Smells
227
+ - `SMELL-DIVERGENT-CHANGE`
228
+ - `SMELL-DATA-CLUMPS`
229
+ - `SMELL-PRIMITIVE-OBSESSION`
230
+ - `SMELL-TEMPORARY-FIELD`
231
+ - `SMELL-LARGE-CLASS`
232
+
233
+ ### Composes Well With
234
+ - Move Function when its preconditions independently hold.
235
+ - Move Field when its preconditions independently hold.
236
+
237
+ ### JavaScript Notes
238
+ - Watch object identity, property descriptors, iteration order, mutability, and serialization.
239
+
240
+ ### TypeScript Notes
241
+ - Use `readonly`, narrow interfaces, branded/value types only when they model real invariants; keep DTO translations explicit.
242
+
243
+ ### React Notes
244
+ - Preserve props/state identity expectations, memoization, context boundaries, and controlled/uncontrolled contracts.
245
+
246
+ ### Vue Notes
247
+ - Preserve reactive proxy identity, computed tracking, store actions, props/emits, and serialization boundaries.
248
+
249
+ ### Frontend-Craft Adaptation
250
+ - Encapsulation can be a module API, service, hook/composable, store slice, domain object, or value abstraction; class syntax is optional.
251
+
252
+ ### Example Transformation
253
+ Before: a compose controller also owns recipient parsing rules. After: move those rules to a recipient domain module/service/composable, not necessarily a class.
254
+
255
+ ## RF-INLINE-CLASS — Inline Class
256
+
257
+ ### Intent
258
+ Fold a class or object boundary back into its main user when the abstraction no longer carries enough responsibility.
259
+
260
+ ### Typical Signals
261
+ - A type mostly delegates or has become trivial after earlier refactoring.
262
+
263
+ ### Avoid When
264
+ - Keep the boundary when it protects a public contract, isolates volatility, or has independent lifecycle/state.
265
+
266
+ ### Preconditions
267
+ - Current observable behavior and affected callers are understood.
268
+ - The target scope is inside a declared diff budget and can be verified after this one primary transformation.
269
+
270
+ ### Mechanics
271
+ 1. Choose the dominant owner.
272
+ 2. Move one field/behavior back at a time.
273
+ 3. Redirect callers and verify.
274
+ 4. Remove the empty abstraction after all references are migrated.
275
+
276
+ ### Behavior-Preservation Checkpoints
277
+ - Compare inputs, outputs, exceptions, side effects, ordering, and public contracts before/after the step.
278
+ - For frontend code, also check UI state, events, focus, network behavior, lifecycle/state transitions, and relevant identity semantics.
279
+
280
+ ### Related Code Smells
281
+ - `SMELL-SHOTGUN-SURGERY`
282
+ - `SMELL-LAZY-ELEMENT`
283
+ - `SMELL-SPECULATIVE-GENERALITY`
284
+
285
+ ### Composes Well With
286
+ - `RF-EXTRACT-CLASS` when its preconditions independently hold.
287
+
288
+ ### JavaScript Notes
289
+ - Watch object identity, property descriptors, iteration order, mutability, and serialization.
290
+
291
+ ### TypeScript Notes
292
+ - Use `readonly`, narrow interfaces, branded/value types only when they model real invariants; keep DTO translations explicit.
293
+
294
+ ### React Notes
295
+ - Preserve props/state identity expectations, memoization, context boundaries, and controlled/uncontrolled contracts.
296
+
297
+ ### Vue Notes
298
+ - Preserve reactive proxy identity, computed tracking, store actions, props/emits, and serialization boundaries.
299
+
300
+ ### Frontend-Craft Adaptation
301
+ - Encapsulation can be a module API, service, hook/composable, store slice, domain object, or value abstraction; class syntax is optional.
302
+
303
+ ### Example Transformation
304
+ Before: a one-method wrapper service only forwards to an API client. After: its only caller uses the client directly if no policy is lost.
305
+
306
+ ## RF-HIDE-DELEGATE — Hide Delegate
307
+
308
+ ### Intent
309
+ Shield clients from a navigation relationship by providing the operation at a stable boundary.
310
+
311
+ ### Typical Signals
312
+ - Many clients know the same internal path to reach a collaborator.
313
+
314
+ ### Avoid When
315
+ - Avoid wrapping every collaborator method; excessive forwarding creates Middle Man.
316
+
317
+ ### Preconditions
318
+ - Current observable behavior and affected callers are understood.
319
+ - The target scope is inside a declared diff budget and can be verified after this one primary transformation.
320
+
321
+ ### Mechanics
322
+ 1. Choose the navigation detail to hide.
323
+ 2. Add one intention-revealing operation on the owner.
324
+ 3. Migrate clients to the new operation.
325
+ 4. Stop before the owner becomes a pass-through facade.
326
+
327
+ ### Behavior-Preservation Checkpoints
328
+ - Compare inputs, outputs, exceptions, side effects, ordering, and public contracts before/after the step.
329
+ - For frontend code, also check UI state, events, focus, network behavior, lifecycle/state transitions, and relevant identity semantics.
330
+
331
+ ### Related Code Smells
332
+ - `SMELL-MESSAGE-CHAINS`
333
+ - `SMELL-INSIDER-TRADING`
334
+
335
+ ### Composes Well With
336
+ - `RF-REMOVE-MIDDLE-MAN` when its preconditions independently hold.
337
+
338
+ ### JavaScript Notes
339
+ - Watch object identity, property descriptors, iteration order, mutability, and serialization.
340
+
341
+ ### TypeScript Notes
342
+ - Use `readonly`, narrow interfaces, branded/value types only when they model real invariants; keep DTO translations explicit.
343
+
344
+ ### React Notes
345
+ - Preserve props/state identity expectations, memoization, context boundaries, and controlled/uncontrolled contracts.
346
+
347
+ ### Vue Notes
348
+ - Preserve reactive proxy identity, computed tracking, store actions, props/emits, and serialization boundaries.
349
+
350
+ ### Frontend-Craft Adaptation
351
+ - Encapsulation can be a module API, service, hook/composable, store slice, domain object, or value abstraction; class syntax is optional.
352
+
353
+ ### Example Transformation
354
+ Before: components read `session.user.organization.policy.canSend`. After: expose `session.canSendMail()` or an equivalent selector.
355
+
356
+ ## RF-REMOVE-MIDDLE-MAN — Remove Middle Man
357
+
358
+ ### Intent
359
+ Let clients reach the real collaborator when an intermediary adds mostly forwarding noise.
360
+
361
+ ### Typical Signals
362
+ - A wrapper delegates a large portion of its API without policy or protection.
363
+
364
+ ### Avoid When
365
+ - Do not expose volatile internals merely to save a few forwarding calls.
366
+
367
+ ### Preconditions
368
+ - Current observable behavior and affected callers are understood.
369
+ - The target scope is inside a declared diff budget and can be verified after this one primary transformation.
370
+
371
+ ### Mechanics
372
+ 1. Identify forwarding methods that add no value.
373
+ 2. Give selected callers direct access to the real collaborator.
374
+ 3. Migrate and verify callers incrementally.
375
+ 4. Remove obsolete delegations while preserving useful policy methods.
376
+
377
+ ### Behavior-Preservation Checkpoints
378
+ - Compare inputs, outputs, exceptions, side effects, ordering, and public contracts before/after the step.
379
+ - For frontend code, also check UI state, events, focus, network behavior, lifecycle/state transitions, and relevant identity semantics.
380
+
381
+ ### Related Code Smells
382
+ - `SMELL-MIDDLE-MAN`
383
+
384
+ ### Composes Well With
385
+ - `RF-HIDE-DELEGATE` when its preconditions independently hold.
386
+
387
+ ### JavaScript Notes
388
+ - Watch object identity, property descriptors, iteration order, mutability, and serialization.
389
+
390
+ ### TypeScript Notes
391
+ - Use `readonly`, narrow interfaces, branded/value types only when they model real invariants; keep DTO translations explicit.
392
+
393
+ ### React Notes
394
+ - Preserve props/state identity expectations, memoization, context boundaries, and controlled/uncontrolled contracts.
395
+
396
+ ### Vue Notes
397
+ - Preserve reactive proxy identity, computed tracking, store actions, props/emits, and serialization boundaries.
398
+
399
+ ### Frontend-Craft Adaptation
400
+ - Encapsulation can be a module API, service, hook/composable, store slice, domain object, or value abstraction; class syntax is optional.
401
+
402
+ ### Example Transformation
403
+ Before: a hook re-exports every store action unchanged. After: consumers use the store API directly while the hook retains only real composition logic.
404
+
405
+ ## RF-SUBSTITUTE-ALGORITHM — Substitute Algorithm
406
+
407
+ ### Intent
408
+ Replace an implementation with a clearer or more suitable algorithm while preserving its externally relevant results.
409
+
410
+ ### Typical Signals
411
+ - The current algorithm is convoluted or a simpler proven algorithm expresses the requirement better.
412
+
413
+ ### Avoid When
414
+ - Avoid when edge cases, stable ordering, error behavior, or performance constraints are not characterized.
415
+
416
+ ### Preconditions
417
+ - Current observable behavior and affected callers are understood.
418
+ - The target scope is inside a declared diff budget and can be verified after this one primary transformation.
419
+
420
+ ### Mechanics
421
+ 1. Lock inputs, outputs, ordering, errors, and relevant complexity expectations.
422
+ 2. Implement the replacement in one isolated boundary.
423
+ 3. Compare against characterization/tests.
424
+ 4. Remove the old algorithm only after equivalence is established.
425
+
426
+ ### Behavior-Preservation Checkpoints
427
+ - Compare inputs, outputs, exceptions, side effects, ordering, and public contracts before/after the step.
428
+ - For frontend code, also check UI state, events, focus, network behavior, lifecycle/state transitions, and relevant identity semantics.
429
+
430
+ ### Related Code Smells
431
+ - No single code smell required; select from concrete structural evidence.
432
+
433
+ ### Composes Well With
434
+ - Combine only with a separately justified next transformation; no fixed sequence is required.
435
+
436
+ ### JavaScript Notes
437
+ - Watch object identity, property descriptors, iteration order, mutability, and serialization.
438
+
439
+ ### TypeScript Notes
440
+ - Use `readonly`, narrow interfaces, branded/value types only when they model real invariants; keep DTO translations explicit.
441
+
442
+ ### React Notes
443
+ - Preserve props/state identity expectations, memoization, context boundaries, and controlled/uncontrolled contracts.
444
+
445
+ ### Vue Notes
446
+ - Preserve reactive proxy identity, computed tracking, store actions, props/emits, and serialization boundaries.
447
+
448
+ ### Frontend-Craft Adaptation
449
+ - Encapsulation can be a module API, service, hook/composable, store slice, domain object, or value abstraction; class syntax is optional.
450
+
451
+ ### Example Transformation
452
+ Before: a manual nested search builds unique recipients. After: a clearer map/set algorithm produces the same order, duplicates policy, and errors.
@@ -0,0 +1,25 @@
1
+ ---
2
+ name: fec-refactoring-functions
3
+ description: Use when behavior-preserving frontend refactoring focuses on function structure, naming, parameters, shared context, or phase boundaries, and the selected technique needs family-specific mechanics, risks, and JavaScript/TypeScript/React/Vue adaptation.
4
+ ---
5
+
6
+ # Function 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 [Function Refactorings](references/function-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 11 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.