@lenardangeloolajay/len-toolkit 1.1.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 (114) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +209 -0
  3. package/bin/cli.js +244 -0
  4. package/package.json +35 -0
  5. package/src/installer.js +236 -0
  6. package/templates/configs/.editorconfig +12 -0
  7. package/templates/configs/sample.gitignore +8 -0
  8. package/templates/docs/FEATURE.md +40 -0
  9. package/templates/docs/HANDOFF.md +39 -0
  10. package/templates/docs/IMPLEMENTATION_PLAN.md +47 -0
  11. package/templates/docs/SPEC_INDEX.md +12 -0
  12. package/templates/docs/VERIFICATION.md +14 -0
  13. package/templates/docs/product/ARCHITECTURE.md +22 -0
  14. package/templates/docs/product/CONSTRAINTS.md +22 -0
  15. package/templates/docs/product/DATA_MODEL.md +22 -0
  16. package/templates/docs/product/OVERVIEW.md +22 -0
  17. package/templates/examples/flutter-handoff/EXERCISES.md +16 -0
  18. package/templates/examples/flutter-handoff/HANDOFF.md +32 -0
  19. package/templates/examples/flutter-handoff/docs/SPEC_INDEX.md +19 -0
  20. package/templates/examples/flutter-handoff/docs/evidence/FEAT-001-verification.md +14 -0
  21. package/templates/examples/flutter-handoff/docs/features/FEAT-001-local-note.md +40 -0
  22. package/templates/examples/flutter-handoff/docs/plans/FEAT-001-implementation.md +43 -0
  23. package/templates/examples/flutter-handoff/docs/product/ARCHITECTURE.md +24 -0
  24. package/templates/examples/flutter-handoff/docs/product/CONSTRAINTS.md +13 -0
  25. package/templates/examples/flutter-handoff/docs/product/DATA_MODEL.md +20 -0
  26. package/templates/examples/flutter-handoff/docs/product/OVERVIEW.md +26 -0
  27. package/templates/rules/.cursorrules +7 -0
  28. package/templates/rules/AGENTS.md +61 -0
  29. package/templates/rules/GEMINI.md +7 -0
  30. package/templates/skills/a-philosophy-of-software-design/SKILL.md +11 -0
  31. package/templates/skills/a-philosophy-of-software-design/a-philosophy-of-software-design.md +370 -0
  32. package/templates/skills/a-philosophy-of-software-design/a-philosophy-of-software-design.mini.md +46 -0
  33. package/templates/skills/a-philosophy-of-software-design/a-philosophy-of-software-design.nano.md +35 -0
  34. package/templates/skills/clean-architecture/SKILL.md +11 -0
  35. package/templates/skills/clean-architecture/clean-architecture.md +515 -0
  36. package/templates/skills/clean-architecture/clean-architecture.mini.md +49 -0
  37. package/templates/skills/clean-architecture/clean-architecture.nano.md +36 -0
  38. package/templates/skills/clean-code/SKILL.md +11 -0
  39. package/templates/skills/clean-code/clean-code.md +297 -0
  40. package/templates/skills/clean-code/clean-code.mini.md +47 -0
  41. package/templates/skills/clean-code/clean-code.nano.md +32 -0
  42. package/templates/skills/code-complete/SKILL.md +11 -0
  43. package/templates/skills/code-complete/code-complete.md +354 -0
  44. package/templates/skills/code-complete/code-complete.mini.md +56 -0
  45. package/templates/skills/code-complete/code-complete.nano.md +41 -0
  46. package/templates/skills/council/SKILL.md +37 -0
  47. package/templates/skills/designing-data-intensive-applications/SKILL.md +11 -0
  48. package/templates/skills/designing-data-intensive-applications/designing-data-intensive-applications.md +393 -0
  49. package/templates/skills/designing-data-intensive-applications/designing-data-intensive-applications.mini.md +55 -0
  50. package/templates/skills/designing-data-intensive-applications/designing-data-intensive-applications.nano.md +34 -0
  51. package/templates/skills/domain-driven-design/SKILL.md +11 -0
  52. package/templates/skills/domain-driven-design/domain-driven-design.md +979 -0
  53. package/templates/skills/domain-driven-design/domain-driven-design.mini.md +48 -0
  54. package/templates/skills/domain-driven-design/domain-driven-design.nano.md +39 -0
  55. package/templates/skills/domain-driven-design-distilled/SKILL.md +11 -0
  56. package/templates/skills/domain-driven-design-distilled/domain-driven-design-distilled.md +317 -0
  57. package/templates/skills/domain-driven-design-distilled/domain-driven-design-distilled.mini.md +56 -0
  58. package/templates/skills/domain-driven-design-distilled/domain-driven-design-distilled.nano.md +41 -0
  59. package/templates/skills/implementation-plan/SKILL.md +42 -0
  60. package/templates/skills/implementing-domain-driven-design/SKILL.md +11 -0
  61. package/templates/skills/implementing-domain-driven-design/implementing-domain-driven-design.md +337 -0
  62. package/templates/skills/implementing-domain-driven-design/implementing-domain-driven-design.mini.md +57 -0
  63. package/templates/skills/implementing-domain-driven-design/implementing-domain-driven-design.nano.md +37 -0
  64. package/templates/skills/patterns-of-enterprise-application-architecture/SKILL.md +11 -0
  65. package/templates/skills/patterns-of-enterprise-application-architecture/patterns-of-enterprise-application-architecture.md +404 -0
  66. package/templates/skills/patterns-of-enterprise-application-architecture/patterns-of-enterprise-application-architecture.mini.md +54 -0
  67. package/templates/skills/patterns-of-enterprise-application-architecture/patterns-of-enterprise-application-architecture.nano.md +35 -0
  68. package/templates/skills/ponytail/SKILL.md +124 -0
  69. package/templates/skills/ponytail-audit/SKILL.md +45 -0
  70. package/templates/skills/ponytail-debt/SKILL.md +48 -0
  71. package/templates/skills/ponytail-gain/SKILL.md +17 -0
  72. package/templates/skills/ponytail-help/SKILL.md +42 -0
  73. package/templates/skills/ponytail-review/SKILL.md +61 -0
  74. package/templates/skills/refactoring/SKILL.md +11 -0
  75. package/templates/skills/refactoring/refactoring.md +433 -0
  76. package/templates/skills/refactoring/refactoring.mini.md +49 -0
  77. package/templates/skills/refactoring/refactoring.nano.md +37 -0
  78. package/templates/skills/refactoring-guru/SKILL.md +11 -0
  79. package/templates/skills/refactoring-guru/refactoring-guru.md +765 -0
  80. package/templates/skills/refactoring-guru/refactoring-guru.mini.md +64 -0
  81. package/templates/skills/refactoring-guru/refactoring-guru.nano.md +41 -0
  82. package/templates/skills/release-it/SKILL.md +11 -0
  83. package/templates/skills/release-it/release-it.md +382 -0
  84. package/templates/skills/release-it/release-it.mini.md +48 -0
  85. package/templates/skills/release-it/release-it.nano.md +38 -0
  86. package/templates/skills/security-audit/AI-AND-LLM.md +83 -0
  87. package/templates/skills/security-audit/ATTACK-CLASSES.md +130 -0
  88. package/templates/skills/security-audit/CLIENT-SIDE.md +83 -0
  89. package/templates/skills/security-audit/CLOUD-AND-DEPLOYMENT.md +86 -0
  90. package/templates/skills/security-audit/DATA-ISOLATION-AND-LIFECYCLE.md +84 -0
  91. package/templates/skills/security-audit/DESKTOP-MOBILE-AND-LOCAL-IPC.md +89 -0
  92. package/templates/skills/security-audit/HUNTING.md +251 -0
  93. package/templates/skills/security-audit/MEMORY-SAFETY-AND-BINARY.md +101 -0
  94. package/templates/skills/security-audit/PROTOCOLS-RPC-AND-MESSAGING.md +81 -0
  95. package/templates/skills/security-audit/RECONNAISSANCE.md +156 -0
  96. package/templates/skills/security-audit/RESOURCE-EXHAUSTION-AND-AVAILABILITY.md +78 -0
  97. package/templates/skills/security-audit/SKILL.md +192 -0
  98. package/templates/skills/security-audit/SUPPLY-CHAIN-AND-RELEASE.md +73 -0
  99. package/templates/skills/security-audit/VALIDATION-AND-REPORTING.md +186 -0
  100. package/templates/skills/security-audit/WEB-PROTOCOL-AND-AUTH.md +105 -0
  101. package/templates/skills/security-audit/report-schema.json +461 -0
  102. package/templates/skills/security-audit/validate-coverage-ledger.cjs +872 -0
  103. package/templates/skills/security-audit/validate-coverage-ledger.test.cjs +740 -0
  104. package/templates/skills/security-audit/validate-findings.cjs +773 -0
  105. package/templates/skills/security-audit/validate-findings.test.cjs +652 -0
  106. package/templates/skills/spec/SKILL.md +55 -0
  107. package/templates/skills/the-pragmatic-programmer/SKILL.md +11 -0
  108. package/templates/skills/the-pragmatic-programmer/the-pragmatic-programmer.md +359 -0
  109. package/templates/skills/the-pragmatic-programmer/the-pragmatic-programmer.mini.md +65 -0
  110. package/templates/skills/the-pragmatic-programmer/the-pragmatic-programmer.nano.md +44 -0
  111. package/templates/skills/working-effectively-with-legacy-code/SKILL.md +11 -0
  112. package/templates/skills/working-effectively-with-legacy-code/working-effectively-with-legacy-code.md +371 -0
  113. package/templates/skills/working-effectively-with-legacy-code/working-effectively-with-legacy-code.mini.md +50 -0
  114. package/templates/skills/working-effectively-with-legacy-code/working-effectively-with-legacy-code.nano.md +35 -0
