opencode-agent-orchestration-kit 1.0.27

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 (236) hide show
  1. package/.github/CODEOWNERS +1 -0
  2. package/.github/ISSUE_TEMPLATE/bug_report.yml +65 -0
  3. package/.github/ISSUE_TEMPLATE/config.yml +11 -0
  4. package/.github/ISSUE_TEMPLATE/documentation.yml +22 -0
  5. package/.github/ISSUE_TEMPLATE/feature_request.yml +43 -0
  6. package/.github/PULL_REQUEST_TEMPLATE.md +25 -0
  7. package/.github/workflows/check.yml +47 -0
  8. package/CODE_OF_CONDUCT.md +24 -0
  9. package/CONTRIBUTING.md +52 -0
  10. package/LICENSE +201 -0
  11. package/NOTICE.md +23 -0
  12. package/README.md +806 -0
  13. package/SECURITY.md +17 -0
  14. package/docker/open-design/.env.example +6 -0
  15. package/docker/open-design/Dockerfile +50 -0
  16. package/docker/open-design/docker-compose.yml +18 -0
  17. package/docker/open-design/opencode-od/agents/od-worker.md +22 -0
  18. package/docker/open-design/opencode-od/opencode.json +24 -0
  19. package/docs/agents.md +21 -0
  20. package/docs/commands.md +16 -0
  21. package/docs/configuration.md +30 -0
  22. package/docs/docker-open-design.md +42 -0
  23. package/docs/impeccable.md +18 -0
  24. package/docs/installation.md +176 -0
  25. package/docs/models.md +17 -0
  26. package/docs/open-design.md +25 -0
  27. package/docs/quickstart.md +74 -0
  28. package/docs/releases/v1.0.10.md +46 -0
  29. package/docs/releases/v1.0.14.md +39 -0
  30. package/docs/releases/v1.0.27.md +66 -0
  31. package/docs/security.md +8 -0
  32. package/docs/superpowers/plans/2026-07-20-safe-installation-lifecycle.md +779 -0
  33. package/docs/superpowers/plans/2026-07-20-version-identity-and-releases.md +590 -0
  34. package/docs/superpowers/specs/2026-07-20-safe-installation-lifecycle-design.md +1350 -0
  35. package/docs/superpowers/specs/2026-07-20-version-identity-and-releases-design.md +557 -0
  36. package/docs/superpowers.md +34 -0
  37. package/docs/synology.md +30 -0
  38. package/docs/troubleshooting.md +54 -0
  39. package/docs/workflows.md +44 -0
  40. package/doctor.sh +5 -0
  41. package/env.example +15 -0
  42. package/install.sh +5 -0
  43. package/opencode/AGENTS.md +104 -0
  44. package/opencode/agents/debugger.md +41 -0
  45. package/opencode/agents/designer.md +93 -0
  46. package/opencode/agents/developer.md +180 -0
  47. package/opencode/agents/evaluator.md +35 -0
  48. package/opencode/agents/evolver.md +31 -0
  49. package/opencode/agents/lead.md +251 -0
  50. package/opencode/agents/researcher.md +76 -0
  51. package/opencode/agents/review_api.md +34 -0
  52. package/opencode/agents/review_coordinator.md +111 -0
  53. package/opencode/agents/review_quality.md +35 -0
  54. package/opencode/agents/review_security.md +35 -0
  55. package/opencode/agents/review_tests.md +37 -0
  56. package/opencode/agents/reviewer.md +116 -0
  57. package/opencode/agents/scoper.md +75 -0
  58. package/opencode/agents/specifier.md +116 -0
  59. package/opencode/commands/code-simplify.md +36 -0
  60. package/opencode/commands/design.md +27 -0
  61. package/opencode/commands/evolve.md +165 -0
  62. package/opencode/commands/feature.md +67 -0
  63. package/opencode/commands/implement.md +11 -0
  64. package/opencode/commands/init.md +34 -0
  65. package/opencode/commands/loop.md +145 -0
  66. package/opencode/commands/mvp-spec.md +20 -0
  67. package/opencode/commands/plan.md +74 -0
  68. package/opencode/commands/research.md +12 -0
  69. package/opencode/commands/review-orchestrated.md +47 -0
  70. package/opencode/commands/review-preflight.md +26 -0
  71. package/opencode/commands/review.md +18 -0
  72. package/opencode/commands/scope.md +36 -0
  73. package/opencode/commands/spec.md +12 -0
  74. package/opencode/commands/test.md +40 -0
  75. package/opencode/docs/ai/evolution/README.md +135 -0
  76. package/opencode/docs/ai/evolution/benchmarks/manual-scenarios.md +123 -0
  77. package/opencode/docs/ai/evolution/benchmarks/router-scenarios.jsonl +8 -0
  78. package/opencode/docs/ai/evolution/evolution_history.md +83 -0
  79. package/opencode/docs/ai/evolution/mechanisms.jsonl +7 -0
  80. package/opencode/docs/ai/evolution/rejected_mechanisms.jsonl +2 -0
  81. package/opencode/docs/ai/evolution/runs/README.md +15 -0
  82. package/opencode/docs/ai/evolution/runs/iteration-001-sidecar/analysis/overview.md +12 -0
  83. package/opencode/docs/ai/evolution/runs/iteration-001-sidecar/change_evaluation.json +108 -0
  84. package/opencode/docs/ai/evolution/runs/iteration-001-sidecar/change_manifest.json +52 -0
  85. package/opencode/docs/ai/evolution/runs/iteration-001-sidecar/evaluation.md +19 -0
  86. package/opencode/docs/ai/evolution/runs/iteration-001-sidecar/post_evaluation.md +12 -0
  87. package/opencode/docs/ai/evolution/runs/iteration-002-feature-flow-fix/analysis/overview.md +7 -0
  88. package/opencode/docs/ai/evolution/runs/iteration-002-feature-flow-fix/change_evaluation.json +31 -0
  89. package/opencode/docs/ai/evolution/runs/iteration-002-feature-flow-fix/evaluation.md +19 -0
  90. package/opencode/docs/ai/evolution/runs/iteration-003-agent-readable-harness/analysis/overview.md +13 -0
  91. package/opencode/docs/ai/evolution/runs/iteration-003-agent-readable-harness/change_evaluation.json +66 -0
  92. package/opencode/docs/ai/evolution/runs/iteration-003-agent-readable-harness/change_manifest.json +82 -0
  93. package/opencode/docs/ai/evolution/runs/iteration-003-agent-readable-harness/evaluation.md +20 -0
  94. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/detail/ahe-run-lifecycle-validator.md +40 -0
  95. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/detail/evolve-evaluation-only-contract.md +15 -0
  96. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/detail/open-design-tool-contract.md +14 -0
  97. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/detail/slash-command-contract-coverage.md +40 -0
  98. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/overview.md +17 -0
  99. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/analysis/pre_apply_approval.md +15 -0
  100. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/change_evaluation.json +252 -0
  101. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/change_manifest.json +210 -0
  102. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/evaluation.md +25 -0
  103. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/post_apply_evaluation.md +15 -0
  104. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/post_manifest_evaluation.md +14 -0
  105. package/opencode/docs/ai/evolution/runs/iteration-004-orchestration-audit/pre_apply_evaluation.md +15 -0
  106. package/opencode/docs/ai/evolution/runs/iteration-005-harness-orchestration-audit/analysis/overview.md +13 -0
  107. package/opencode/docs/ai/evolution/runs/iteration-005-harness-orchestration-audit/change_evaluation.json +14 -0
  108. package/opencode/docs/ai/evolution/runs/iteration-005-harness-orchestration-audit/change_manifest.json +30 -0
  109. package/opencode/docs/ai/evolution/runs/iteration-005-harness-orchestration-audit/evaluation.md +25 -0
  110. package/opencode/docs/ai/evolution/runs/iteration-006-lead-delegation-audit/analysis/overview.md +13 -0
  111. package/opencode/docs/ai/evolution/runs/iteration-006-lead-delegation-audit/change_evaluation.json +14 -0
  112. package/opencode/docs/ai/evolution/runs/iteration-006-lead-delegation-audit/change_manifest.json +29 -0
  113. package/opencode/docs/ai/evolution/runs/iteration-006-lead-delegation-audit/evaluation.md +18 -0
  114. package/opencode/docs/ai/evolution/runs/iteration-007-agent-skills-integration/analysis/overview.md +13 -0
  115. package/opencode/docs/ai/evolution/runs/iteration-007-agent-skills-integration/change_evaluation.json +14 -0
  116. package/opencode/docs/ai/evolution/runs/iteration-007-agent-skills-integration/change_manifest.json +34 -0
  117. package/opencode/docs/ai/evolution/runs/iteration-007-agent-skills-integration/evaluation.md +17 -0
  118. package/opencode/docs/ai/evolution/runs/iteration-008-lead-readonly-shell-permissions/analysis/overview.md +13 -0
  119. package/opencode/docs/ai/evolution/runs/iteration-008-lead-readonly-shell-permissions/change_evaluation.json +12 -0
  120. package/opencode/docs/ai/evolution/runs/iteration-008-lead-readonly-shell-permissions/change_manifest.json +28 -0
  121. package/opencode/docs/ai/evolution/runs/iteration-008-lead-readonly-shell-permissions/evaluation.md +17 -0
  122. package/opencode/docs/ai/evolution/runs/iteration-009-lead-developer-ownership-loop/analysis/overview.md +9 -0
  123. package/opencode/docs/ai/evolution/runs/iteration-009-lead-developer-ownership-loop/change_evaluation.json +14 -0
  124. package/opencode/docs/ai/evolution/runs/iteration-009-lead-developer-ownership-loop/change_manifest.json +31 -0
  125. package/opencode/docs/ai/evolution/runs/iteration-009-lead-developer-ownership-loop/evaluation.md +18 -0
  126. package/opencode/docs/ai/evolution/runs/iteration-010-token-plugin-sidebar-content/analysis/overview.md +12 -0
  127. package/opencode/docs/ai/evolution/runs/iteration-010-token-plugin-sidebar-content/change_evaluation.json +14 -0
  128. package/opencode/docs/ai/evolution/runs/iteration-010-token-plugin-sidebar-content/change_manifest.json +31 -0
  129. package/opencode/docs/ai/evolution/runs/iteration-010-token-plugin-sidebar-content/evaluation.md +17 -0
  130. package/opencode/docs/ai/evolution/runs/iteration-011-lead-cd-which-permissions/analysis/overview.md +10 -0
  131. package/opencode/docs/ai/evolution/runs/iteration-011-lead-cd-which-permissions/change_evaluation.json +14 -0
  132. package/opencode/docs/ai/evolution/runs/iteration-011-lead-cd-which-permissions/change_manifest.json +30 -0
  133. package/opencode/docs/ai/evolution/runs/iteration-011-lead-cd-which-permissions/evaluation.md +17 -0
  134. package/opencode/docs/ai/evolution/runs/iteration-012-lead-shell-allowlist-boundaries/analysis/overview.md +25 -0
  135. package/opencode/docs/ai/evolution/runs/iteration-012-lead-shell-allowlist-boundaries/change_evaluation.json +28 -0
  136. package/opencode/docs/ai/evolution/runs/iteration-012-lead-shell-allowlist-boundaries/change_manifest.json +31 -0
  137. package/opencode/docs/ai/evolution/runs/iteration-012-lead-shell-allowlist-boundaries/evaluation.md +22 -0
  138. package/opencode/docs/ai/evolution/runs/iteration-013-doc-gardening-mechanical-checks/analysis/overview.md +27 -0
  139. package/opencode/docs/ai/evolution/runs/iteration-013-doc-gardening-mechanical-checks/change_evaluation.json +32 -0
  140. package/opencode/docs/ai/evolution/runs/iteration-013-doc-gardening-mechanical-checks/change_manifest.json +49 -0
  141. package/opencode/docs/ai/evolution/runs/iteration-013-doc-gardening-mechanical-checks/evaluation.md +92 -0
  142. package/opencode/docs/ai/evolution/runs/iteration-014-harness-baseline/analysis/detail/token-vs-semantic.md +31 -0
  143. package/opencode/docs/ai/evolution/runs/iteration-014-harness-baseline/analysis/overview.md +14 -0
  144. package/opencode/docs/ai/evolution/runs/iteration-014-harness-baseline/evaluation.md +36 -0
  145. package/opencode/docs/ai/evolution/runs/iteration-015-semantic-checker/analysis/overview.md +13 -0
  146. package/opencode/docs/ai/evolution/runs/iteration-015-semantic-checker/change_evaluation.json +31 -0
  147. package/opencode/docs/ai/evolution/runs/iteration-015-semantic-checker/change_manifest.json +47 -0
  148. package/opencode/docs/ai/evolution/runs/iteration-015-semantic-checker/evaluation.md +27 -0
  149. package/opencode/docs/ai/evolution/runs/iteration-016-contract-prompt-alignment/analysis/overview.md +32 -0
  150. package/opencode/docs/ai/evolution/runs/iteration-016-contract-prompt-alignment/change_evaluation.json +31 -0
  151. package/opencode/docs/ai/evolution/runs/iteration-016-contract-prompt-alignment/change_manifest.json +35 -0
  152. package/opencode/docs/ai/evolution/runs/iteration-016-contract-prompt-alignment/evaluation.md +31 -0
  153. package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/analysis/detail/pattern-1-feature-sidecar-false-positive.md +51 -0
  154. package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/analysis/detail/pattern-2-checker-time-budget.md +52 -0
  155. package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/analysis/overview.md +99 -0
  156. package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/change_evaluation.json +61 -0
  157. package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/change_manifest.json +61 -0
  158. package/opencode/docs/ai/evolution/runs/iteration-017-ahe-cycle/evaluation.md +448 -0
  159. package/opencode/docs/ai/evolution/runs/iteration-018-free-message-routing-audit/analysis/detail/intake-gray-zone.md +65 -0
  160. package/opencode/docs/ai/evolution/runs/iteration-018-free-message-routing-audit/analysis/overview.md +172 -0
  161. package/opencode/docs/ai/evolution/runs/iteration-018-free-message-routing-audit/evaluation.md +226 -0
  162. package/opencode/docs/ai/evolution/runs/iteration-019-handoff-routing-audit/analysis/detail/plan-only-gray-zone.md +62 -0
  163. package/opencode/docs/ai/evolution/runs/iteration-019-handoff-routing-audit/analysis/overview.md +167 -0
  164. package/opencode/docs/ai/evolution/runs/iteration-019-handoff-routing-audit/evaluation.md +163 -0
  165. package/opencode/docs/ai/evolution/runs/iteration-020-loop-engineering-command/analysis/overview.md +42 -0
  166. package/opencode/docs/ai/evolution/runs/iteration-020-loop-engineering-command/change_evaluation.json +46 -0
  167. package/opencode/docs/ai/evolution/runs/iteration-020-loop-engineering-command/change_manifest.json +57 -0
  168. package/opencode/docs/ai/evolution/runs/iteration-020-loop-engineering-command/evaluation.md +48 -0
  169. package/opencode/docs/ai/evolution/runs/iteration-021/analysis/detail/contract-vs-runtime-gap.md +163 -0
  170. package/opencode/docs/ai/evolution/runs/iteration-021/analysis/detail/evidence-collection-blocker.md +134 -0
  171. package/opencode/docs/ai/evolution/runs/iteration-021/analysis/overview.md +111 -0
  172. package/opencode/docs/ai/evolution/runs/iteration-021/change_evaluation.json +52 -0
  173. package/opencode/docs/ai/evolution/runs/iteration-021/change_manifest.json +50 -0
  174. package/opencode/docs/ai/evolution/runs/iteration-021/evaluation.md +46 -0
  175. package/opencode/docs/ai/evolution/runs/iteration-021/manifest-justification.md +48 -0
  176. package/opencode/docs/ai/evolution/session-sources.md +91 -0
  177. package/opencode/docs/ai/harness/README.md +32 -0
  178. package/opencode/docs/ai/harness/agents.md +148 -0
  179. package/opencode/docs/ai/harness/checks.md +119 -0
  180. package/opencode/docs/ai/harness/commands.md +391 -0
  181. package/opencode/docs/ai/harness/evidence.md +85 -0
  182. package/opencode/docs/ai/harness/init-detection-rules.md +160 -0
  183. package/opencode/docs/ai/harness/orchestrated-review.md +131 -0
  184. package/opencode/docs/ai/harness/skill-metadata-schema.md +198 -0
  185. package/opencode/docs/ai/harness/skill-resolution.md +202 -0
  186. package/opencode/docs/ai/harness/skill_registry.json +443 -0
  187. package/opencode/docs/ai/harness/skill_registry.md +43 -0
  188. package/opencode/docs/ai/project-context-template.md +53 -0
  189. package/opencode/opencode.json +38 -0
  190. package/opencode/package-lock.json +1717 -0
  191. package/opencode/package.json +11 -0
  192. package/opencode/plugins/token-tree-usage.tsx +206 -0
  193. package/opencode/references/performance-checklist.md +153 -0
  194. package/opencode/references/security-checklist.md +134 -0
  195. package/opencode/references/testing-patterns.md +236 -0
  196. package/opencode/scripts/check-harness.mjs +1572 -0
  197. package/opencode/scripts/check-harness.test.mjs +820 -0
  198. package/opencode/scripts/collect-session-evidence.mjs +612 -0
  199. package/opencode/scripts/collect-session-evidence.test.mjs +443 -0
  200. package/opencode/scripts/preflight-audit.mjs +497 -0
  201. package/opencode/scripts/preflight-audit.test.mjs +363 -0
  202. package/opencode/scripts/project-capability-snapshot.mjs +407 -0
  203. package/opencode/scripts/project-capability-snapshot.test.mjs +382 -0
  204. package/opencode/scripts/review-orchestrated-prepare.mjs +547 -0
  205. package/opencode/scripts/review-orchestrated-prepare.test.mjs +516 -0
  206. package/opencode/scripts/skill-resolver.mjs +585 -0
  207. package/opencode/scripts/skill-resolver.test.mjs +781 -0
  208. package/opencode/scripts/update-skill-registry.mjs +380 -0
  209. package/opencode/skills/api-and-interface-design/SKILL.md +315 -0
  210. package/opencode/skills/autonomous-loops/SKILL.md +312 -0
  211. package/opencode/skills/code-review-and-quality/SKILL.md +365 -0
  212. package/opencode/skills/code-simplification/SKILL.md +345 -0
  213. package/opencode/skills/context-engineering/SKILL.md +252 -0
  214. package/opencode/skills/debugging-and-error-recovery/SKILL.md +316 -0
  215. package/opencode/skills/documentation-and-adrs/SKILL.md +298 -0
  216. package/opencode/skills/doubt-driven-development/SKILL.md +168 -0
  217. package/opencode/skills/iterative-retrieval/SKILL.md +232 -0
  218. package/opencode/skills/open-design/SKILL.md +123 -0
  219. package/opencode/skills/performance-optimization/SKILL.md +365 -0
  220. package/opencode/skills/security-and-hardening/SKILL.md +369 -0
  221. package/opencode/skills/source-driven-development/SKILL.md +210 -0
  222. package/opencode/skills/test-driven-development/SKILL.md +406 -0
  223. package/opencode/skills/using-agent-skills/SKILL.md +194 -0
  224. package/opencode/skills/verification-loop/SKILL.md +162 -0
  225. package/opencode/tools/open_design.ts +361 -0
  226. package/opencode/tui.json +5 -0
  227. package/package.json +20 -0
  228. package/rollback.sh +5 -0
  229. package/scripts/check.sh +184 -0
  230. package/scripts/install-smoke.sh +111 -0
  231. package/scripts/manage-installation.mjs +1498 -0
  232. package/scripts/manage-installation.test.mjs +1936 -0
  233. package/scripts/version.mjs +197 -0
  234. package/scripts/version.test.mjs +195 -0
  235. package/uninstall.sh +5 -0
  236. package/upgrade.sh +5 -0
