jdi-cli 0.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 (159) hide show
  1. package/AGENTS.md +209 -0
  2. package/ARCHITECTURE.md +210 -0
  3. package/COMMANDS.md +241 -0
  4. package/CREATE-EXAMPLE.md +385 -0
  5. package/CREATE.md +315 -0
  6. package/EXTENSION.md +141 -0
  7. package/LICENSE +21 -0
  8. package/MEMORY.md +471 -0
  9. package/PORTABILITY.md +438 -0
  10. package/README.md +789 -0
  11. package/bin/git-hooks/post-commit +16 -0
  12. package/bin/git-hooks/pre-commit +21 -0
  13. package/bin/jdi-build.ps1 +381 -0
  14. package/bin/jdi-build.sh +332 -0
  15. package/bin/jdi-doctor.ps1 +403 -0
  16. package/bin/jdi-doctor.sh +400 -0
  17. package/bin/jdi-install-caveman.ps1 +97 -0
  18. package/bin/jdi-install-caveman.sh +99 -0
  19. package/bin/jdi-install-playwright.ps1 +319 -0
  20. package/bin/jdi-install-playwright.sh +284 -0
  21. package/bin/jdi-install.ps1 +154 -0
  22. package/bin/jdi-install.sh +132 -0
  23. package/bin/jdi-uninstall.ps1 +309 -0
  24. package/bin/jdi-uninstall.sh +264 -0
  25. package/bin/jdi-update.ps1 +215 -0
  26. package/bin/jdi-update.sh +209 -0
  27. package/bin/jdi.js +460 -0
  28. package/bin/lib/jdi-monitor.ps1 +66 -0
  29. package/bin/lib/jdi-monitor.sh +74 -0
  30. package/bin/lib/jdi-truncate.ps1 +96 -0
  31. package/bin/lib/jdi-truncate.sh +99 -0
  32. package/bin/lib/ui.js +197 -0
  33. package/core/agents/jdi-adopter.md +465 -0
  34. package/core/agents/jdi-architect.md +894 -0
  35. package/core/agents/jdi-asker.md +153 -0
  36. package/core/agents/jdi-bootstrap.md +247 -0
  37. package/core/agents/jdi-planner.md +254 -0
  38. package/core/agents/jdi-researcher.md +303 -0
  39. package/core/commands/jdi-adopt.md +155 -0
  40. package/core/commands/jdi-bootstrap.md +81 -0
  41. package/core/commands/jdi-create.md +80 -0
  42. package/core/commands/jdi-discuss.md +80 -0
  43. package/core/commands/jdi-do.md +200 -0
  44. package/core/commands/jdi-loop.md +315 -0
  45. package/core/commands/jdi-new.md +131 -0
  46. package/core/commands/jdi-plan.md +73 -0
  47. package/core/commands/jdi-ship.md +146 -0
  48. package/core/commands/jdi-verify.md +159 -0
  49. package/core/skills/clean-code/SKILL.md +261 -0
  50. package/core/skills/dry/SKILL.md +150 -0
  51. package/core/skills/frontend-rules/SKILL.md +386 -0
  52. package/core/skills/frontend-validator/SKILL.md +567 -0
  53. package/core/skills/kiss/SKILL.md +178 -0
  54. package/core/skills/solid/SKILL.md +281 -0
  55. package/core/skills/yagni/SKILL.md +207 -0
  56. package/core/templates/agent.md +72 -0
  57. package/core/templates/doer-specialist.md +216 -0
  58. package/core/templates/reviewer-specialist.md +405 -0
  59. package/core/templates/skill.md +66 -0
  60. package/package.json +70 -0
  61. package/runtimes/antigravity/agents.md +74 -0
  62. package/runtimes/antigravity/skills/clean-code/SKILL.md +252 -0
  63. package/runtimes/antigravity/skills/dry/SKILL.md +141 -0
  64. package/runtimes/antigravity/skills/frontend-rules/SKILL.md +376 -0
  65. package/runtimes/antigravity/skills/frontend-validator/SKILL.md +559 -0
  66. package/runtimes/antigravity/skills/jdi-adopt/SKILL.md +155 -0
  67. package/runtimes/antigravity/skills/jdi-adopter/SKILL.md +436 -0
  68. package/runtimes/antigravity/skills/jdi-architect/SKILL.md +872 -0
  69. package/runtimes/antigravity/skills/jdi-asker/SKILL.md +125 -0
  70. package/runtimes/antigravity/skills/jdi-asker/references/context-template.md +34 -0
  71. package/runtimes/antigravity/skills/jdi-asker/references/decision-format.md +19 -0
  72. package/runtimes/antigravity/skills/jdi-asker/scripts/find_phase_dir.sh +25 -0
  73. package/runtimes/antigravity/skills/jdi-bootstrap/SKILL.md +81 -0
  74. package/runtimes/antigravity/skills/jdi-create/SKILL.md +80 -0
  75. package/runtimes/antigravity/skills/jdi-discuss/SKILL.md +80 -0
  76. package/runtimes/antigravity/skills/jdi-discuss/scripts/run_command.sh +62 -0
  77. package/runtimes/antigravity/skills/jdi-do/SKILL.md +200 -0
  78. package/runtimes/antigravity/skills/jdi-loop/SKILL.md +315 -0
  79. package/runtimes/antigravity/skills/jdi-new/SKILL.md +131 -0
  80. package/runtimes/antigravity/skills/jdi-plan/SKILL.md +73 -0
  81. package/runtimes/antigravity/skills/jdi-planner/SKILL.md +225 -0
  82. package/runtimes/antigravity/skills/jdi-researcher/SKILL.md +274 -0
  83. package/runtimes/antigravity/skills/jdi-ship/SKILL.md +146 -0
  84. package/runtimes/antigravity/skills/jdi-verify/SKILL.md +159 -0
  85. package/runtimes/antigravity/skills/kiss/SKILL.md +169 -0
  86. package/runtimes/antigravity/skills/solid/SKILL.md +272 -0
  87. package/runtimes/antigravity/skills/yagni/SKILL.md +198 -0
  88. package/runtimes/claude/CLAUDE.md +91 -0
  89. package/runtimes/claude/agents/jdi-adopter.md +430 -0
  90. package/runtimes/claude/agents/jdi-architect.md +864 -0
  91. package/runtimes/claude/agents/jdi-asker.md +119 -0
  92. package/runtimes/claude/agents/jdi-bootstrap.md +213 -0
  93. package/runtimes/claude/agents/jdi-planner.md +221 -0
  94. package/runtimes/claude/agents/jdi-researcher.md +269 -0
  95. package/runtimes/claude/commands/jdi-adopt.md +155 -0
  96. package/runtimes/claude/commands/jdi-bootstrap.md +81 -0
  97. package/runtimes/claude/commands/jdi-create.md +80 -0
  98. package/runtimes/claude/commands/jdi-discuss.md +80 -0
  99. package/runtimes/claude/commands/jdi-do.md +200 -0
  100. package/runtimes/claude/commands/jdi-loop.md +315 -0
  101. package/runtimes/claude/commands/jdi-new.md +131 -0
  102. package/runtimes/claude/commands/jdi-plan.md +73 -0
  103. package/runtimes/claude/commands/jdi-ship.md +146 -0
  104. package/runtimes/claude/commands/jdi-verify.md +159 -0
  105. package/runtimes/claude/settings.example.json +132 -0
  106. package/runtimes/claude/skills/clean-code/SKILL.md +247 -0
  107. package/runtimes/claude/skills/dry/SKILL.md +136 -0
  108. package/runtimes/claude/skills/frontend-rules/SKILL.md +369 -0
  109. package/runtimes/claude/skills/frontend-validator/SKILL.md +553 -0
  110. package/runtimes/claude/skills/kiss/SKILL.md +164 -0
  111. package/runtimes/claude/skills/solid/SKILL.md +267 -0
  112. package/runtimes/claude/skills/yagni/SKILL.md +193 -0
  113. package/runtimes/copilot/agents/jdi-adopter.agent.md +430 -0
  114. package/runtimes/copilot/agents/jdi-architect.agent.md +864 -0
  115. package/runtimes/copilot/agents/jdi-asker.agent.md +119 -0
  116. package/runtimes/copilot/agents/jdi-bootstrap.agent.md +213 -0
  117. package/runtimes/copilot/agents/jdi-planner.agent.md +221 -0
  118. package/runtimes/copilot/agents/jdi-researcher.agent.md +269 -0
  119. package/runtimes/copilot/copilot-instructions.md +80 -0
  120. package/runtimes/copilot/prompts/jdi-adopt.prompt.md +155 -0
  121. package/runtimes/copilot/prompts/jdi-bootstrap.prompt.md +81 -0
  122. package/runtimes/copilot/prompts/jdi-create.prompt.md +80 -0
  123. package/runtimes/copilot/prompts/jdi-discuss.prompt.md +80 -0
  124. package/runtimes/copilot/prompts/jdi-do.prompt.md +200 -0
  125. package/runtimes/copilot/prompts/jdi-loop.prompt.md +315 -0
  126. package/runtimes/copilot/prompts/jdi-new.prompt.md +131 -0
  127. package/runtimes/copilot/prompts/jdi-plan.prompt.md +73 -0
  128. package/runtimes/copilot/prompts/jdi-ship.prompt.md +146 -0
  129. package/runtimes/copilot/prompts/jdi-verify.prompt.md +159 -0
  130. package/runtimes/opencode/AGENTS.md +87 -0
  131. package/runtimes/opencode/agents/jdi-adopter.md +434 -0
  132. package/runtimes/opencode/agents/jdi-architect.md +861 -0
  133. package/runtimes/opencode/agents/jdi-asker.md +123 -0
  134. package/runtimes/opencode/agents/jdi-bootstrap.md +217 -0
  135. package/runtimes/opencode/agents/jdi-planner.md +225 -0
  136. package/runtimes/opencode/agents/jdi-researcher.md +273 -0
  137. package/runtimes/opencode/commands/jdi-adopt.md +155 -0
  138. package/runtimes/opencode/commands/jdi-bootstrap.md +81 -0
  139. package/runtimes/opencode/commands/jdi-create.md +80 -0
  140. package/runtimes/opencode/commands/jdi-discuss.md +80 -0
  141. package/runtimes/opencode/commands/jdi-do.md +200 -0
  142. package/runtimes/opencode/commands/jdi-loop.md +315 -0
  143. package/runtimes/opencode/commands/jdi-new.md +131 -0
  144. package/runtimes/opencode/commands/jdi-plan.md +73 -0
  145. package/runtimes/opencode/commands/jdi-ship.md +146 -0
  146. package/runtimes/opencode/commands/jdi-verify.md +159 -0
  147. package/runtimes/opencode/opencode.example.jsonc +169 -0
  148. package/runtimes/opencode/skills/clean-code/SKILL.md +247 -0
  149. package/runtimes/opencode/skills/dry/SKILL.md +136 -0
  150. package/runtimes/opencode/skills/frontend-rules/SKILL.md +369 -0
  151. package/runtimes/opencode/skills/frontend-validator/SKILL.md +553 -0
  152. package/runtimes/opencode/skills/kiss/SKILL.md +164 -0
  153. package/runtimes/opencode/skills/solid/SKILL.md +267 -0
  154. package/runtimes/opencode/skills/yagni/SKILL.md +193 -0
  155. package/templates-jdi-folder/config.json +18 -0
  156. package/templates-jdi-folder/registry.md +31 -0
  157. package/templates-jdi-folder/reviewers.md +33 -0
  158. package/templates-jdi-folder/skills-registry.md +32 -0
  159. package/templates-jdi-folder/specialists.md +39 -0
