@kinqs/brainrouter-mcp-server 0.3.4

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 (337) hide show
  1. package/.env.example +144 -0
  2. package/README.md +56 -0
  3. package/agents/README.md +120 -0
  4. package/agents/code-reviewer.md +97 -0
  5. package/agents/security-auditor.md +101 -0
  6. package/agents/test-engineer.md +95 -0
  7. package/dist/__tests__/agent_mode.test.d.ts +1 -0
  8. package/dist/__tests__/api-routes.test.d.ts +1 -0
  9. package/dist/__tests__/api-routes.test.js +170 -0
  10. package/dist/__tests__/crypto.test.d.ts +1 -0
  11. package/dist/__tests__/crypto.test.js +28 -0
  12. package/dist/__tests__/host-integrations.test.d.ts +1 -0
  13. package/dist/__tests__/host-integrations.test.js +82 -0
  14. package/dist/__tests__/integration.test.d.ts +1 -0
  15. package/dist/__tests__/integration.test.js +50 -0
  16. package/dist/__tests__/loader.test.d.ts +1 -0
  17. package/dist/__tests__/loader.test.js +89 -0
  18. package/dist/__tests__/neural-spark.test.d.ts +1 -0
  19. package/dist/__tests__/neural-spark.test.js +112 -0
  20. package/dist/__tests__/pagination.test.d.ts +1 -0
  21. package/dist/__tests__/pagination.test.js +23 -0
  22. package/dist/__tests__/redaction.test.d.ts +1 -0
  23. package/dist/__tests__/redaction.test.js +17 -0
  24. package/dist/__tests__/registry.test.d.ts +1 -0
  25. package/dist/__tests__/registry.test.js +56 -0
  26. package/dist/__tests__/retry.test.d.ts +1 -0
  27. package/dist/__tests__/retry.test.js +30 -0
  28. package/dist/__tests__/skill-activation.test.d.ts +1 -0
  29. package/dist/__tests__/skill-activation.test.js +112 -0
  30. package/dist/__tests__/working-memory.test.d.ts +1 -0
  31. package/dist/__tests__/working-memory.test.js +200 -0
  32. package/dist/__tests__/workspace-paths.test.d.ts +1 -0
  33. package/dist/__tests__/workspace-paths.test.js +56 -0
  34. package/dist/__tests__/writer.test.d.ts +1 -0
  35. package/dist/__tests__/writer.test.js +94 -0
  36. package/dist/api/auth/crypto.d.ts +4 -0
  37. package/dist/api/auth/crypto.js +54 -0
  38. package/dist/api/middleware/auth.d.ts +12 -0
  39. package/dist/api/middleware/auth.js +90 -0
  40. package/dist/api/pagination.d.ts +18 -0
  41. package/dist/api/pagination.js +32 -0
  42. package/dist/api/routes/auth.d.ts +1 -0
  43. package/dist/api/routes/auth.js +130 -0
  44. package/dist/api/routes/chat-completions.d.ts +7 -0
  45. package/dist/api/routes/chat-completions.js +474 -0
  46. package/dist/api/routes/contradictions.d.ts +1 -0
  47. package/dist/api/routes/contradictions.js +28 -0
  48. package/dist/api/routes/evidence.d.ts +1 -0
  49. package/dist/api/routes/evidence.js +59 -0
  50. package/dist/api/routes/governance.d.ts +1 -0
  51. package/dist/api/routes/governance.js +95 -0
  52. package/dist/api/routes/graph.d.ts +1 -0
  53. package/dist/api/routes/graph.js +25 -0
  54. package/dist/api/routes/hooks.d.ts +1 -0
  55. package/dist/api/routes/hooks.js +88 -0
  56. package/dist/api/routes/memories.d.ts +1 -0
  57. package/dist/api/routes/memories.js +92 -0
  58. package/dist/api/routes/persona.d.ts +1 -0
  59. package/dist/api/routes/persona.js +9 -0
  60. package/dist/api/routes/scenes.d.ts +1 -0
  61. package/dist/api/routes/scenes.js +35 -0
  62. package/dist/api/routes/skills.d.ts +1 -0
  63. package/dist/api/routes/skills.js +14 -0
  64. package/dist/api/routes/stats.d.ts +1 -0
  65. package/dist/api/routes/stats.js +8 -0
  66. package/dist/api/routes/users.d.ts +1 -0
  67. package/dist/api/routes/users.js +82 -0
  68. package/dist/api/routes/working.d.ts +1 -0
  69. package/dist/api/routes/working.js +88 -0
  70. package/dist/index.d.ts +2 -0
  71. package/dist/index.js +492 -0
  72. package/dist/integrations/claude-code.d.ts +12 -0
  73. package/dist/integrations/claude-code.js +35 -0
  74. package/dist/integrations/codex.d.ts +12 -0
  75. package/dist/integrations/codex.js +34 -0
  76. package/dist/integrations/generic-mcp.d.ts +52 -0
  77. package/dist/integrations/generic-mcp.js +118 -0
  78. package/dist/loader.d.ts +29 -0
  79. package/dist/loader.js +200 -0
  80. package/dist/memory/capture.d.ts +35 -0
  81. package/dist/memory/capture.js +230 -0
  82. package/dist/memory/config.d.ts +2 -0
  83. package/dist/memory/config.js +3 -0
  84. package/dist/memory/engine.d.ts +203 -0
  85. package/dist/memory/engine.js +626 -0
  86. package/dist/memory/llm-semaphore.d.ts +41 -0
  87. package/dist/memory/llm-semaphore.js +81 -0
  88. package/dist/memory/memory-type-config.d.ts +11 -0
  89. package/dist/memory/memory-type-config.js +65 -0
  90. package/dist/memory/pipeline/cognitive-contradiction.d.ts +7 -0
  91. package/dist/memory/pipeline/cognitive-contradiction.js +59 -0
  92. package/dist/memory/pipeline/cognitive-dedup.d.ts +23 -0
  93. package/dist/memory/pipeline/cognitive-dedup.js +38 -0
  94. package/dist/memory/pipeline/cognitive-extractor.d.ts +21 -0
  95. package/dist/memory/pipeline/cognitive-extractor.js +183 -0
  96. package/dist/memory/pipeline/contextual-focus-builder.d.ts +13 -0
  97. package/dist/memory/pipeline/contextual-focus-builder.js +135 -0
  98. package/dist/memory/pipeline/focus-direction-shift.d.ts +10 -0
  99. package/dist/memory/pipeline/focus-direction-shift.js +27 -0
  100. package/dist/memory/pipeline/graph-builder.d.ts +11 -0
  101. package/dist/memory/pipeline/graph-builder.js +88 -0
  102. package/dist/memory/pipeline/graph-recall.d.ts +13 -0
  103. package/dist/memory/pipeline/graph-recall.js +55 -0
  104. package/dist/memory/pipeline/identity-distiller.d.ts +15 -0
  105. package/dist/memory/pipeline/identity-distiller.js +40 -0
  106. package/dist/memory/pipeline/l1-contradiction.d.ts +7 -0
  107. package/dist/memory/pipeline/l1-contradiction.js +66 -0
  108. package/dist/memory/pipeline/l1-dedup.d.ts +23 -0
  109. package/dist/memory/pipeline/l1-dedup.js +39 -0
  110. package/dist/memory/pipeline/l1-extractor.d.ts +21 -0
  111. package/dist/memory/pipeline/l1-extractor.js +180 -0
  112. package/dist/memory/pipeline/l2-direction-shift.d.ts +10 -0
  113. package/dist/memory/pipeline/l2-direction-shift.js +27 -0
  114. package/dist/memory/pipeline/l2-scene.d.ts +15 -0
  115. package/dist/memory/pipeline/l2-scene.js +140 -0
  116. package/dist/memory/pipeline/l3-distiller.d.ts +15 -0
  117. package/dist/memory/pipeline/l3-distiller.js +40 -0
  118. package/dist/memory/pipeline/neural-spark.d.ts +27 -0
  119. package/dist/memory/pipeline/neural-spark.js +78 -0
  120. package/dist/memory/pipeline/skill-prewarm.d.ts +63 -0
  121. package/dist/memory/pipeline/skill-prewarm.js +127 -0
  122. package/dist/memory/pipeline/task-queue.d.ts +54 -0
  123. package/dist/memory/pipeline/task-queue.js +117 -0
  124. package/dist/memory/prompts/cognitive-contradiction.d.ts +1 -0
  125. package/dist/memory/prompts/cognitive-contradiction.js +25 -0
  126. package/dist/memory/prompts/cognitive-extraction.d.ts +10 -0
  127. package/dist/memory/prompts/cognitive-extraction.js +114 -0
  128. package/dist/memory/prompts/core-identity.d.ts +6 -0
  129. package/dist/memory/prompts/core-identity.js +60 -0
  130. package/dist/memory/prompts/focus-direction-shift.d.ts +5 -0
  131. package/dist/memory/prompts/focus-direction-shift.js +32 -0
  132. package/dist/memory/prompts/focus-scene-cluster.d.ts +2 -0
  133. package/dist/memory/prompts/focus-scene-cluster.js +33 -0
  134. package/dist/memory/prompts/focus-scene.d.ts +7 -0
  135. package/dist/memory/prompts/focus-scene.js +40 -0
  136. package/dist/memory/prompts/graph-extraction-batch.d.ts +14 -0
  137. package/dist/memory/prompts/graph-extraction-batch.js +54 -0
  138. package/dist/memory/prompts/graph-extraction.d.ts +2 -0
  139. package/dist/memory/prompts/graph-extraction.js +53 -0
  140. package/dist/memory/prompts/l1-contradiction-batch.d.ts +16 -0
  141. package/dist/memory/prompts/l1-contradiction-batch.js +47 -0
  142. package/dist/memory/prompts/l1-contradiction.d.ts +1 -0
  143. package/dist/memory/prompts/l1-contradiction.js +25 -0
  144. package/dist/memory/prompts/l1-extraction.d.ts +10 -0
  145. package/dist/memory/prompts/l1-extraction.js +114 -0
  146. package/dist/memory/prompts/l2-direction-shift.d.ts +5 -0
  147. package/dist/memory/prompts/l2-direction-shift.js +32 -0
  148. package/dist/memory/prompts/l2-scene-cluster.d.ts +2 -0
  149. package/dist/memory/prompts/l2-scene-cluster.js +33 -0
  150. package/dist/memory/prompts/l2-scene.d.ts +7 -0
  151. package/dist/memory/prompts/l2-scene.js +40 -0
  152. package/dist/memory/prompts/l3-persona.d.ts +6 -0
  153. package/dist/memory/prompts/l3-persona.js +60 -0
  154. package/dist/memory/recall.d.ts +47 -0
  155. package/dist/memory/recall.js +427 -0
  156. package/dist/memory/redaction.d.ts +1 -0
  157. package/dist/memory/redaction.js +24 -0
  158. package/dist/memory/retry.d.ts +13 -0
  159. package/dist/memory/retry.js +53 -0
  160. package/dist/memory/scheduler.d.ts +9 -0
  161. package/dist/memory/scheduler.js +16 -0
  162. package/dist/memory/skill-hints-loader.d.ts +30 -0
  163. package/dist/memory/skill-hints-loader.js +100 -0
  164. package/dist/memory/store/embedding.d.ts +16 -0
  165. package/dist/memory/store/embedding.js +68 -0
  166. package/dist/memory/store/reranker.d.ts +24 -0
  167. package/dist/memory/store/reranker.js +83 -0
  168. package/dist/memory/store/sqlite.d.ts +167 -0
  169. package/dist/memory/store/sqlite.js +1816 -0
  170. package/dist/memory/store/types.d.ts +101 -0
  171. package/dist/memory/store/types.js +1 -0
  172. package/dist/memory/types.d.ts +207 -0
  173. package/dist/memory/types.js +7 -0
  174. package/dist/memory/validation.d.ts +441 -0
  175. package/dist/memory/validation.js +129 -0
  176. package/dist/memory/working/canvas.d.ts +5 -0
  177. package/dist/memory/working/canvas.js +43 -0
  178. package/dist/memory/working/offload.d.ts +71 -0
  179. package/dist/memory/working/offload.js +211 -0
  180. package/dist/memory/working/step-log.d.ts +16 -0
  181. package/dist/memory/working/step-log.js +35 -0
  182. package/dist/registry.d.ts +34 -0
  183. package/dist/registry.js +305 -0
  184. package/dist/resolver.d.ts +17 -0
  185. package/dist/resolver.js +126 -0
  186. package/dist/scripts/validate-foreign-workspace-path.d.ts +1 -0
  187. package/dist/scripts/validate-foreign-workspace-path.js +39 -0
  188. package/dist/tools/agent_memory_tools.d.ts +485 -0
  189. package/dist/tools/agent_memory_tools.js +793 -0
  190. package/dist/tools/create_skill.d.ts +46 -0
  191. package/dist/tools/create_skill.js +46 -0
  192. package/dist/tools/get_doc.d.ts +21 -0
  193. package/dist/tools/get_doc.js +24 -0
  194. package/dist/tools/get_persona.d.ts +15 -0
  195. package/dist/tools/get_persona.js +20 -0
  196. package/dist/tools/get_reference.d.ts +15 -0
  197. package/dist/tools/get_reference.js +20 -0
  198. package/dist/tools/get_skill.d.ts +34 -0
  199. package/dist/tools/get_skill.js +65 -0
  200. package/dist/tools/get_template_doc.d.ts +21 -0
  201. package/dist/tools/get_template_doc.js +24 -0
  202. package/dist/tools/list_docs.d.ts +15 -0
  203. package/dist/tools/list_docs.js +16 -0
  204. package/dist/tools/list_skills.d.ts +18 -0
  205. package/dist/tools/list_skills.js +17 -0
  206. package/dist/tools/list_template_docs.d.ts +15 -0
  207. package/dist/tools/list_template_docs.js +16 -0
  208. package/dist/tools/memory-engineering.d.ts +225 -0
  209. package/dist/tools/memory-engineering.js +284 -0
  210. package/dist/tools/memory-explain.d.ts +34 -0
  211. package/dist/tools/memory-explain.js +109 -0
  212. package/dist/tools/memory-governance.d.ts +171 -0
  213. package/dist/tools/memory-governance.js +224 -0
  214. package/dist/tools/memory-hooks.d.ts +67 -0
  215. package/dist/tools/memory-hooks.js +102 -0
  216. package/dist/tools/memory-working.d.ts +98 -0
  217. package/dist/tools/memory-working.js +101 -0
  218. package/dist/tools/memory_capture_turn.d.ts +66 -0
  219. package/dist/tools/memory_capture_turn.js +85 -0
  220. package/dist/tools/memory_consolidate.d.ts +55 -0
  221. package/dist/tools/memory_consolidate.js +176 -0
  222. package/dist/tools/memory_contradictions.d.ts +53 -0
  223. package/dist/tools/memory_contradictions.js +52 -0
  224. package/dist/tools/memory_graph_query.d.ts +51 -0
  225. package/dist/tools/memory_graph_query.js +35 -0
  226. package/dist/tools/memory_mark_cited.d.ts +43 -0
  227. package/dist/tools/memory_mark_cited.js +63 -0
  228. package/dist/tools/memory_recall.d.ts +77 -0
  229. package/dist/tools/memory_recall.js +81 -0
  230. package/dist/tools/memory_register_skill_hints.d.ts +49 -0
  231. package/dist/tools/memory_register_skill_hints.js +55 -0
  232. package/dist/tools/memory_resolve_session.d.ts +24 -0
  233. package/dist/tools/memory_resolve_session.js +133 -0
  234. package/dist/tools/memory_search.d.ts +146 -0
  235. package/dist/tools/memory_search.js +84 -0
  236. package/dist/tools/search_skills.d.ts +18 -0
  237. package/dist/tools/search_skills.js +17 -0
  238. package/dist/tools/update_doc.d.ts +24 -0
  239. package/dist/tools/update_doc.js +35 -0
  240. package/dist/tools/update_skill.d.ts +30 -0
  241. package/dist/tools/update_skill.js +80 -0
  242. package/dist/types.d.ts +81 -0
  243. package/dist/types.js +4 -0
  244. package/dist/writer.d.ts +30 -0
  245. package/dist/writer.js +220 -0
  246. package/docs/TEMPLATE ONLY +1 -0
  247. package/docs/api/API.md +64 -0
  248. package/docs/api/security/SECURITY.md +58 -0
  249. package/docs/deployment/DockerDeployment.md +30 -0
  250. package/docs/design/Design.md +59 -0
  251. package/docs/design/themes/apple.md +101 -0
  252. package/docs/design/themes/dieter-grid.md +100 -0
  253. package/docs/design/themes/gallery-white.md +100 -0
  254. package/docs/design/themes/pinterest.md +101 -0
  255. package/docs/design/themes/realty-open-house.md +101 -0
  256. package/docs/design/themes/vodafone.md +101 -0
  257. package/docs/hooks/Hooks.md +30 -0
  258. package/docs/schema/Schema.md +35 -0
  259. package/docs/strategy/ScalingStrategy.md +19 -0
  260. package/package.json +88 -0
  261. package/references/accessibility-checklist.md +160 -0
  262. package/references/orchestration-patterns.md +370 -0
  263. package/references/performance-checklist.md +153 -0
  264. package/references/security-checklist.md +134 -0
  265. package/references/testing-patterns.md +236 -0
  266. package/skills/agent/adr-skill/SKILL.md +299 -0
  267. package/skills/agent/agentic-engineering-workflow/SKILL.md +95 -0
  268. package/skills/agent/bootstrap-skill/SKILL.md +103 -0
  269. package/skills/agent/context-engineering/SKILL.md +307 -0
  270. package/skills/agent/debugging-and-error-recovery/SKILL.md +308 -0
  271. package/skills/agent/developer-growth-analysis/SKILL.md +328 -0
  272. package/skills/agent/doubt-driven-skill/SKILL.md +249 -0
  273. package/skills/agent/handover-skill/SKILL.md +112 -0
  274. package/skills/agent/idea-refine-skill/SKILL.md +185 -0
  275. package/skills/agent/idea-refine-skill/examples.md +238 -0
  276. package/skills/agent/idea-refine-skill/frameworks.md +99 -0
  277. package/skills/agent/idea-refine-skill/refinement-criteria.md +113 -0
  278. package/skills/agent/interview-skill/SKILL.md +226 -0
  279. package/skills/agent/planning-skill/SKILL.md +270 -0
  280. package/skills/agent/skill-authoring/SKILL.md +189 -0
  281. package/skills/agent/source-driven-skill/SKILL.md +197 -0
  282. package/skills/agent/spec-driven-skill/SKILL.md +221 -0
  283. package/skills/agent/sync-skill/SKILL.md +92 -0
  284. package/skills/agent/using-agent-skills/SKILL.md +189 -0
  285. package/skills/api/a11y-skill/SKILL.md +88 -0
  286. package/skills/api/api-skill/SKILL.md +123 -0
  287. package/skills/api/auth-skill/SKILL.md +80 -0
  288. package/skills/api/debug-skill/SKILL.md +535 -0
  289. package/skills/api/performance-skill/SKILL.md +100 -0
  290. package/skills/api/testing-skill/SKILL.md +100 -0
  291. package/skills/codebase/code-review-and-quality/SKILL.md +228 -0
  292. package/skills/codebase/code-simplification/SKILL.md +352 -0
  293. package/skills/codebase/code-structure-cleanup/SKILL.md +142 -0
  294. package/skills/codebase/concerns-skill/SKILL.md +89 -0
  295. package/skills/codebase/conventions-skill/SKILL.md +95 -0
  296. package/skills/codebase/doc-management-skill/SKILL.md +47 -0
  297. package/skills/codebase/git-workflow-skill/SKILL.md +312 -0
  298. package/skills/communication/1-3-1-rule/SKILL.md +120 -0
  299. package/skills/design/brutalist-skill/SKILL.md +131 -0
  300. package/skills/design/concept-diagrams/SKILL.md +387 -0
  301. package/skills/design/concept-diagrams/examples/apartment-floor-plan-conversion.md +244 -0
  302. package/skills/design/concept-diagrams/examples/automated-password-reset-flow.md +276 -0
  303. package/skills/design/concept-diagrams/examples/autonomous-llm-research-agent-flow.md +240 -0
  304. package/skills/design/concept-diagrams/examples/banana-journey-tree-to-smoothie.md +161 -0
  305. package/skills/design/concept-diagrams/examples/commercial-aircraft-structure.md +209 -0
  306. package/skills/design/concept-diagrams/examples/cpu-ooo-microarchitecture.md +236 -0
  307. package/skills/design/concept-diagrams/examples/electricity-grid-flow.md +182 -0
  308. package/skills/design/concept-diagrams/examples/feature-film-production-pipeline.md +172 -0
  309. package/skills/design/concept-diagrams/examples/hospital-emergency-department-flow.md +165 -0
  310. package/skills/design/concept-diagrams/examples/ml-benchmark-grouped-bar-chart.md +114 -0
  311. package/skills/design/concept-diagrams/examples/place-order-uml-sequence.md +325 -0
  312. package/skills/design/concept-diagrams/examples/smart-city-infrastructure.md +173 -0
  313. package/skills/design/concept-diagrams/examples/smartphone-layer-anatomy.md +154 -0
  314. package/skills/design/concept-diagrams/examples/sn2-reaction-mechanism.md +247 -0
  315. package/skills/design/concept-diagrams/examples/wind-turbine-structure.md +338 -0
  316. package/skills/design/concept-diagrams/references/dashboard-patterns.md +43 -0
  317. package/skills/design/concept-diagrams/references/infrastructure-patterns.md +144 -0
  318. package/skills/design/concept-diagrams/references/physical-shape-cookbook.md +42 -0
  319. package/skills/design/concept-diagrams/templates/template.html +174 -0
  320. package/skills/design/gpt-tasteskill/SKILL.md +114 -0
  321. package/skills/design/minimalist-skill/SKILL.md +116 -0
  322. package/skills/design/output-skill/SKILL.md +87 -0
  323. package/skills/design/redesign-skill/SKILL.md +213 -0
  324. package/skills/design/soft-skill/SKILL.md +132 -0
  325. package/skills/design/stitch-skill/EXAMPLE.md +121 -0
  326. package/skills/design/stitch-skill/SKILL.md +222 -0
  327. package/skills/design/taste-skill/SKILL.md +269 -0
  328. package/skills/devops/ci-cd-skill/SKILL.md +402 -0
  329. package/skills/devops/docker-skill/SKILL.md +297 -0
  330. package/skills/devops/domain-skill/SKILL.md +234 -0
  331. package/skills/lifecycle/changelog-generator/SKILL.md +135 -0
  332. package/skills/lifecycle/incremental-skill/SKILL.md +257 -0
  333. package/skills/lifecycle/migration-skill/SKILL.md +218 -0
  334. package/skills/lifecycle/shipping-skill/SKILL.md +321 -0
  335. package/skills/memory/agent-memory/SKILL.md +122 -0
  336. package/skills/qa/browser-testing-skill/SKILL.md +314 -0
  337. package/skills/ux/adversarial-ux-skill/SKILL.md +168 -0