@@ -0,0 +1,48 @@
1
+ ---
2
+ name: ponytail-debt
3
+ description: >
4
+ Harvest every `ponytail:` comment in the codebase into a debt ledger, so the
5
+ deliberate shortcuts and deferrals ponytail leaves behind get tracked instead
6
+ of rotting into "later means never". Use when the user says "ponytail debt",
7
+ "/ponytail-debt", "what did ponytail defer", "list the shortcuts", "ponytail
8
+ ledger", or "what did we mark to do later". One-shot report, changes nothing.
9
+ license: MIT
10
+ ---
11
+
12
+ Every deliberate ponytail shortcut is marked with a `ponytail:` comment naming
13
+ its ceiling and upgrade path. This collects them into one ledger so a deferral
14
+ can't quietly become permanent.
15
+
16
+ ## Scan
17
+
18
+ Grep the repo for comment markers, skipping `node_modules`, `.git`, and build
19
+ output:
20
+
21
+ `grep -rnE '(#|//) ?ponytail:' .` (add other comment prefixes if your stack uses them)
22
+
23
+ Each hit is one ledger row. The comment prefix keeps prose that merely mentions
24
+ the convention out of the ledger.
25
+
26
+ ## Output
27
+
28
+ One row per marker, grouped by file:
29
+
30
+ `<file>:<line>, <what was simplified>. ceiling: <the limit named>. upgrade: <the trigger to revisit>.`
31
+
32
+ The convention is `ponytail: <ceiling>, <upgrade path>`, so pull the ceiling
33
+ and the trigger straight from the comment. Want an owner per row too? add
34
+ `git blame -L<line>,<line>`.
35
+
36
+ Flag the rot risk: any `ponytail:` comment that names no upgrade path or
37
+ trigger gets a `no-trigger` tag, those are the ones that silently rot.
38
+
39
+ End with `<N> markers, <M> with no trigger.` Nothing found: `No ponytail: debt. Clean ledger.`
40
+
41
+ ## Boundaries
42
+
43
+ Reads and reports only, changes nothing. To persist it, ask and it writes the
44
+ ledger to a file (e.g. `PONYTAIL-DEBT.md`). One-shot. "stop ponytail-debt" or
45
+ "normal mode" to revert.
46
+
47
+
48
+ Read project AGENTS.md for shared workflow, scope, and evidence policy.
@@ -0,0 +1,17 @@
1
+ ---
2
+ name: ponytail-gain
3
+ description: >
4
+ Report Ponytail impact only from available, attributable benchmark evidence.
5
+ Use for ponytail gain or scoreboard requests; never infer savings for this repo.
6
+ license: MIT
7
+ ---
8
+
9
+ # Ponytail gain
10
+
11
+ Read project AGENTS.md for evidence policy.
12
+ The original upstream benchmark dataset is not bundled with this toolkit.
13
+ If no verified benchmark evidence is available, report that savings are unverified here rather than displaying unsupported percentages.
14
+ If evidence is supplied, state its source, conditions, measured baseline, and limitations before reporting results.
15
+ Never extrapolate benchmark results into savings for the current project or compare against an implementation that was never built.
16
+ Use ponytail-debt for counted shortcuts and ponytail-audit for proposed reductions, labeling proposals as estimates.
17
+ This is a read-only report and does not change modes or files.
@@ -0,0 +1,42 @@
1
+ ---
2
+ name: ponytail-help
3
+ description: >
4
+ Quick-reference card for all ponytail modes, skills, and commands.
5
+ One-shot display, not a persistent mode. Trigger: /ponytail-help,
6
+ "ponytail help", "what ponytail commands", "how do I use ponytail".
7
+ license: MIT
8
+ ---
9
+
10
+ # Ponytail Help
11
+
12
+ Display this reference card when invoked. One-shot, do NOT change mode,
13
+ write flag files, or persist anything.
14
+
15
+ ## Levels
16
+
17
+ | Level | Trigger | What change |
18
+ |-------|---------|-------------|
19
+ | **Lite** | `/ponytail lite` | Build what's asked, name the lazier alternative in one line. |
20
+ | **Full** | `/ponytail` | The ladder enforced: YAGNI → stdlib → native → one line → minimum. Default. |
21
+ | **Ultra** | `/ponytail ultra` | YAGNI extremist. Deletion before addition. Challenges requirements before building. |
22
+
23
+ Level sticks until changed or session end.
24
+
25
+ ## Skills
26
+
27
+ | Skill | Trigger | What it does |
28
+ |-------|---------|--------------|
29
+ | **ponytail** | `/ponytail` | Lazy mode itself. Simplest solution that works. |
30
+ | **ponytail-review** | `/ponytail-review` | Over-engineering review: `L42: yagni: factory, one product. Inline.` |
31
+ | **ponytail-audit** | `/ponytail-audit` | Whole-repo over-engineering audit: ranked list of what to delete. |
32
+ | **ponytail-debt** | `/ponytail-debt` | Harvest `ponytail:` shortcut comments into a tracked ledger. |
33
+ | **ponytail-gain** | `/ponytail-gain` | Measured-impact scoreboard: less code, less cost, more speed. |
34
+ | **ponytail-help** | `/ponytail-help` | This card. |
35
+
36
+ ## Deactivate
37
+
38
+ Say "stop ponytail" or "normal mode". Resume anytime with `/ponytail`.
39
+ `/ponytail off` also works.
40
+
41
+
42
+ Read project AGENTS.md for shared workflow, scope, and evidence policy.
@@ -0,0 +1,61 @@
1
+ ---
2
+ name: ponytail-review
3
+ description: >
4
+ Code review focused exclusively on over-engineering. Finds what to delete:
5
+ reinvented standard library, unneeded dependencies, speculative abstractions,
6
+ dead flexibility. One line per finding: location, what to cut, what replaces
7
+ it. Use when the user says "review for over-engineering", "what can we
8
+ delete", "is this over-engineered", "simplify review", or invokes
9
+ /ponytail-review. Complements correctness-focused review, this one only
10
+ hunts complexity.
11
+ license: MIT
12
+ ---
13
+
14
+ Review diffs for unnecessary complexity. One line per finding: location, what
15
+ to cut, what replaces it. The diff's best outcome is getting shorter.
16
+
17
+ ## Format
18
+
19
+ `L<line>: <tag> <what>. <replacement>.`, or `<file>:L<line>: ...` for
20
+ multi-file diffs.
21
+
22
+ Tags:
23
+
24
+ - `delete:` dead code, unused flexibility, speculative feature. Replacement: nothing.
25
+ - `stdlib:` hand-rolled thing the standard library ships. Name the function.
26
+ - `native:` dependency or code doing what the platform already does. Name the feature.
27
+ - `yagni:` abstraction with one implementation, config nobody sets, layer with one caller.
28
+ - `shrink:` same logic, fewer lines. Show the shorter form.
29
+
30
+ ## Examples
31
+
32
+ ❌ "This EmailValidator class might be more complex than necessary, have you
33
+ considered whether all these validation rules are needed at this stage?"
34
+
35
+ ✅ `L12-38: stdlib: 27-line validator class. "@" in email, 1 line, real validation is the confirmation mail.`
36
+
37
+ ✅ `L4: native: moment.js imported for one format call. Intl.DateTimeFormat, 0 deps.`
38
+
39
+ ✅ `repo.py:L88: yagni: AbstractRepository with one implementation. Inline it until a second one exists.`
40
+
41
+ ✅ `L52-71: delete: retry wrapper around an idempotent local call. Nothing replaces it.`
42
+
43
+ ✅ `L30-44: shrink: manual loop builds dict. dict(zip(keys, values)), 1 line.`
44
+
45
+ ## Scoring
46
+
47
+ End with the only metric that matters: `net: -<N> lines possible.`
48
+
49
+ If there is nothing to cut, say `Lean already. Ship.` and stop.
50
+
51
+ ## Boundaries
52
+
53
+ Scope: over-engineering and complexity only. Correctness bugs, security holes,
54
+ and performance are explicitly out of scope. Route them to a normal review
55
+ pass, not this one. A single smoke test or `assert`-based
56
+ self-check is the ponytail minimum, not bloat, never flag it for deletion.
57
+ Does not apply the fixes, only lists them.
58
+ "stop ponytail-review" or "normal mode": revert to verbose review style.
59
+
60
+
61
+ Read project AGENTS.md for shared workflow, scope, and evidence policy.
@@ -0,0 +1,11 @@
1
+ ---
2
+ name: refactoring
3
+ description: Apply Martin Fowler-inspired refactoring rules when improving existing code structure while preserving observable behavior.
4
+ license: MIT
5
+ ---
6
+
7
+ # Refactoring Skill
8
+
9
+ Use this skill when a task involves behavior-preserving code improvement, code smells, small refactoring steps, test-backed cleanup, or separating refactoring from feature changes.
10
+
11
+ Before making design or code decisions, read and apply [refactoring.mini.md](refactoring.mini.md). Use [refactoring.md](refactoring.md) only as a deeper reference when the mini rules are not enough for the current refactoring tradeoff.
@@ -0,0 +1,433 @@
1
+ # OBEY Refactoring by Martin Fowler
2
+
3
+ ## Purpose
4
+
5
+ This repository follows the discipline of **Refactoring** in the sense of Martin Fowler:
6
+ improve the internal structure of code **without changing its observable behavior**.
7
+
8
+ All code generation, edits, and reviews must optimize for:
9
+ - small behavior-preserving changes
10
+ - clearer names and simpler control flow
11
+ - lower duplication
12
+ - smaller units of responsibility
13
+ - explicit movement from bad design toward good design
14
+ - steady design improvement as part of daily work
15
+
16
+ This file is a binding engineering policy: `MUST` is binding, `SHOULD` is a strong default, and `MUST NOT` is forbidden.
17
+
18
+ ---
19
+
20
+ ## Primary Directive
21
+
22
+ When modifying existing code, do **not** start by rewriting large areas.
23
+ Start by making the next safe structural improvement that makes the desired change easier.
24
+
25
+ Prefer:
26
+ 1. establish a safety net
27
+ 2. make a preparatory refactoring
28
+ 3. make the functional change
29
+ 4. refactor again if needed
30
+
31
+ Reject changes that bundle large functional changes with unrelated structural churn.
32
+
33
+ ---
34
+
35
+ ## What Counts as Refactoring
36
+
37
+ Refactoring here means:
38
+ - changing structure without changing external behavior
39
+ - applying small, composable transformations
40
+ - removing code smells before or during feature work
41
+ - making the next change easier
42
+ - improving readability, locality, and testability
43
+
44
+ Refactoring here does **not** mean:
45
+ - large rewrites
46
+ - unverified cleanup
47
+ - “modernization” with unclear behavioral impact
48
+ - renaming everything at once
49
+ - mixing architecture migration, feature work, and cleanup in one uncontrolled patch
50
+
51
+ ---
52
+
53
+ ## Non-Negotiable Rules
54
+
55
+ 1. **Preserve Behavior**
56
+ - Refactorings must preserve observable behavior.
57
+ - If behavior must change, isolate the behavior change from structural refactoring.
58
+ - Never disguise a feature change as a refactoring.
59
+
60
+ 2. **Work in Small Steps**
61
+ - Prefer many small safe edits over one large transformation.
62
+ - Each step should be understandable and reversible.
63
+ - If a patch feels too large to reason about locally, split it.
64
+
65
+ 3. **Keep the System Running**
66
+ - Do not leave code in a broken intermediate state unless explicitly asked for a draft.
67
+ - Every refactoring sequence should maintain a runnable, buildable state where practical.
68
+
69
+ 4. **Refactor Before and After Feature Work**
70
+ - If code is hard to change, first reshape it.
71
+ - After the feature lands, clean remaining structural debt introduced by the change.
72
+
73
+ 5. **Use the Simplest Helpful Refactoring**
74
+ - Do not introduce patterns or abstractions earlier than needed.
75
+ - Prefer local simplification before large-scale abstraction.
76
+
77
+ ---
78
+
79
+ ## Safety Rules
80
+
81
+ ### Tests and Verification
82
+ 1. Create or identify a safety net before risky refactoring.
83
+ 2. Prefer characterization tests when working on unclear existing behavior.
84
+ 3. If tests are absent, make the smallest changes possible and improve testability first.
85
+ 4. Keep refactoring and test updates aligned with preserved behavior.
86
+ 5. Never delete a failing test just to complete a refactoring.
87
+
88
+ ### Commit and Patch Discipline
89
+ 1. Separate structural edits from behavior changes whenever practical.
90
+ 2. Group related refactorings together.
91
+ 3. Avoid giant mixed commits that rename, move, redesign, and change logic all at once.
92
+ 4. Prefer reviewable sequences of transformations.
93
+
94
+ ### Preparatory Refactoring
95
+ Before implementing a feature, ask:
96
+ - what makes this change awkward?
97
+ - what local structural change would make it straightforward?
98
+ - can I rename, extract, move, split, or inline first?
99
+
100
+ Do the preparatory refactoring before the feature change.
101
+
102
+ ---
103
+
104
+ ## Code Smell Policy
105
+
106
+ When modifying code, actively look for these smells.
107
+
108
+ ### Duplicated Code
109
+ - Duplicate logic is a default target for elimination.
110
+ - Remove duplication by extracting shared behavior, not by introducing vague utility dumping grounds.
111
+ - Do not abstract coincidental similarity.
112
+
113
+ ### Long Functions
114
+ - Split long functions when they mix responsibilities, levels of abstraction, or phases of work.
115
+ - Extract meaningful chunks with names that explain intent.
116
+ - Do not create micro-method noise with no explanatory value.
117
+
118
+ ### Long Parameter Lists
119
+ - Replace repeated clumps with parameter objects or richer domain objects where appropriate.
120
+ - Remove boolean flags that switch behavior.
121
+ - Avoid signatures that require callers to memorize argument order.
122
+
123
+ ### Global Data and Hidden Dependencies
124
+ - Reduce reliance on globals, singletons, and ambient context.
125
+ - Make dependencies explicit where possible.
126
+ - Refactor toward injection, parameters, or clear ownership.
127
+
128
+ ### Divergent Change
129
+ - If one class changes for many different reasons, split responsibilities.
130
+ - Separate business logic, formatting, transport, persistence, and integration concerns.
131
+
132
+ ### Shotgun Surgery
133
+ - If one change forces edits across many files, centralize the knowledge.
134
+ - Introduce a better boundary or clearer ownership.
135
+
136
+ ### Feature Envy
137
+ - If a method mostly manipulates another object's data, move it or reshape the model.
138
+ - Put behavior near the data or concept it belongs to.
139
+
140
+ ### Data Clumps and Primitive Obsession
141
+ - Replace repeated primitive bundles with meaningful types.
142
+ - Give recurring business concepts names and validation.
143
+
144
+ ### Switch Statements and Conditionals
145
+ - Reduce repeated branching on type or mode when polymorphism, tables, strategies, or better data structures fit.
146
+ - Do not replace a single honest conditional with needless indirection.
147
+
148
+ ### Temporary Fields and Weird Lifecycles
149
+ - Remove fields that exist only for unusual code paths when a separate object or clearer phase model is better.
150
+ - Prefer modeling states explicitly over half-initialized objects.
151
+
152
+ ### Middle Man and Speculative Generality
153
+ - Remove forwarding layers that add no value.
154
+ - Delete abstractions created “just in case” if they are not earning their keep.
155
+
156
+ ---
157
+
158
+ ## Preferred Refactoring Moves
159
+
160
+ ### Naming Refactorings
161
+ - Rename variables to reveal intent.
162
+ - Rename functions to describe behavior, not mechanism.
163
+ - Rename types and modules to align with problem-domain terminology.
164
+ - Rename before deeper refactoring when bad names block understanding.
165
+
166
+ ### Extraction Refactorings
167
+ - Extract function when a block has a coherent purpose.
168
+ - Extract variable when an expression is hard to read.
169
+ - Extract class when one class has multiple reasons to change.
170
+ - Extract module when a file mixes unrelated concerns.
171
+
172
+ ### Movement Refactorings
173
+ - Move function to the module or type where the data or concept lives.
174
+ - Move field when ownership is clearer elsewhere.
175
+ - Move statements to group related operations and reduce cognitive jumps.
176
+
177
+ ### Simplification Refactorings
178
+ - Inline accidental abstractions.
179
+ - Collapse unnecessary layers.
180
+ - Replace nested conditionals with guard clauses where it improves clarity.
181
+ - Consolidate duplicate conditional fragments.
182
+
183
+ ### Data Refactorings
184
+ - Encapsulate mutable state.
185
+ - Replace magic values with named constants or domain types.
186
+ - Introduce parameter objects for repeated argument groups.
187
+ - Replace raw collections with named abstractions when behavior accumulates around them.
188
+
189
+ ---
190
+
191
+ ## Refactoring Catalog Index
192
+
193
+ ### Composing Methods
194
+ - USE Extract Method when a code fragment has a coherent purpose and a useful name.
195
+ - USE Inline Method when a method body is clearer than its indirection.
196
+ - USE Inline Temp when a temporary variable obscures a direct expression.
197
+ - USE Replace Temp with Query when a calculated value deserves a named query and can be reused safely.
198
+ - USE Introduce Explaining Variable when a complex expression needs named parts.
199
+ - USE Split Temporary Variable when one variable carries multiple meanings.
200
+ - USE Remove Assignments to Parameters when parameter mutation obscures input meaning.
201
+ - USE Replace Method with Method Object when local state prevents clean extraction.
202
+ - USE Substitute Algorithm when a clearer algorithm can replace a tangled one without changing behavior.
203
+
204
+ ### Moving Features
205
+ - USE Move Method or Move Field when behavior or state belongs more naturally to another object.
206
+ - USE Extract Class when one class has more than one reason to change.
207
+ - USE Inline Class when a class no longer earns its existence.
208
+ - USE Hide Delegate when clients know too much about an object's collaborator.
209
+ - USE Remove Middle Man when a forwarding object no longer hides useful detail.
210
+ - USE Introduce Foreign Method only when you cannot edit the class that should own the behavior.
211
+ - USE Introduce Local Extension when repeated foreign methods need a local, coherent extension point.
212
+
213
+ ### Organizing Data
214
+ - USE Self Encapsulate Field when direct field access blocks flexibility.
215
+ - USE Replace Data Value with Object when a primitive carries behavior, validation, or meaning.
216
+ - USE Change Value to Reference when identity and shared updates matter.
217
+ - USE Change Reference to Value when value semantics simplify ownership.
218
+ - USE Replace Array with Object when positions in a collection have names or rules.
219
+ - USE Duplicate Observed Data only when UI or framework synchronization forces it; keep synchronization explicit.
220
+ - USE Change Unidirectional Association to Bidirectional only when traversal is needed both ways.
221
+ - USE Change Bidirectional Association to Unidirectional when one direction is unnecessary coupling.
222
+ - USE Encapsulate Collection when external mutation can bypass invariants.
223
+ - USE Replace Record with Data Class when raw records need named access and behavior can grow safely.
224
+ - USE Replace Type Code with Class, Subclasses, or State/Strategy according to whether behavior varies by type.
225
+ - USE Replace Subclass with Fields when subclass variation is only data.
226
+
227
+ ### Simplifying Calls and Conditionals
228
+ - USE Decompose Conditional, Consolidate Conditional Expression, and Consolidate Duplicate Conditional Fragments to make branching intent visible.
229
+ - USE Remove Control Flag when loop or conditional state can be expressed directly.
230
+ - USE Replace Nested Conditional with Guard Clauses when it clarifies the normal path.
231
+ - USE Replace Conditional with Polymorphism only when repeated type-based behavior justifies it.
232
+ - USE Introduce Null Object when repeated null behavior has a stable meaning.
233
+ - USE Introduce Assertion when an assumption should be explicit during development.
234
+ - USE Rename Method, Add Parameter, Remove Parameter, Parameterize Method, or Replace Parameter with Explicit Methods to make caller intent clearer.
235
+ - USE Preserve Whole Object when callers pass several values from the same object.
236
+ - USE Replace Parameter with Method when the receiver can obtain the value itself without hidden coupling.
237
+ - USE Remove Setting Method when post-construction mutation should not be allowed.
238
+ - USE Hide Method when public surface exposes unnecessary operations.
239
+ - USE Replace Constructor with Factory Method when creation intent or subtype selection needs a name.
240
+ - USE Encapsulate Downcast when callers should not own cast details.
241
+ - USE Replace Error Code with Exception or Replace Exception with Test according to the expected failure model.
242
+
243
+ ### Generalization and Big Refactorings
244
+ - USE Pull Up Field, Pull Up Method, or Pull Up Constructor Body when duplicated superclass behavior is real.
245
+ - USE Push Down Method or Push Down Field when only some subclasses need the feature.
246
+ - USE Extract Subclass, Extract Superclass, or Extract Interface only when callers or variation points justify them.
247
+ - USE Collapse Hierarchy when inheritance no longer adds meaning.
248
+ - USE Form Template Method when similar algorithms differ in controlled steps.
249
+ - USE Replace Inheritance with Delegation when inheritance couples unrelated responsibilities.
250
+ - USE Replace Delegation with Inheritance only when the subtype relationship is genuine and stable.
251
+ - USE Tease Apart Inheritance when one hierarchy mixes multiple variation axes.
252
+ - USE Convert Procedural Design to Objects when data and behavior need clearer ownership.
253
+ - USE Separate Domain from Presentation when UI and policy are tangled.
254
+ - USE Extract Hierarchy when several types share behavior with meaningful variation.
255
+
256
+ ---
257
+
258
+ ## Function-Level Rules
259
+
260
+ 1. One function should usually perform one coherent task.
261
+ 2. Keep abstraction level consistent inside a function.
262
+ 3. Remove hidden side effects unless the function's purpose is to cause them.
263
+ 4. Prefer guard clauses over deeply nested conditionals when that clarifies the happy path.
264
+ 5. Split phases like parsing, validation, computation, and I/O when they are mixed together.
265
+ 6. Keep variable scope tight.
266
+ 7. Delete dead code rather than comment it out.
267
+
268
+ ---
269
+
270
+ ## Class and Module Rules
271
+
272
+ 1. A class or module should have a narrow reason to change.
273
+ 2. Separate policy from presentation, I/O, persistence, and framework details.
274
+ 3. Prefer composition of small focused units over god objects.
275
+ 4. Delete or inline abstractions that no longer pay for themselves.
276
+ 5. Do not create `utils`, `helpers`, or `common` modules as a default response to duplication.
277
+ 6. Organize modules around concepts and behavior, not leftover convenience.
278
+
279
+ ---
280
+
281
+ ## Rules for Working with Conditionals
282
+
283
+ 1. Replace repeated branching on type or status with stronger modeling when useful.
284
+ 2. Use lookup tables for stable mapping logic.
285
+ 3. Replace nested if/else pyramids with guard clauses, extracted predicates, or strategies when that reduces branching complexity.
286
+ 4. Keep explicit conditionals when they are simple and honest.
287
+ 5. Never introduce polymorphism merely to avoid a small local conditional.
288
+
289
+ ---
290
+
291
+ ## Data and Mutation Rules
292
+
293
+ 1. Encapsulate mutation.
294
+ 2. Narrow write access to the smallest useful surface.
295
+ 3. Replace ad hoc mutations with intention-revealing operations.
296
+ 4. Remove duplicated update logic by centralizing state transitions.
297
+ 5. Prefer immutable intermediate values when that simplifies reasoning.
298
+
299
+ ---
300
+
301
+ ## Error Handling Rules
302
+
303
+ 1. Refactor error handling to make the main path visible.
304
+ 2. Keep cleanup, validation, and recovery logic from drowning core behavior.
305
+ 3. Standardize similar error paths when they duplicate structure.
306
+ 4. Preserve existing error semantics unless intentionally changing behavior.
307
+
308
+ ---
309
+
310
+ ## Review Rules
311
+
312
+ When reviewing or generating changes, actively look for:
313
+ - duplicated logic
314
+ - long functions
315
+ - long classes
316
+ - tangled control flow
317
+ - mixed abstraction levels
318
+ - feature envy
319
+ - shotgun surgery
320
+ - divergent change
321
+ - pass-through layers
322
+ - speculative generality
323
+ - hidden side effects
324
+ - global state reliance
325
+ - code that requires too much context to change safely
326
+
327
+ ---
328
+
329
+ ## Forbidden Patterns
330
+
331
+ Do not generate or keep these patterns unless explicitly required and justified.
332
+
333
+ ### Big-Bang Rewrite
334
+ - replacing a working subsystem wholesale to “clean it up”
335
+ - rewriting before understanding current behavior
336
+ - changing structure and behavior in one giant move
337
+
338
+ ### Mixed-Intent Patches
339
+ - feature work mixed with huge unrelated renames
340
+ - behavior changes hidden inside cleanup
341
+ - code motion that makes review impossible
342
+
343
+ ### Abstracting Too Early
344
+ - introducing interfaces or strategy hierarchies before a second real need appears
345
+ - creating common libraries for one caller
346
+ - replacing understandable duplication with unclear shared code
347
+
348
+ ### Refactoring Theater
349
+ - renaming things while deeper design problems remain untouched
350
+ - introducing patterns instead of removing complexity
351
+ - creating more files, layers, or wrappers without improving changeability
352
+
353
+ ### Untested Structural Surgery
354
+ - large refactors without any safety net
355
+ - “cleanup” on fragile code with no verification strategy
356
+ - assuming behavior is obvious when it is not
357
+
358
+ ---
359
+
360
+ ## Code Generation Rules
361
+
362
+ When asked to modify existing code, use this default order:
363
+ 1. understand current behavior
364
+ 2. identify the friction for the requested change
365
+ 3. add or improve the safety net if needed
366
+ 4. perform preparatory refactoring
367
+ 5. implement the behavioral change
368
+ 6. perform follow-up cleanup
369
+ 7. stop when the design is clearly better
370
+
371
+ Preferred first moves:
372
+ - rename badly named things
373
+ - extract coherent functions
374
+ - isolate side effects
375
+ - split mixed responsibilities
376
+ - move behavior closer to the owning concept
377
+ - remove duplication
378
+ - simplify conditionals
379
+
380
+ Preferred avoidance:
381
+ - unnecessary framework migrations
382
+ - gratuitous API redesign
383
+ - large hierarchy introduction
384
+ - replacing all old code with new code because the old code is ugly
385
+
386
+ ---
387
+
388
+ ## Testing Rules
389
+
390
+ 1. Add characterization tests before risky edits when behavior is unclear.
391
+ 2. Keep tests focused on externally visible behavior.
392
+ 3. Update tests only when behavior intentionally changes.
393
+ 4. Do not couple tests to private implementation details more than necessary.
394
+ 5. Refactor tests too when they become noisy or duplicative.
395
+ 6. Keep test data expressive and minimal.
396
+
397
+ ---
398
+
399
+ ## Stopping Rules
400
+
401
+ Stop refactoring when:
402
+ - the requested change is easy to implement
403
+ - the main smells blocking change are removed
404
+ - further cleanup would become speculative
405
+ - the next abstraction is not yet justified
406
+ - readability and local changeability are clearly improved
407
+
408
+ ---
409
+
410
+ ## Review Checklist
411
+
412
+ Before finalizing any change, verify:
413
+ - Did we preserve observable behavior during refactoring?
414
+ - Did we separate structural change from behavior change where practical?
415
+ - Did we remove at least one real source of friction?
416
+ - Is the code easier to read than before?
417
+ - Is the code easier to test or change than before?
418
+ - Did we reduce duplication or accidental complexity?
419
+ - Did we avoid speculative abstraction?
420
+ - Did we avoid a giant mixed patch?
421
+ - Did names improve?
422
+ - Did control flow become simpler?
423
+ - Did responsibilities become clearer?
424
+
425
+ If any answer is no, revise before shipping.
426
+
427
+ ---
428
+
429
+ ## Final Instruction
430
+
431
+ When uncertain, choose the next **small, behavior-preserving transformation**
432
+ that makes the requested change easier and the code easier to understand.
433
+ Reject approaches that gamble on large rewrites or mix too many intentions at once.
@@ -0,0 +1,49 @@
1
+ # OBEY Refactoring by Martin Fowler
2
+
3
+ ## When to use
4
+
5
+ Use when changing existing code, preparing a feature or bug fix, reviewing cleanup, or reducing structural friction without intending to change observable behavior.
6
+
7
+ ## Primary bias to correct
8
+
9
+ Refactoring is behavior-preserving design work in small steps. Do not turn cleanup into a rewrite, a hidden feature change, or speculative architecture.
10
+
11
+ ## Decision rules
12
+
13
+ - Preserve observable behavior during refactoring. Isolate behavior changes from structural changes and never disguise a feature, migration, or redesign as cleanup.
14
+ - Work in small, reversible, buildable, testable, reviewable steps. Split a patch when it is too large to reason about locally.
15
+ - Establish or identify a safety net before risky refactoring. Use characterization tests for unclear behavior, keep test updates aligned with intended behavior, and never delete a failing test to finish cleanup.
16
+ - Use preparatory and follow-up refactoring around feature work: identify what makes the requested change awkward, reshape that local structure first when useful, make the behavior change, then clean debt introduced by the change.
17
+ - Refactor the current blocking smell, not every smell in sight: duplication, long functions, long parameter lists, globals, divergent change, shotgun surgery, feature envy, primitive obsession, repeated conditionals, temporary fields, middle men, or speculative generality.
18
+ - Prefer the simplest named move that helps: rename, extract, inline, move, split meanings, introduce a parameter or value object, encapsulate a field or collection, decompose conditionals, use guard clauses, or substitute a clearer algorithm.
19
+ - Make names and functions reveal intent. Rename before deeper work when bad names block understanding; keep functions coherent, at one abstraction level, with tight variable scope and separated phases.
20
+ - Put behavior and state with the concept that owns them. Split classes or modules with multiple reasons to change; separate business policy from formatting, transport, persistence, I/O, frameworks, and integration details.
21
+ - Keep data, mutation, and call contracts explicit. Avoid behavior-switching boolean flags, confusing argument order, parameter reassignment, exposed mutable collections, unnecessary setters, public fields, and duplicated state-transition logic.
22
+ - Simplify conditionals honestly. Use guard clauses, extracted predicates, lookup tables, consolidated duplicate fragments, state, strategy, polymorphism, or null objects only when they reduce repeated branching or clarify variation.
23
+ - Use abstraction and generalization only when current evidence justifies them. Remove pass-through layers, vague utilities, middle men, unused hierarchy, and just-in-case interfaces that do not improve changeability.
24
+ - Preserve error semantics unless intentionally changing behavior. Refactor error handling to reveal the main path and consolidate duplicate validation, cleanup, recovery, or error structures.
25
+ - Keep patch intent reviewable. Group related refactorings, separate structural edits from behavior where practical, and avoid giant patches that rename, move, redesign, and change logic together.
26
+ - Stop when the requested change is easy, the blocking smell is gone, readability and local changeability are clearly better, and the next cleanup would be speculative.
27
+
28
+ ## Trigger rules
29
+
30
+ - When adding behavior, first ask what structural friction blocks the change; refactor before the feature only when it makes the feature safer or simpler.
31
+ - When fixing a bug in unclear code, characterize the current failure and refactor only enough to make the fix visible before changing behavior.
32
+ - When tests are absent or weak, make the smallest possible structural move and improve testability before attempting broader cleanup.
33
+ - When the same edit appears for a third time, remove duplication through clearer ownership instead of copying again.
34
+ - When a function mixes responsibilities, abstraction levels, phases, or hidden side effects, rename, extract, split phases, or isolate side effects before adding more logic.
35
+ - When one change forces edits across many files, centralize the knowledge or introduce a clearer boundary.
36
+ - When repeated conditionals or type codes grow, decompose intent first; introduce polymorphism, state, strategy, or a table only when the variation is real.
37
+ - When UI and domain behavior mix, move rules toward domain objects and verify any required presentation synchronization.
38
+ - When a patch mixes intents or code motion makes review hard, split the change unless context makes that impractical.
39
+ - When tempted to rewrite, choose the next small behavior-preserving transformation that recovers control.
40
+
41
+ ## Final checklist
42
+
43
+ - Observable behavior preserved?
44
+ - Structural change, behavior change, and test updates separated where practical?
45
+ - Safety net, characterization, or verification gap recorded?
46
+ - At least one real source of friction removed?
47
+ - Names, responsibilities, control flow, data ownership, and interfaces clearer?
48
+ - Patch still reviewable and runnable?
49
+ - Cleanup stopped before speculative abstraction or rewrite pressure took over?