@@ -0,0 +1,247 @@
1
+ ---
2
+ name: clean-code
3
+ description: Clean Code. Human-readable code, optimized for reading (read 10x more than written). Names reveal intent, small functions, no redundant comments, explicit error handling, no magic numbers. Applies in any language.
4
+ ---
5
+
6
+ # Skill: Clean Code
7
+
8
+ > Code is read 10x more than written. Optimize for reading.
9
+
10
+ Not about pretty style. About **making reader understand in 1 pass**, without mentally simulating execution.
11
+
12
+ ## Rules
13
+
14
+ ### 1. Names reveal intent
15
+
16
+ - **Variable**: what it **is**, not how it's stored (`elapsedSeconds` > `t` > `time`)
17
+ - **Function**: what it **does**, verb + object (`calculateTax(order)`, not `tax(order)`)
18
+ - **Boolean**: yes/no question (`isActive`, `hasPermission`, `canSubmit`)
19
+ - **Class/module**: noun (`OrderRepository`, `EmailValidator`)
20
+ - **Interface**: role/capability (`Repository`, `Cacheable`) — no `I`/`Abstract` prefix if language doesn't require
21
+
22
+ ### Anti-names
23
+
24
+ | Wrong | Right |
25
+ |---|---|
26
+ | `data`, `info`, `value`, `temp`, `result` | something descriptive of the context |
27
+ | `processData()` | `parseUserPayload()`, `applyDiscount()`, etc |
28
+ | `Manager`, `Helper`, `Util` | name of the real responsibility |
29
+ | `flag`, `status` | `isComplete`, `paymentStatus` |
30
+ | `obj`, `item`, `thing` | actual type |
31
+ | Abbreviations: `usr`, `ctx`, `mgr`, `cfg` | `user`, `context` (exception: well-established domain convention) |
32
+ | Variables with `_2`, `_new`, `_old` | refactor until 1 remains |
33
+
34
+ ### 2. Small functions
35
+
36
+ - **Size**: ideally < 20 lines. If over 50, almost certainly doing too much.
37
+ - **1 abstraction level**: inside function, all operations at same level. Mixing "open connection" + "calculate tax" = no.
38
+ - **3-4 params max**: more than that signals either missing object or too much responsibility.
39
+ - **1 logical exit**: early return is OK; multiple returns mid-complex-logic is bad.
40
+
41
+ ### 3. Functions do **one** thing
42
+
43
+ If you describe function as "does X **and** Y", split into two. Function name must be precise.
44
+
45
+ Exception: orchestrators (controllers, command handlers) coordinate — OK to describe as "validates, saves, notifies" if each step is a call to another function.
46
+
47
+ ### 4. Comments
48
+
49
+ **Default: DON'T write**.
50
+
51
+ Well-named code doesn't need to explain **what** it does. If you feel like writing a comment, first attempt: rename function/variable.
52
+
53
+ ### Comments OK when:
54
+
55
+ - **Why** non-obvious: workaround for specific bug, surprising design decision, external constraint
56
+ - **Critical invariant**: "this array MUST be sorted for binary search to work"
57
+ - **TODO/FIXME marker** with ticket link: `// TODO(#1234): handle UTF-16 surrogate`
58
+ - **Pitfall warning**: "// don't call this in a loop, O(n^2)"
59
+ - **Public API doc**: contract for caller (params, returns, exceptions)
60
+
61
+ ### Comments bad when:
62
+
63
+ - Explain **what** (code already says)
64
+ - Repeat the function name in English
65
+ - Comment goes stale relative to code
66
+ - "// removed on XX/YY" left in the tree
67
+ - "// hack" without explanation
68
+ - "// not sure why this works" — investigate, don't guess
69
+
70
+ ### 5. Explicit error handling
71
+
72
+ - **Never silence exception**: `try { ... } catch {}` is **latent bug**
73
+ - **Explicit handling**: structured log + rethrow OR return Result/Either
74
+ - **Errors are part of the contract**: document what can fail
75
+ - **Boundary**: handle error at the boundary (controller, top-level handler), not at every internal call
76
+ - **Validation**: at the entry (boundary), not scattered
77
+
78
+ ### 6. No magic numbers/strings
79
+
80
+ - Number or string with meaning becomes a **named constant**
81
+ - `if (status === 3)` becomes `if (status === OrderStatus.Shipped)`
82
+ - `setTimeout(fn, 86400000)` becomes `setTimeout(fn, MS_PER_DAY)`
83
+ - Exception: 0, 1, -1, universally clear cases
84
+
85
+ ### 7. Command-Query Separation (CQS)
86
+
87
+ - **Query**: returns info, does **not** mutate state
88
+ - **Command**: mutates state, does **not** return (or returns void/minimal ack)
89
+
90
+ `function getUser(id)` that **also** updates last_access violates CQS — caller doesn't expect side-effect. Split.
91
+
92
+ ### 8. Boy Scout Rule
93
+
94
+ > Leave the campground cleaner than you found it.
95
+
96
+ Touched a file? Small cleanness improvement is OK in the same commit:
97
+ - Rename obscure variable
98
+ - Split giant function you already had to read
99
+ - Remove stale comment
100
+ - Delete dead code
101
+
102
+ No heavy unrelated refactor — atomic commit still rules.
103
+
104
+ ### 9. Formatting
105
+
106
+ - **Auto-format**: linter/formatter on the project (prettier, dotnet format, ruff format, gofmt) — no human decisions
107
+ - **Member order**: consistent convention (publics before privates, or group by feature)
108
+ - **Blank line**: separates logical blocks. Function all glued together is hard to scan.
109
+ - **Consistent indentation**: respect project convention
110
+
111
+ ### 10. Symmetry and consistency
112
+
113
+ - Functions at same "level" have similar signature
114
+ - `getUserById, getUserByEmail` — consistent param order
115
+ - Exceptions "as is" vs "throws" vs Result — pick **one** style in the project
116
+ - `null` vs `undefined` vs `Option` — pick **one**
117
+ - Consistent naming convention (camelCase, PascalCase, snake_case) following the language
118
+
119
+ ## Classic code smells
120
+
121
+ | Smell | Symptom |
122
+ |---|---|
123
+ | **Long function** | > 50 lines |
124
+ | **Long parameter list** | > 4 params |
125
+ | **God class** | 1 class does everything |
126
+ | **Feature envy** | method uses more data from **another** class than its own |
127
+ | **Data clump** | same 3-4 params bundled in multiple places -> object |
128
+ | **Primitive obsession** | everything is string/int, no value objects |
129
+ | **Scattered switch statements** | OCP violated |
130
+ | **Shotgun surgery** | simple change touches N files |
131
+ | **Divergent change** | 1 class changes for 5 different reasons (SRP) |
132
+ | **Dead code** | function/parameter/var never used |
133
+ | **Speculative generality** | flexibility without caller (YAGNI) |
134
+ | **Comments compensating bad code** | refactor code, delete comment |
135
+ | **Magic numbers** | 86400, 1024 with no name |
136
+ | **Silenced exceptions** | `catch {}`, `catch (Exception _) { }` |
137
+ | **Long if/else chains** | use polymorphism/strategy |
138
+ | **Inconsistent naming** | `getUser` here, `fetchAccount` there, `loadOrder` over there |
139
+ | **Boolean parameter** | `fn(true)` at caller — nobody knows what `true` means |
140
+
141
+ ## Procedure
142
+
143
+ ### Doer
144
+
145
+ After writing:
146
+ 1. **Name review**: does each variable/function have a name that stands without a comment? Rename if not.
147
+ 2. **Size**: any function > 30 lines? Split.
148
+ 3. **Magic**: any number/string without obvious meaning? Constant.
149
+ 4. **Redundant comments**: any comment that just repeats the code? Delete.
150
+ 5. **Error handling**: any silent `catch {}`? Log or rethrow.
151
+
152
+ ### Reviewer (gate 5)
153
+
154
+ ```bash
155
+ # Long functions
156
+ awk '/^(function|def|public |private |protected |async )/ { start=NR; name=$0 }
157
+ /^}$|^\s{0,2}}\s*$/ { if (NR-start > 50) print FILENAME":"start": function with "(NR-start)" lines: "name }' src/**/*.{ts,cs,py,go,java}
158
+
159
+ # Magic numbers (typical suspects)
160
+ grep -RnE '\b(86400|3600|1024|65535|1000000)\b' src/
161
+
162
+ # Silent catch
163
+ grep -RnE 'catch\s*(\([^)]*\))?\s*\{\s*\}' src/
164
+ grep -RnE 'except.*:\s*pass\s*$' src/
165
+ grep -RnE 'catch.*:.*ignore' src/
166
+
167
+ # TODO without ticket
168
+ grep -RnE 'TODO(?!.*#\d+)|FIXME(?!.*#\d+)' src/
169
+
170
+ # Suspect boolean params
171
+ grep -RnE 'function \w+\([^)]*: bool|: boolean' src/
172
+
173
+ # Generic name
174
+ grep -RnE '\b(data|info|value|temp|tmp|result|obj|item|thing)\b\s*[:=]' src/ | head -20
175
+
176
+ # Dead code (linter catches — confirm)
177
+
178
+ # Obvious comments
179
+ grep -RnE '^\s*//\s*(get|set|return|increment|decrement|loop|iterate)\b' src/
180
+ ```
181
+
182
+ Relevant match -> WARN or BLOCK depending on severity.
183
+
184
+ ## Inputs
185
+
186
+ - Diff/content of the file
187
+ - Project convention (linter config, naming convention from PROJECT.md)
188
+
189
+ ## Outputs
190
+
191
+ Does NOT produce a file. Modifies judgement.
192
+
193
+ ## Examples
194
+
195
+ ### Example 1: bad names
196
+
197
+ Wrong:
198
+ ```python
199
+ def calc(d, t):
200
+ r = d * t * 0.18
201
+ return r
202
+ ```
203
+
204
+ Right:
205
+ ```python
206
+ VAT_RATE = 0.18
207
+
208
+ def calculate_vat(amount: Decimal, qty: int) -> Decimal:
209
+ return amount * qty * VAT_RATE
210
+ ```
211
+
212
+ ### Example 2: giant function
213
+
214
+ Wrong: 1 function of 120 lines validating, saving, sending email, logging.
215
+
216
+ Right: 4 functions of 20 lines each + 1 orchestrator of 15 lines that coordinates.
217
+
218
+ ### Example 3: silenced exception
219
+
220
+ Wrong:
221
+ ```typescript
222
+ try {
223
+ await sendNotification(user)
224
+ } catch {}
225
+ ```
226
+
227
+ Latent bug — notification failure disappears.
228
+
229
+ Right:
230
+ ```typescript
231
+ try {
232
+ await sendNotification(user)
233
+ } catch (err) {
234
+ logger.error("notification failed", { userId: user.id, err })
235
+ // intentional: notification is best-effort, doesn't block flow
236
+ }
237
+ ```
238
+
239
+ Comment here justifies the "why" of the no-rethrow.
240
+
241
+ ### Example 4: boolean param
242
+
243
+ Wrong: `createUser("alice", "alice@x.com", true, false)`
244
+
245
+ Right: `createUser({ name: "alice", email: "alice@x.com", admin: true, sendWelcome: false })`
246
+
247
+ Caller becomes self-documented.
@@ -0,0 +1,136 @@
1
+ ---
2
+ name: dry
3
+ description: DRY (Don't Repeat Yourself). 1 source of truth per piece of knowledge. Detects real duplication (same decision in 2+ places) and separates from apparent duplication (same code, different reasons). Applies in any language.
4
+ ---
5
+
6
+ # Skill: DRY
7
+
8
+ > Every piece of knowledge has **one** authoritative, unambiguous representation in the system.
9
+
10
+ DRY is not about copying code. It's about **duplicated knowledge** — business rule, formula, format, decision, present in 2+ places and that change **together** when the requirement changes.
11
+
12
+ ## Rules
13
+
14
+ ### 1. Knowledge duplication != code coincidence
15
+
16
+ **Knowledge duplication (violates DRY):**
17
+ - Tax calculation in 2 places
18
+ - CPF validation in 3 services
19
+ - Date format schema scattered across the app
20
+ - Same timeout constant in 4 files
21
+
22
+ When the rule changes, you change in N places — miss one, system becomes inconsistent.
23
+
24
+ **Code coincidence (does NOT violate DRY):**
25
+ - 2 functions with 5 identical lines but different domains
26
+ - Framework boilerplate repeated (every controller has `[Authorize]`)
27
+ - Similar iteration loop in 2 unrelated contexts
28
+
29
+ Forcing abstraction here couples things that shouldn't be coupled.
30
+
31
+ ### 2. Rule of 3
32
+
33
+ - 1 occurrence: leave it
34
+ - 2 occurrences: pay attention, but don't abstract yet
35
+ - 3 occurrences: abstract (probably real knowledge duplication)
36
+
37
+ Skipping this rule produces **premature abstraction** — worse than duplication because callers are already coupled to the wrong interface.
38
+
39
+ ### 3. Types of DRY
40
+
41
+ **Code DRY:** reusable functions/classes for repeated logic
42
+ **Data DRY:** 1 source schema (generates DTO + validator + DB + docs)
43
+ **Process DRY:** 1 build script that serves dev + CI + prod
44
+ **Documentation DRY:** docs generated from code, not written in parallel
45
+
46
+ ### 4. Single Source of Truth (SSoT)
47
+
48
+ For each piece of knowledge, identify:
49
+ - **Where the truth lives** (DB schema, env config, business rule)
50
+ - **Who derives from it** (DTOs, types, docs, UI)
51
+ - **Derivation tool** (codegen, schema migration, type inference)
52
+
53
+ Never: manually edit both the source and the derived.
54
+
55
+ ### 5. When NOT to apply DRY
56
+
57
+ - **Premature abstraction**: 2 similar callers but with diverging future evolutions -> leave duplicated
58
+ - **Cross-boundary**: duplicating across microservices > coupling via shared lib
59
+ - **Test setup**: readable redundant tests > shared magical helpers
60
+ - **Wrong abstraction**: better duplicate than extract wrong (Sandi Metz: "duplication is far cheaper than the wrong abstraction")
61
+
62
+ ## Anti-patterns
63
+
64
+ | Anti-pattern | Why it violates |
65
+ |---|---|
66
+ | Copy-paste without extraction after 3rd occurrence | Duplicated knowledge, each caller silently diverges |
67
+ | Utility helper with 15 unrelated functions | "DRY" became ball of mud — bundles unrelated things |
68
+ | Abstraction after 2nd duplication with extension hooks "just in case" | Premature abstraction + YAGNI violated together |
69
+ | Same constant hardcoded in 4 files | Single source of truth absent — extract to config |
70
+ | Validation logic duplicated client + server | Code OK, but should share schema (Zod, Pydantic, JSON Schema) |
71
+ | Comment explaining what code does | Doc duplicates code, will go out of sync |
72
+
73
+ ## Procedure
74
+
75
+ ### Doer (before writing)
76
+
77
+ 1. Is there an identical rule/calculation/constant elsewhere in the codebase? If so, refer/import. Don't duplicate.
78
+ 2. Going to create the 2nd occurrence? OK, but mentally mark it.
79
+ 3. Going to create the 3rd? Stop. Refactor first into abstraction, then use.
80
+
81
+ ### Reviewer (gate 5)
82
+
83
+ Per-language specific greps (examples):
84
+
85
+ ```bash
86
+ # Duplicated magic constants
87
+ grep -RnE '\b86400\b|\b3600\b|\b1024\b' src/
88
+
89
+ # Same string in 3+ places
90
+ sort src/ | uniq -c | sort -rn | head -20 # coarse heuristic
91
+
92
+ # Duplicated email/CPF/etc validation
93
+ grep -RnE 'regex.*@|EmailRegex|CpfValidator|cpf_pattern' src/
94
+
95
+ # Hardcoded URLs/endpoints
96
+ grep -RnE 'https?://[a-z0-9.-]+\.[a-z]{2,}' src/ --include='*.ts' --include='*.cs' --include='*.py'
97
+ ```
98
+
99
+ 3+ matches of the same pattern in different files -> WARN.
100
+
101
+ ## Inputs
102
+
103
+ - Diff or content of the modified file
104
+ - Context: project stack for adapted greps
105
+
106
+ ## Outputs
107
+
108
+ Does NOT produce a file. Modifies judgement:
109
+ - Doer chooses to reuse/extract
110
+ - Reviewer marks WARN with pointer to refactor
111
+
112
+ ## Examples
113
+
114
+ ### Example 1: 3 services calculating tax
115
+
116
+ Wrong:
117
+ ```
118
+ service A: total * 0.18
119
+ service B: amount * 0.18
120
+ service C: value * 0.18
121
+ ```
122
+
123
+ Right: extract `TaxCalculator.applyVat(amount)` or `const VAT_RATE = 0.18` in shared config.
124
+
125
+ Reviewer marks WARN: "tax 0.18 hardcoded in 3 services. Extract to `config/tax.{ts,cs,py}`."
126
+
127
+ ### Example 2: Code coincidence (does NOT violate DRY)
128
+
129
+ ```
130
+ function findUser(id) { return db.query(...) }
131
+ function findOrder(id) { return db.query(...) }
132
+ ```
133
+
134
+ Same structure, different domains. **Don't** extract `findEntity(id, table)` — will force abstraction that will diverge (user has soft-delete, order has cache, etc).
135
+
136
+ Reviewer ignores — code coincidence is OK.