@@ -0,0 +1,100 @@
1
+ ---
2
+ name: testing-skill
3
+ description: Mocking strategies, assertion standards, integration testing, and test coverage rules. Use when writing tests for new features, bug fixes, API endpoints, or core library integrations.
4
+ hints: |
5
+ - Write tests alongside or immediately after implementing code to verify behavioral paths.
6
+ - Mock all external dependencies (e.g. databases, Redis caches, email services, third-party APIs).
7
+ - Verify security barriers, including authentication blocks, permission levels, and validation errors.
8
+ - Enforce strict response schema checks using object matching or JSON schema snapshots.
9
+ - Target 100% path coverage for error handling branches and catch blocks.
10
+ ---
11
+
12
+ # Testing Skill
13
+
14
+ ## Overview
15
+
16
+ This skill ensures that every codebase feature is robust, regression-free, secure, and easily verifiable. All new features and endpoints must incorporate corresponding unit or integration tests that validate both standard success operations and failure boundaries.
17
+
18
+ ## Workflow
19
+
20
+ - **[TEST-001] Security Shield Verification**
21
+ - Integration tests must verify the entire request-handling ingress pipeline:
22
+ - Confirm `401 Unauthorized` responses when requests are unauthenticated.
23
+ - Confirm `403 Forbidden` responses when requests lack required roles.
24
+ - Confirm `429 Too Many Requests` when rate limits are exceeded (using mocks to accelerate testing).
25
+ - Confirm `400 Bad Request` when structural input validation (e.g., Zod, Joi) fails.
26
+
27
+ - **[TEST-002] Mandatory Mocking**
28
+ - Never run unit or integration tests against a live production database or external system.
29
+ - Mock all database querying layers (such as `readQuery`, `writeQuery`, or ORM functions) using mock injection systems.
30
+ - Mock all external integrations, including Cloud storage, email transmitters, and Redis cache clusters.
31
+
32
+ - **[TEST-003] Response Schema Consistency**
33
+ - Ensure API responses precisely match active specifications using `expect.objectContaining` or json-schema snapshot comparisons.
34
+
35
+ - **[TEST-004] Error Case Coverage**
36
+ - Exercise failure branches. Tests must cover `catch` blocks, invalid formats, entity-not-found exceptions, and rate limit occurrences.
37
+
38
+ ## Implementation Pattern (Vitest + Supertest)
39
+
40
+ ```typescript
41
+ import request from 'supertest';
42
+ import { vi, describe, it, expect } from 'vitest';
43
+ import app from '../../app';
44
+ import { query } from '../../database/connection';
45
+
46
+ vi.mock('../../database/connection');
47
+
48
+ describe('POST /api/v1/resource', () => {
49
+ it('should reject unauthenticated requests [TEST-001]', async () => {
50
+ const response = await request(app).post('/api/v1/resource').send({});
51
+ expect(response.status).toBe(401);
52
+ });
53
+
54
+ it('should validate input using Zod [TEST-001]', async () => {
55
+ const response = await request(app)
56
+ .post('/api/v1/resource')
57
+ .set('Authorization', 'Bearer valid_token')
58
+ .send({ invalid: 'data' });
59
+ expect(response.status).toBe(400);
60
+ expect(response.body.error.code).toBe('VALIDATION_ERROR');
61
+ });
62
+ });
63
+ ```
64
+
65
+ ---
66
+
67
+ ## When to Use
68
+
69
+ - Implementing new backend routes, controllers, or service logic.
70
+ - Resolving bugs, where a regression-preventing test should be added.
71
+ - Modifying critical authentication, security, or routing middlewares.
72
+ - Restructuring core data-fetching models or database connectors.
73
+
74
+ **When NOT to use:**
75
+ - Updating documentation files (`README.md`, `walkthrough.md`) or configuration comments.
76
+ - Working on local scratch files, design assets, or styling-only UI adjustments.
77
+
78
+ ## Common Rationalizations
79
+
80
+ | Rationalization | Reality |
81
+ |---|---|
82
+ | "The feature is too simple to test." | Simple features aggregate. Without automated test verification, basic structural regressions occur when global layouts or database models change. |
83
+ | "Writing mocks is too slow and tedious." | Live database connections in tests cause flaky, slow, and environment-dependent builds. Mocks guarantee stable, ultra-fast test execution. |
84
+ | "I'll add test coverage in a subsequent PR." | Post-hoc testing rarely happens due to shifting priorities. Features without automated proof of success are considered incomplete. |
85
+
86
+ ## Red Flags
87
+
88
+ - Tests that require a live, external internet connection or local database instance to pass.
89
+ - Bypassing input validation or authorization middleware checks in integration tests.
90
+ - High test coverage metrics that only assert success paths while completely skipping failure scenarios.
91
+ - Suppressing uncaught exceptions or console errors inside active test suites.
92
+
93
+ ## Verification
94
+
95
+ After completing the test suite implementation, verify:
96
+ - [ ] Automated test suite runs synchronously and passes without flakiness or timeout warnings.
97
+ - [ ] Security boundaries (401 Unauthorized, 400 Bad Request) are explicitly tested.
98
+ - [ ] Database interfaces and external API calls are verified as 100% mocked.
99
+ - [ ] Response structures match specifications precisely.
100
+ - [ ] Test coverage reports are generated and confirm error path traversal.
@@ -0,0 +1,228 @@
1
+ ---
2
+ name: code-review-and-quality
3
+ description: Conducts multi-axis code review across correctness, readability, architecture, security, and performance. Use before merging any change. Use when reviewing code written by yourself, another agent, or a human. Use when running an agentic review-fix loop until tests pass and the PR is clean.
4
+ hints: |
5
+ - Review tests first — they reveal intent before you read the implementation.
6
+ - Evaluate across all five axes: correctness, readability, architecture, security, performance.
7
+ - PRs over ~300 lines should be split before review — accuracy degrades on large diffs.
8
+ - In the review-fix loop: fix only issues that are real and relevant — never over-fix.
9
+ - Approve when the change improves overall code health, even if it isn't perfect.
10
+ memory_hints: |
11
+ - Capture recurring review failures the user encounters (e.g. always missing error handling, recurring N+1 patterns).
12
+ - Note if user consistently skips specific review axes (e.g. tends to skip security review).
13
+ - Extract project-specific quality standards the user has set (e.g. "all PRs must be under 200 lines").
14
+ - Remember when user requests review on AI-generated code — note what types of issues are found.
15
+ ---
16
+
17
+ # Code Review and Quality
18
+
19
+ ## Overview
20
+
21
+ Multi-dimensional code review with quality gates. Every change gets reviewed before merge — no exceptions. Review covers five axes: correctness, readability, architecture, security, and performance.
22
+
23
+ **The approval standard:** Approve a change when it definitely improves overall code health, even if it isn't perfect. Perfect code doesn't exist — the goal is continuous improvement. Don't block a change because it isn't exactly how you would have written it. If it improves the codebase and follows the project's conventions, approve it.
24
+
25
+ ## When to Use
26
+
27
+ - Before merging any PR or change
28
+ - After completing a feature implementation
29
+ - When another agent or model produced code you need to evaluate
30
+ - When refactoring existing code
31
+ - After any bug fix (review both the fix and the regression test)
32
+
33
+ ## Workflow
34
+
35
+ Read the diff and task context first, review tests before implementation details, evaluate the five quality axes, list concrete findings with severity and file references, then verify fixes with the relevant build and test commands.
36
+
37
+ ## The Five-Axis Review
38
+
39
+ Every review evaluates code across these dimensions:
40
+
41
+ ### 1. Correctness
42
+
43
+ Does the code do what it claims to do?
44
+
45
+ - Does it match the spec or task requirements?
46
+ - Are edge cases handled (null, empty, boundary values)?
47
+ - Are error paths handled (not just the happy path)?
48
+ - Does it pass all tests? Are the tests actually testing the right things?
49
+ - Are there off-by-one errors, race conditions, or state inconsistencies?
50
+
51
+ ### 2. Readability & Simplicity
52
+
53
+ Can another engineer (or agent) understand this code without the author explaining it?
54
+
55
+ - Are names descriptive and consistent with project conventions? (No `temp`, `data`, `result` without context)
56
+ - Is the control flow straightforward (avoid nested ternaries, deep callbacks)?
57
+ - Is the code organized logically (related code grouped, clear module boundaries)?
58
+ - Are there any "clever" tricks that should be simplified?
59
+ - **Could this be done in fewer lines?** (1000 lines where 100 suffice is a failure)
60
+ - **Are abstractions earning their complexity?** (Don't generalize until the third use case)
61
+ - Would comments help clarify non-obvious intent? (But don't comment obvious code.)
62
+ - Are there dead code artifacts: no-op variables (`_unused`), backwards-compat shims, or `// removed` comments?
63
+
64
+ ### 3. Architecture
65
+
66
+ Does the change fit the system's design?
67
+
68
+ - Does it follow existing patterns or introduce a new one? If new, is it justified?
69
+ - Does it maintain clean module boundaries?
70
+ - Is there code duplication that should be shared?
71
+ - Are dependencies flowing in the right direction (no circular dependencies)?
72
+ - Is the abstraction level appropriate (not over-engineered, not too coupled)?
73
+
74
+ ### 4. Security
75
+
76
+ For detailed security guidance, see `security-and-hardening`. Does the change introduce vulnerabilities?
77
+
78
+ - Is user input validated and sanitized?
79
+ - Are secrets kept out of code, logs, and version control?
80
+ - Is authentication/authorization checked where needed?
81
+ - Are SQL queries parameterized (no string concatenation)?
82
+ - Are outputs encoded to prevent XSS?
83
+ - Are dependencies from trusted sources with no known vulnerabilities?
84
+ - Is data from external sources (APIs, logs, user content, config files) treated as untrusted?
85
+ - Are external data flows validated at system boundaries before use in logic or rendering?
86
+
87
+ ### 5. Performance
88
+
89
+ For detailed profiling and optimization, see `performance-optimization`. Does the change introduce performance problems?
90
+
91
+ - Any N+1 query patterns?
92
+ - Any unbounded loops or unconstrained data fetching?
93
+ - Any synchronous operations that should be async?
94
+ - Any unnecessary re-renders in UI components?
95
+ - Any missing pagination on list endpoints?
96
+ - Any large objects created in hot paths?
97
+
98
+ ## Change Sizing
99
+
100
+ Small, focused changes are easier to review, faster to merge, and safer to deploy. Target these sizes:
101
+
102
+ ```
103
+ ~100 lines changed → Good. Reviewable in one sitting.
104
+ ~300 lines changed → Acceptable if it's a single logical change.
105
+ ~1000 lines changed → Too large. Split it.
106
+ ```
107
+
108
+ **What counts as "one change":** A single self-contained modification that addresses one thing, includes related tests, and keeps the system functional after submission. One part of a feature — not the whole feature.
109
+
110
+ ## Change Descriptions
111
+
112
+ Every change needs a description that stands alone in version control history.
113
+
114
+ **First line:** Short, imperative, standalone. "Delete the FizzBuzz RPC" not "Deleting the FizzBuzz RPC."
115
+ **Body:** What is changing and why. Include context, decisions, and reasoning not visible in the code itself.
116
+
117
+ ## Agentic Review-Fix Loop (Grep Loop)
118
+
119
+ This is an auto-research-style loop for code review, specifically useful when a PR is small and you want an agent to repeatedly fix review feedback until tests pass and the PR is merge-ready.
120
+
121
+ 1. Create a small PR.
122
+ 2. Let a review tool, AI reviewer, or human inspect it.
123
+ 3. Feed the review back to the coding agent.
124
+ 4. Agent fixes the feedback.
125
+ 5. Review again.
126
+ 6. Repeat until the PR is clean and tests pass.
127
+
128
+ ### Review-Fix Prompt
129
+
130
+ ```md
131
+ Run a review-fix loop for this PR.
132
+
133
+ Inputs:
134
+ - Current branch: <branch-name>
135
+ - Review feedback: <paste feedback or point to reviewer output>
136
+ - Required end state: tests pass, reviewer issues resolved, no unrelated rewrites.
137
+
138
+ Rules:
139
+ 1. Read the PR diff first.
140
+ 2. Read the review feedback.
141
+ 3. Fix only issues that are real and relevant to this PR.
142
+ 4. Add or update tests for each bug fix when possible.
143
+ 5. Run the relevant tests/typechecks.
144
+ 6. Commit/push the fix if this workflow is allowed to push.
145
+ 7. Stop only when the PR is clean or when blocked by a decision that needs a human.
146
+ ```
147
+
148
+ ### Pre-Flight Check
149
+
150
+ Before starting the loop, ask: "Is this PR too large for a reliable review loop? If yes, suggest how to split it." If the answer is yes, split the PR first.
151
+
152
+ ### Human Guardrails & Pitfalls
153
+
154
+ - **Thousands of lines in one PR:** The reviewer and coding agent both lose accuracy. Split it.
155
+ - **No tests:** The loop needs objective checks, not just vibes.
156
+ - **Blindly accepting every comment:** Some comments are wrong or irrelevant.
157
+ - **Over-fixing:** Agents can rewrite unrelated code. Fix only what was reviewed.
158
+ - **False security:** A clean review is not proof the product is valuable; it only means this diff looks clean.
159
+
160
+ ## The Review Checklist
161
+
162
+ ```markdown
163
+ ## Review: [PR/Change title]
164
+
165
+ ### Context
166
+ - [ ] I understand what this change does and why
167
+
168
+ ### Correctness
169
+ - [ ] Change matches spec/task requirements
170
+ - [ ] Edge cases handled
171
+ - [ ] Error paths handled
172
+ - [ ] Tests cover the change adequately
173
+
174
+ ### Readability
175
+ - [ ] Names are clear and consistent
176
+ - [ ] Logic is straightforward
177
+ - [ ] No unnecessary complexity
178
+
179
+ ### Architecture
180
+ - [ ] Follows existing patterns
181
+ - [ ] No unnecessary coupling or dependencies
182
+ - [ ] Appropriate abstraction level
183
+
184
+ ### Security
185
+ - [ ] No secrets in code
186
+ - [ ] Input validated at boundaries
187
+ - [ ] No injection vulnerabilities
188
+ - [ ] Auth checks in place
189
+ - [ ] External data sources treated as untrusted
190
+
191
+ ### Performance
192
+ - [ ] No N+1 patterns
193
+ - [ ] No unbounded operations
194
+ - [ ] Pagination on list endpoints
195
+
196
+ ### Verification
197
+ - [ ] Tests pass
198
+ - [ ] Build succeeds
199
+ - [ ] Manual verification done (if applicable)
200
+
201
+ ### Verdict
202
+ - [ ] **Approve** — Ready to merge
203
+ - [ ] **Request changes** — Issues must be addressed
204
+ ```
205
+
206
+ ## Common Rationalizations
207
+
208
+ | Rationalization | Reality |
209
+ |---|---|
210
+ | "It works, that's good enough" | Working code that's unreadable, insecure, or architecturally wrong creates debt that compounds. |
211
+ | "I wrote it, so I know it's correct" | Authors are blind to their own assumptions. Every change benefits from another set of eyes. |
212
+ | "We'll clean it up later" | Later never comes. The review is the quality gate — use it. |
213
+ | "AI-generated code is probably fine" | AI code needs more scrutiny, not less. It's confident and plausible, even when wrong. |
214
+
215
+ ## Red Flags
216
+
217
+ - PRs merged without any review.
218
+ - "LGTM" without evidence of actual review.
219
+ - Security-sensitive changes without security-focused review.
220
+ - Large PRs that are "too big to review properly" (split them).
221
+ - Review comments without severity labels.
222
+
223
+ ## Verification
224
+
225
+ After completing the skill, confirm:
226
+ - [ ] All Critical issues are identified and addressed.
227
+ - [ ] The review follows the five-axis framework.
228
+ - [ ] The output follows the standard checklist template.
@@ -0,0 +1,352 @@
1
+ ---
2
+ name: code-simplification
3
+ description: Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend than it should be. Use when reviewing code that has accumulated unnecessary complexity.
4
+ hints:
5
+ - Separate refactoring/simplification from feature implementation; never mix the two in a single PR.
6
+ - Apply Chesterton's Fence: understand why the original code was written before simplifying it.
7
+ - Prioritize comprehension speed and readability over clever tricks or extreme line count reduction.
8
+ - Verify every simplification step immediately by running the unit test suite or the build system.
9
+ - Review openSrc/ or existing patterns for idiomatic simplification examples in the target language.
10
+ ---
11
+
12
+ # Code Simplification
13
+
14
+ > Inspired by the [Claude Code Simplifier plugin](https://github.com/anthropics/claude-plugins-official/blob/main/plugins/code-simplifier/agents/code-simplifier.md). Adapted here as a model-agnostic, process-driven skill for any AI coding agent.
15
+
16
+ ## Overview
17
+
18
+ Simplify code by reducing complexity while preserving exact behavior. The goal is not fewer lines — it's code that is easier to read, understand, modify, and debug. Every simplification must pass a simple test: "Would a new team member understand this faster than the original?"
19
+
20
+ ## When to Use
21
+
22
+ - After a feature is working and tests pass, but the implementation feels heavier than it needs to be
23
+ - During code review when readability or complexity issues are flagged
24
+ - When you encounter deeply nested logic, long functions, or unclear names
25
+ - When refactoring code written under time pressure
26
+ - When consolidating related logic scattered across files
27
+ - After merging changes that introduced duplication or inconsistency
28
+
29
+ **When NOT to use:**
30
+
31
+ - Code is already clean and readable — don't simplify for the sake of it
32
+ - You don't understand what the code does yet — comprehend before you simplify
33
+ - The code is performance-critical and the "simpler" version would be measurably slower
34
+ - You're about to rewrite the module entirely — simplifying throwaway code wastes effort
35
+
36
+ ## The Five Principles
37
+
38
+ ### 1. Preserve Behavior Exactly
39
+
40
+ Don't change what the code does — only how it expresses it. All inputs, outputs, side effects, error behavior, and edge cases must remain identical. If you're not sure a simplification preserves behavior, don't make it.
41
+
42
+ ```
43
+ ASK BEFORE EVERY CHANGE:
44
+ → Does this produce the same output for every input?
45
+ → Does this maintain the same error behavior?
46
+ → Does this preserve the same side effects and ordering?
47
+ → Do all existing tests still pass without modification?
48
+ ```
49
+
50
+ ### 2. Follow Project Conventions
51
+
52
+ Simplification means making code more consistent with the codebase, not imposing external preferences. Before simplifying:
53
+
54
+ ```
55
+ 1. Read CLAUDE.md / project conventions
56
+ 2. Study how neighboring code handles similar patterns
57
+ 3. Match the project's style for:
58
+ - Import ordering and module system
59
+ - Function declaration style
60
+ - Naming conventions
61
+ - Error handling patterns
62
+ - Type annotation depth
63
+ ```
64
+
65
+ Simplification that breaks project consistency is not simplification — it's churn.
66
+
67
+ ### 3. Prefer Clarity Over Cleverness
68
+
69
+ Explicit code is better than compact code when the compact version requires a mental pause to parse.
70
+
71
+ ```typescript
72
+ // UNCLEAR: Dense ternary chain
73
+ const label = isNew ? 'New' : isUpdated ? 'Updated' : isArchived ? 'Archived' : 'Active';
74
+
75
+ // CLEAR: Readable mapping
76
+ function getStatusLabel(item: Item): string {
77
+ if (item.isNew) return 'New';
78
+ if (item.isUpdated) return 'Updated';
79
+ if (item.isArchived) return 'Archived';
80
+ return 'Active';
81
+ }
82
+ ```
83
+
84
+ ```typescript
85
+ // UNCLEAR: Chained reduces with inline logic
86
+ const result = items.reduce((acc, item) => ({
87
+ ...acc,
88
+ [item.id]: { ...acc[item.id], count: (acc[item.id]?.count ?? 0) + 1 }
89
+ }), {});
90
+
91
+ // CLEAR: Named intermediate step
92
+ const countById = new Map<string, number>();
93
+ for (const item of items) {
94
+ countById.set(item.id, (countById.get(item.id) ?? 0) + 1);
95
+ }
96
+ ```
97
+
98
+ ### 4. Maintain Balance
99
+
100
+ Simplification has a failure mode: over-simplification. Watch for these traps:
101
+
102
+ - **Inlining too aggressively** — removing a helper that gave a concept a name makes the call site harder to read
103
+ - **Combining unrelated logic** — two simple functions merged into one complex function is not simpler
104
+ - **Removing "unnecessary" abstraction** — some abstractions exist for extensibility or testability, not complexity
105
+ - **Optimizing for line count** — fewer lines is not the goal; easier comprehension is
106
+
107
+ ### 5. Scope to What Changed
108
+
109
+ Default to simplifying recently modified code. Avoid drive-by refactors of unrelated code unless explicitly asked to broaden scope. Unscoped simplification creates noise in diffs and risks unintended regressions.
110
+
111
+ ## The Simplification Process
112
+
113
+ ### Step 1: Understand Before Touching (Chesterton's Fence)
114
+
115
+ Before changing or removing anything, understand why it exists. This is Chesterton's Fence: if you see a fence across a road and don't understand why it's there, don't tear it down. First understand the reason, then decide if the reason still applies.
116
+
117
+ ```
118
+ BEFORE SIMPLIFYING, ANSWER:
119
+ - What is this code's responsibility?
120
+ - What calls it? What does it call?
121
+ - What are the edge cases and error paths?
122
+ - Are there tests that define the expected behavior?
123
+ - Why might it have been written this way? (Performance? Platform constraint? Historical reason?)
124
+ - Check git blame: what was the original context for this code?
125
+ ```
126
+
127
+ If you can't answer these, you're not ready to simplify. Read more context first.
128
+
129
+ ### Step 2: Identify Simplification Opportunities
130
+
131
+ Scan for these patterns — each one is a concrete signal, not a vague smell:
132
+
133
+ **Structural complexity:**
134
+
135
+ | Pattern | Signal | Simplification |
136
+ |---------|--------|----------------|
137
+ | Deep nesting (3+ levels) | Hard to follow control flow | Extract conditions into guard clauses or helper functions |
138
+ | Long functions (50+ lines) | Multiple responsibilities | Split into focused functions with descriptive names |
139
+ | Nested ternaries | Requires mental stack to parse | Replace with if/else chains, switch, or lookup objects |
140
+ | Boolean parameter flags | `doThing(true, false, true)` | Replace with options objects or separate functions |
141
+ | Repeated conditionals | Same `if` check in multiple places | Extract to a well-named predicate function |
142
+
143
+ **Naming and readability:**
144
+
145
+ | Pattern | Signal | Simplification |
146
+ |---------|--------|----------------|
147
+ | Generic names | `data`, `result`, `temp`, `val`, `item` | Rename to describe the content: `userProfile`, `validationErrors` |
148
+ | Abbreviated names | `usr`, `cfg`, `btn`, `evt` | Use full words unless the abbreviation is universal (`id`, `url`, `api`) |
149
+ | Misleading names | Function named `get` that also mutates state | Rename to reflect actual behavior |
150
+ | Comments explaining "what" | `// increment counter` above `count++` | Delete the comment — the code is clear enough |
151
+ | Comments explaining "why" | `// Retry because the API is flaky under load` | Keep these — they carry intent the code can't express |
152
+
153
+ **Redundancy:**
154
+
155
+ | Pattern | Signal | Simplification |
156
+ |---------|--------|----------------|
157
+ | Duplicated logic | Same 5+ lines in multiple places | Extract to a shared function |
158
+ | Dead code | Unreachable branches, unused variables, commented-out blocks | Remove (after confirming it's truly dead) |
159
+ | Unnecessary abstractions | Wrapper that adds no value | Inline the wrapper, call the underlying function directly |
160
+ | Over-engineered patterns | Factory-for-a-factory, strategy-with-one-strategy | Replace with the simple direct approach |
161
+ | Redundant type assertions | Casting to a type that's already inferred | Remove the assertion |
162
+
163
+ ### Step 3: Apply Changes Incrementally
164
+
165
+ Make one simplification at a time. Run tests after each change. **Submit refactoring changes separately from feature or bug fix changes.** A PR that refactors and adds a feature is two PRs — split them.
166
+
167
+ ```
168
+ FOR EACH SIMPLIFICATION:
169
+ 1. Make the change
170
+ 2. Run the test suite
171
+ 3. If tests pass → commit (or continue to next simplification)
172
+ 4. If tests fail → revert and reconsider
173
+ ```
174
+
175
+ Avoid batching multiple simplifications into a single untested change. If something breaks, you need to know which simplification caused it.
176
+
177
+ **The Rule of 500:** If a refactoring would touch more than 500 lines, invest in automation (codemods, sed scripts, AST transforms) rather than making the changes by hand. Manual edits at that scale are error-prone and exhausting to review.
178
+
179
+ ### Step 4: Verify the Result
180
+
181
+ After all simplifications, step back and evaluate the whole:
182
+
183
+ ```
184
+ COMPARE BEFORE AND AFTER:
185
+ - Is the simplified version genuinely easier to understand?
186
+ - Did you introduce any new patterns inconsistent with the codebase?
187
+ - Is the diff clean and reviewable?
188
+ - Would a teammate approve this change?
189
+ ```
190
+
191
+ If the "simplified" version is harder to understand or review, revert. Not every simplification attempt succeeds.
192
+
193
+ ## Language-Specific Guidance
194
+
195
+ ### TypeScript / JavaScript
196
+
197
+ ```typescript
198
+ // SIMPLIFY: Unnecessary async wrapper
199
+ // Before
200
+ async function getUser(id: string): Promise<User> {
201
+ return await userService.findById(id);
202
+ }
203
+ // After
204
+ function getUser(id: string): Promise<User> {
205
+ return userService.findById(id);
206
+ }
207
+
208
+ // SIMPLIFY: Verbose conditional assignment
209
+ // Before
210
+ let displayName: string;
211
+ if (user.nickname) {
212
+ displayName = user.nickname;
213
+ } else {
214
+ displayName = user.fullName;
215
+ }
216
+ // After
217
+ const displayName = user.nickname || user.fullName;
218
+
219
+ // SIMPLIFY: Manual array building
220
+ // Before
221
+ const activeUsers: User[] = [];
222
+ for (const user of users) {
223
+ if (user.isActive) {
224
+ activeUsers.push(user);
225
+ }
226
+ }
227
+ // After
228
+ const activeUsers = users.filter((user) => user.isActive);
229
+
230
+ // SIMPLIFY: Redundant boolean return
231
+ // Before
232
+ function isValid(input: string): boolean {
233
+ if (input.length > 0 && input.length < 100) {
234
+ return true;
235
+ }
236
+ return false;
237
+ }
238
+ // After
239
+ function isValid(input: string): boolean {
240
+ return input.length > 0 && input.length < 100;
241
+ }
242
+ ```
243
+
244
+ ### Python
245
+
246
+ ```python
247
+ # SIMPLIFY: Verbose dictionary building
248
+ # Before
249
+ result = {}
250
+ for item in items:
251
+ result[item.id] = item.name
252
+ # After
253
+ result = {item.id: item.name for item in items}
254
+
255
+ # SIMPLIFY: Nested conditionals with early return
256
+ # Before
257
+ def process(data):
258
+ if data is not None:
259
+ if data.is_valid():
260
+ if data.has_permission():
261
+ return do_work(data)
262
+ else:
263
+ raise PermissionError("No permission")
264
+ else:
265
+ raise ValueError("Invalid data")
266
+ else:
267
+ raise TypeError("Data is None")
268
+ # After
269
+ def process(data):
270
+ if data is None:
271
+ raise TypeError("Data is None")
272
+ if not data.is_valid():
273
+ raise ValueError("Invalid data")
274
+ if not data.has_permission():
275
+ raise PermissionError("No permission")
276
+ return do_work(data)
277
+ ```
278
+
279
+ ### React / JSX
280
+
281
+ ```tsx
282
+ // SIMPLIFY: Verbose conditional rendering
283
+ // Before
284
+ function UserBadge({ user }: Props) {
285
+ if (user.isAdmin) {
286
+ return <Badge variant="admin">Admin</Badge>;
287
+ } else {
288
+ return <Badge variant="default">User</Badge>;
289
+ }
290
+ }
291
+ // After
292
+ function UserBadge({ user }: Props) {
293
+ const variant = user.isAdmin ? 'admin' : 'default';
294
+ const label = user.isAdmin ? 'Admin' : 'User';
295
+ return <Badge variant={variant}>{label}</Badge>;
296
+ }
297
+
298
+ // SIMPLIFY: Prop drilling through intermediate components
299
+ // Before — consider whether context or composition solves this better.
300
+ // This is a judgment call — flag it, don't auto-refactor.
301
+ ```
302
+
303
+ ## Common Rationalizations
304
+
305
+ | Rationalization | Reality |
306
+ |---|---|
307
+ | "It's working, no need to touch it" | Working code that's hard to read will be hard to fix when it breaks. Simplifying now saves time on every future change. |
308
+ | "Fewer lines is always simpler" | A 1-line nested ternary is not simpler than a 5-line if/else. Simplicity is about comprehension speed, not line count. |
309
+ | "I'll just quickly simplify this unrelated code too" | Unscoped simplification creates noisy diffs and risks regressions in code you didn't intend to change. Stay focused. |
310
+ | "The types make it self-documenting" | Types document structure, not intent. A well-named function explains *why* better than a type signature explains *what*. |
311
+ | "This abstraction might be useful later" | Don't preserve speculative abstractions. If it's not used now, it's complexity without value. Remove it and re-add when needed. |
312
+ | "The original author must have had a reason" | Maybe. Check git blame — apply Chesterton's Fence. But accumulated complexity often has no reason; it's just the residue of iteration under pressure. |
313
+ | "I'll refactor while adding this feature" | Separate refactoring from feature work. Mixed changes are harder to review, revert, and understand in history. |
314
+
315
+ ## Red Flags
316
+
317
+ - Simplification that requires modifying tests to pass (you likely changed behavior)
318
+ - "Simplified" code that is longer and harder to follow than the original
319
+ - Renaming things to match your preferences rather than project conventions
320
+ - Removing error handling because "it makes the code cleaner"
321
+ - Simplifying code you don't fully understand
322
+ - Batching many simplifications into one large, hard-to-review commit
323
+ - Refactoring code outside the scope of the current task without being asked
324
+
325
+ ## Required Checks
326
+
327
+ After completing a simplification pass:
328
+
329
+ - [ ] All existing tests pass without modification
330
+ - [ ] Build succeeds with no new warnings
331
+ - [ ] Linter/formatter passes (no style regressions)
332
+ - [ ] Each simplification is a reviewable, incremental change
333
+ - [ ] The diff is clean — no unrelated changes mixed in
334
+ - [ ] Simplified code follows project conventions (checked against CLAUDE.md or equivalent)
335
+ - [ ] No error handling was removed or weakened
336
+ - [ ] No dead code was left behind (unused imports, unreachable branches)
337
+ - [ ] A teammate or review agent would approve the change as a net improvement
338
+
339
+ ## Workflow
340
+
341
+ 1. **Locate Complex Code:** Identify code with high cyclomatic complexity, deep nesting, vague naming, or redundant logic.
342
+ 2. **Apply Chesterton's Fence:** Read git history or docstrings to understand why the current complexity exists before modifying it.
343
+ 3. **Refactor Incrementally:** Break down refactoring into micro-steps (e.g. invert if-statements to return early, extract sub-functions, rename variables).
344
+ 4. **Compile and Test:** Run compile and test suites after each micro-step to ensure behavior is fully preserved.
345
+ 5. **Review and Polish:** Compare readability before/after; ensure naming and formatting align with project style.
346
+
347
+ ## Verification
348
+
349
+ After executing this skill, confirm:
350
+ - [ ] All unit tests pass successfully without modifying test code.
351
+ - [ ] Readability has measurably improved (verified by visual inspection).
352
+ - [ ] No behavioral side-effects or functional regressions were introduced.