@@ -0,0 +1,365 @@
1
+ ---
2
+ name: performance-optimization
3
+ description: Optimizes application performance. Use when performance requirements exist, when you suspect performance regressions, or when Core Web Vitals or load times need improvement. Use when profiling reveals bottlenecks that need fixing.
4
+ phase: verify
5
+ domains:
6
+ - performance
7
+ stacks:
8
+ - any
9
+ allowed_agents:
10
+ - developer
11
+ - reviewer
12
+ - lead
13
+ surfaces:
14
+ - profiling
15
+ - optimization
16
+ skill_source: built-in
17
+ origin: null
18
+ status: active
19
+ ---
20
+
21
+ # Performance Optimization
22
+
23
+ ## Overview
24
+
25
+ Measure before optimizing. Performance work without measurement is guessing — and guessing leads to premature optimization that adds complexity without improving what matters. Profile first, identify the actual bottleneck, fix it, measure again. Optimize only what measurements prove matters.
26
+
27
+ ## When to Use
28
+
29
+ - Performance requirements exist in the spec (load time budgets, response time SLAs)
30
+ - Users or monitoring report slow behavior
31
+ - Core Web Vitals scores are below thresholds
32
+ - You suspect a change introduced a regression
33
+ - Building features that handle large datasets or high traffic
34
+
35
+ **When NOT to use:** Don't optimize before you have evidence of a problem. Premature optimization adds complexity that costs more than the performance it gains.
36
+
37
+ ## Core Web Vitals Targets
38
+
39
+ | Metric | Good | Needs Improvement | Poor |
40
+ |--------|------|-------------------|------|
41
+ | **LCP** (Largest Contentful Paint) | ≤ 2.5s | ≤ 4.0s | > 4.0s |
42
+ | **INP** (Interaction to Next Paint) | ≤ 200ms | ≤ 500ms | > 500ms |
43
+ | **CLS** (Cumulative Layout Shift) | ≤ 0.1 | ≤ 0.25 | > 0.25 |
44
+
45
+ ## The Optimization Workflow
46
+
47
+ ```
48
+ 1. MEASURE → Establish baseline with real data
49
+ 2. IDENTIFY → Find the actual bottleneck (not assumed)
50
+ 3. FIX → Address the specific bottleneck
51
+ 4. VERIFY → Measure again, confirm improvement
52
+ 5. GUARD → Add monitoring or tests to prevent regression
53
+ ```
54
+
55
+ ### Step 1: Measure
56
+
57
+ Two complementary approaches — use both:
58
+
59
+ - **Synthetic (Lighthouse, DevTools Performance tab):** Controlled conditions, reproducible. Best for CI regression detection and isolating specific issues.
60
+ - **RUM (web-vitals library, CrUX):** Real user data in real conditions. Required to validate that a fix actually improved user experience.
61
+
62
+ **Frontend:**
63
+ ```bash
64
+ # Synthetic: Lighthouse in Chrome DevTools (or CI)
65
+ # Chrome DevTools → Performance tab → Record
66
+ # Chrome DevTools MCP → Performance trace, if configured
67
+
68
+ # RUM: Web Vitals library in code
69
+ import { onLCP, onINP, onCLS } from 'web-vitals';
70
+
71
+ onLCP(console.log);
72
+ onINP(console.log);
73
+ onCLS(console.log);
74
+ ```
75
+
76
+ **Backend:**
77
+ ```bash
78
+ # Response time logging
79
+ # Application Performance Monitoring (APM)
80
+ # Database query logging with timing
81
+
82
+ # Simple timing
83
+ console.time('db-query');
84
+ const result = await db.query(...);
85
+ console.timeEnd('db-query');
86
+ ```
87
+
88
+ ### Where to Start Measuring
89
+
90
+ Use the symptom to decide what to measure first:
91
+
92
+ ```
93
+ What is slow?
94
+ ├── First page load
95
+ │ ├── Large bundle? --> Measure bundle size, check code splitting
96
+ │ ├── Slow server response? --> Measure TTFB in DevTools Network waterfall
97
+ │ │ ├── DNS long? --> Add dns-prefetch / preconnect for known origins
98
+ │ │ ├── TCP/TLS long? --> Enable HTTP/2, check edge deployment, keep-alive
99
+ │ │ └── Waiting (server) long? --> Profile backend, check queries and caching
100
+ │ └── Render-blocking resources? --> Check network waterfall for CSS/JS blocking
101
+ ├── Interaction feels sluggish
102
+ │ ├── UI freezes on click? --> Profile main thread, look for long tasks (>50ms)
103
+ │ ├── Form input lag? --> Check re-renders, controlled component overhead
104
+ │ └── Animation jank? --> Check layout thrashing, forced reflows
105
+ ├── Page after navigation
106
+ │ ├── Data loading? --> Measure API response times, check for waterfalls
107
+ │ └── Client rendering? --> Profile component render time, check for N+1 fetches
108
+ └── Backend / API
109
+ ├── Single endpoint slow? --> Profile database queries, check indexes
110
+ ├── All endpoints slow? --> Check connection pool, memory, CPU
111
+ └── Intermittent slowness? --> Check for lock contention, GC pauses, external deps
112
+ ```
113
+
114
+ ### Step 2: Identify the Bottleneck
115
+
116
+ Common bottlenecks by category:
117
+
118
+ **Frontend:**
119
+
120
+ | Symptom | Likely Cause | Investigation |
121
+ |---------|-------------|---------------|
122
+ | Slow LCP | Large images, render-blocking resources, slow server | Check network waterfall, image sizes |
123
+ | High CLS | Images without dimensions, late-loading content, font shifts | Check layout shift attribution |
124
+ | Poor INP | Heavy JavaScript on main thread, large DOM updates | Check long tasks in Performance trace |
125
+ | Slow initial load | Large bundle, many network requests | Check bundle size, code splitting |
126
+
127
+ **Backend:**
128
+
129
+ | Symptom | Likely Cause | Investigation |
130
+ |---------|-------------|---------------|
131
+ | Slow API responses | N+1 queries, missing indexes, unoptimized queries | Check database query log |
132
+ | Memory growth | Leaked references, unbounded caches, large payloads | Heap snapshot analysis |
133
+ | CPU spikes | Synchronous heavy computation, regex backtracking | CPU profiling |
134
+ | High latency | Missing caching, redundant computation, network hops | Trace requests through the stack |
135
+
136
+ ### Step 3: Fix Common Anti-Patterns
137
+
138
+ #### N+1 Queries (Backend)
139
+
140
+ ```typescript
141
+ // BAD: N+1 — one query per task for the owner
142
+ const tasks = await db.tasks.findMany();
143
+ for (const task of tasks) {
144
+ task.owner = await db.users.findUnique({ where: { id: task.ownerId } });
145
+ }
146
+
147
+ // GOOD: Single query with join/include
148
+ const tasks = await db.tasks.findMany({
149
+ include: { owner: true },
150
+ });
151
+ ```
152
+
153
+ #### Unbounded Data Fetching
154
+
155
+ ```typescript
156
+ // BAD: Fetching all records
157
+ const allTasks = await db.tasks.findMany();
158
+
159
+ // GOOD: Paginated with limits
160
+ const tasks = await db.tasks.findMany({
161
+ take: 20,
162
+ skip: (page - 1) * 20,
163
+ orderBy: { createdAt: 'desc' },
164
+ });
165
+ ```
166
+
167
+ #### Missing Image Optimization (Frontend)
168
+
169
+ ```html
170
+ <!-- BAD: No dimensions, no format optimization -->
171
+ <img src="/hero.jpg" />
172
+
173
+ <!-- GOOD: Hero / LCP image — art direction + resolution switching, high priority -->
174
+ <!--
175
+ Two techniques combined:
176
+ - Art direction (media): different crop/composition per breakpoint
177
+ - Resolution switching (srcset + sizes): right file size per screen density
178
+ -->
179
+ <picture>
180
+ <!-- Mobile: portrait crop (8:10) -->
181
+ <source
182
+ media="(max-width: 767px)"
183
+ srcset="/hero-mobile-400.avif 400w, /hero-mobile-800.avif 800w"
184
+ sizes="100vw"
185
+ width="800"
186
+ height="1000"
187
+ type="image/avif"
188
+ />
189
+ <source
190
+ media="(max-width: 767px)"
191
+ srcset="/hero-mobile-400.webp 400w, /hero-mobile-800.webp 800w"
192
+ sizes="100vw"
193
+ width="800"
194
+ height="1000"
195
+ type="image/webp"
196
+ />
197
+ <!-- Desktop: landscape crop (2:1) -->
198
+ <source
199
+ srcset="/hero-800.avif 800w, /hero-1200.avif 1200w, /hero-1600.avif 1600w"
200
+ sizes="(max-width: 1200px) 100vw, 1200px"
201
+ width="1200"
202
+ height="600"
203
+ type="image/avif"
204
+ />
205
+ <source
206
+ srcset="/hero-800.webp 800w, /hero-1200.webp 1200w, /hero-1600.webp 1600w"
207
+ sizes="(max-width: 1200px) 100vw, 1200px"
208
+ width="1200"
209
+ height="600"
210
+ type="image/webp"
211
+ />
212
+ <img
213
+ src="/hero-desktop.jpg"
214
+ width="1200"
215
+ height="600"
216
+ fetchpriority="high"
217
+ alt="Hero image description"
218
+ />
219
+ </picture>
220
+
221
+ <!-- GOOD: Below-the-fold image — lazy loaded + async decoding -->
222
+ <img
223
+ src="/content.webp"
224
+ width="800"
225
+ height="400"
226
+ loading="lazy"
227
+ decoding="async"
228
+ alt="Content image description"
229
+ />
230
+ ```
231
+
232
+ #### Unnecessary Re-renders (React)
233
+
234
+ ```tsx
235
+ // BAD: Creates new object on every render, causing children to re-render
236
+ function TaskList() {
237
+ return <TaskFilters options={{ sortBy: 'date', order: 'desc' }} />;
238
+ }
239
+
240
+ // GOOD: Stable reference
241
+ const DEFAULT_OPTIONS = { sortBy: 'date', order: 'desc' } as const;
242
+ function TaskList() {
243
+ return <TaskFilters options={DEFAULT_OPTIONS} />;
244
+ }
245
+
246
+ // Use React.memo for expensive components
247
+ const TaskItem = React.memo(function TaskItem({ task }: Props) {
248
+ return <div>{/* expensive render */}</div>;
249
+ });
250
+
251
+ // Use useMemo for expensive computations
252
+ function TaskStats({ tasks }: Props) {
253
+ const stats = useMemo(() => calculateStats(tasks), [tasks]);
254
+ return <div>{stats.completed} / {stats.total}</div>;
255
+ }
256
+ ```
257
+
258
+ #### Large Bundle Size
259
+
260
+ ```typescript
261
+ // Modern bundlers (Vite, webpack 5+) handle named imports with tree-shaking automatically,
262
+ // provided the dependency ships ESM and is marked `sideEffects: false` in package.json.
263
+ // Profile before changing import styles — the real gains come from splitting and lazy loading.
264
+
265
+ // GOOD: Dynamic import for heavy, rarely-used features
266
+ const ChartLibrary = lazy(() => import('./ChartLibrary'));
267
+
268
+ // GOOD: Route-level code splitting wrapped in Suspense
269
+ const SettingsPage = lazy(() => import('./pages/Settings'));
270
+
271
+ function App() {
272
+ return (
273
+ <Suspense fallback={<Spinner />}>
274
+ <SettingsPage />
275
+ </Suspense>
276
+ );
277
+ }
278
+ ```
279
+
280
+ #### Missing Caching (Backend)
281
+
282
+ ```typescript
283
+ // Cache frequently-read, rarely-changed data
284
+ const CACHE_TTL = 5 * 60 * 1000; // 5 minutes
285
+ let cachedConfig: AppConfig | null = null;
286
+ let cacheExpiry = 0;
287
+
288
+ async function getAppConfig(): Promise<AppConfig> {
289
+ if (cachedConfig && Date.now() < cacheExpiry) {
290
+ return cachedConfig;
291
+ }
292
+ cachedConfig = await db.config.findFirst();
293
+ cacheExpiry = Date.now() + CACHE_TTL;
294
+ return cachedConfig;
295
+ }
296
+
297
+ // HTTP caching headers for static assets
298
+ app.use('/static', express.static('public', {
299
+ maxAge: '1y', // Cache for 1 year
300
+ immutable: true, // Never revalidate (use content hashing in filenames)
301
+ }));
302
+
303
+ // Cache-Control for API responses
304
+ res.set('Cache-Control', 'public, max-age=300'); // 5 minutes
305
+ ```
306
+
307
+ ## Performance Budget
308
+
309
+ Set budgets and enforce them:
310
+
311
+ ```
312
+ JavaScript bundle: < 200KB gzipped (initial load)
313
+ CSS: < 50KB gzipped
314
+ Images: < 200KB per image (above the fold)
315
+ Fonts: < 100KB total
316
+ API response time: < 200ms (p95)
317
+ Time to Interactive: < 3.5s on 4G
318
+ Lighthouse Performance score: ≥ 90
319
+ ```
320
+
321
+ **Enforce in CI:**
322
+ ```bash
323
+ # Bundle size check
324
+ npx bundlesize --config bundlesize.config.json
325
+
326
+ # Lighthouse CI
327
+ npx lhci autorun
328
+ ```
329
+
330
+ ## See Also
331
+
332
+ For detailed performance checklists, optimization commands, and anti-pattern reference, see `references/performance-checklist.md`.
333
+
334
+
335
+ ## Common Rationalizations
336
+
337
+ | Rationalization | Reality |
338
+ |---|---|
339
+ | "We'll optimize later" | Performance debt compounds. Fix obvious anti-patterns now, defer micro-optimizations. |
340
+ | "It's fast on my machine" | Your machine isn't the user's. Profile on representative hardware and networks. |
341
+ | "This optimization is obvious" | If you didn't measure, you don't know. Profile first. |
342
+ | "Users won't notice 100ms" | Research shows 100ms delays impact conversion rates. Users notice more than you think. |
343
+ | "The framework handles performance" | Frameworks prevent some issues but can't fix N+1 queries or oversized bundles. |
344
+
345
+ ## Red Flags
346
+
347
+ - Optimization without profiling data to justify it
348
+ - N+1 query patterns in data fetching
349
+ - List endpoints without pagination
350
+ - Images without dimensions, lazy loading, or responsive sizes
351
+ - Bundle size growing without review
352
+ - No performance monitoring in production
353
+ - `React.memo` and `useMemo` everywhere (overusing is as bad as underusing)
354
+
355
+ ## Verification
356
+
357
+ After any performance-related change:
358
+
359
+ - [ ] Before and after measurements exist (specific numbers)
360
+ - [ ] The specific bottleneck is identified and addressed
361
+ - [ ] Core Web Vitals are within "Good" thresholds
362
+ - [ ] Bundle size hasn't increased significantly
363
+ - [ ] No N+1 queries in new data fetching code
364
+ - [ ] Performance budget passes in CI (if configured)
365
+ - [ ] Existing tests still pass (optimization didn't break behavior)