trinity-method-sdk 2.0.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.
- package/CHANGELOG.md +116 -0
- package/LICENSE +21 -0
- package/README.md +555 -0
- package/dist/cli/commands/deploy/agents.d.ts +14 -0
- package/dist/cli/commands/deploy/agents.js +59 -0
- package/dist/cli/commands/deploy/ci-cd.d.ts +13 -0
- package/dist/cli/commands/deploy/ci-cd.js +50 -0
- package/dist/cli/commands/deploy/claude-setup.d.ts +17 -0
- package/dist/cli/commands/deploy/claude-setup.js +91 -0
- package/dist/cli/commands/deploy/configuration.d.ts +13 -0
- package/dist/cli/commands/deploy/configuration.js +215 -0
- package/dist/cli/commands/deploy/directories.d.ts +12 -0
- package/dist/cli/commands/deploy/directories.js +38 -0
- package/dist/cli/commands/deploy/gitignore.d.ts +12 -0
- package/dist/cli/commands/deploy/gitignore.js +53 -0
- package/dist/cli/commands/deploy/index.d.ts +38 -0
- package/dist/cli/commands/deploy/index.js +156 -0
- package/dist/cli/commands/deploy/knowledge-base.d.ts +16 -0
- package/dist/cli/commands/deploy/knowledge-base.js +75 -0
- package/dist/cli/commands/deploy/linting.d.ts +18 -0
- package/dist/cli/commands/deploy/linting.js +51 -0
- package/dist/cli/commands/deploy/metrics.d.ts +13 -0
- package/dist/cli/commands/deploy/metrics.js +34 -0
- package/dist/cli/commands/deploy/pre-flight.d.ts +13 -0
- package/dist/cli/commands/deploy/pre-flight.js +29 -0
- package/dist/cli/commands/deploy/root-files.d.ts +16 -0
- package/dist/cli/commands/deploy/root-files.js +178 -0
- package/dist/cli/commands/deploy/sdk-install.d.ts +12 -0
- package/dist/cli/commands/deploy/sdk-install.js +57 -0
- package/dist/cli/commands/deploy/summary.d.ts +14 -0
- package/dist/cli/commands/deploy/summary.js +130 -0
- package/dist/cli/commands/deploy/templates.d.ts +14 -0
- package/dist/cli/commands/deploy/templates.js +84 -0
- package/dist/cli/commands/deploy/types.d.ts +39 -0
- package/dist/cli/commands/deploy/types.js +5 -0
- package/dist/cli/commands/update/agents.d.ts +14 -0
- package/dist/cli/commands/update/agents.js +31 -0
- package/dist/cli/commands/update/backup.d.ts +31 -0
- package/dist/cli/commands/update/backup.js +97 -0
- package/dist/cli/commands/update/commands.d.ts +14 -0
- package/dist/cli/commands/update/commands.js +75 -0
- package/dist/cli/commands/update/index.d.ts +15 -0
- package/dist/cli/commands/update/index.js +118 -0
- package/dist/cli/commands/update/knowledge-base.d.ts +14 -0
- package/dist/cli/commands/update/knowledge-base.js +38 -0
- package/dist/cli/commands/update/pre-flight.d.ts +13 -0
- package/dist/cli/commands/update/pre-flight.js +37 -0
- package/dist/cli/commands/update/summary.d.ts +20 -0
- package/dist/cli/commands/update/summary.js +47 -0
- package/dist/cli/commands/update/templates.d.ts +14 -0
- package/dist/cli/commands/update/templates.js +25 -0
- package/dist/cli/commands/update/types.d.ts +13 -0
- package/dist/cli/commands/update/types.js +7 -0
- package/dist/cli/commands/update/utils.d.ts +11 -0
- package/dist/cli/commands/update/utils.js +19 -0
- package/dist/cli/commands/update/verification.d.ts +20 -0
- package/dist/cli/commands/update/verification.js +54 -0
- package/dist/cli/commands/update/version.d.ts +18 -0
- package/dist/cli/commands/update/version.js +36 -0
- package/dist/cli/commands/update.d.ts +7 -0
- package/dist/cli/commands/update.js +7 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.js +36 -0
- package/dist/cli/types.d.ts +77 -0
- package/dist/cli/types.js +5 -0
- package/dist/cli/utils/deploy-ci.d.ts +22 -0
- package/dist/cli/utils/deploy-ci.js +138 -0
- package/dist/cli/utils/deploy-linting.d.ts +3 -0
- package/dist/cli/utils/deploy-linting.js +136 -0
- package/dist/cli/utils/detect-stack.d.ts +3 -0
- package/dist/cli/utils/detect-stack.js +270 -0
- package/dist/cli/utils/error-classes.d.ts +63 -0
- package/dist/cli/utils/error-classes.js +84 -0
- package/dist/cli/utils/error-handler.d.ts +59 -0
- package/dist/cli/utils/error-handler.js +127 -0
- package/dist/cli/utils/errors.d.ts +52 -0
- package/dist/cli/utils/errors.js +102 -0
- package/dist/cli/utils/get-sdk-path.d.ts +18 -0
- package/dist/cli/utils/get-sdk-path.js +31 -0
- package/dist/cli/utils/inject-dependencies.d.ts +2 -0
- package/dist/cli/utils/inject-dependencies.js +55 -0
- package/dist/cli/utils/linting-tools.d.ts +8 -0
- package/dist/cli/utils/linting-tools.js +206 -0
- package/dist/cli/utils/metrics/code-quality.d.ts +32 -0
- package/dist/cli/utils/metrics/code-quality.js +122 -0
- package/dist/cli/utils/metrics/dependency-parser.d.ts +21 -0
- package/dist/cli/utils/metrics/dependency-parser.js +153 -0
- package/dist/cli/utils/metrics/file-complexity.d.ts +26 -0
- package/dist/cli/utils/metrics/file-complexity.js +77 -0
- package/dist/cli/utils/metrics/framework-detector.d.ts +17 -0
- package/dist/cli/utils/metrics/framework-detector.js +120 -0
- package/dist/cli/utils/metrics/git-metrics.d.ts +30 -0
- package/dist/cli/utils/metrics/git-metrics.js +83 -0
- package/dist/cli/utils/metrics/index.d.ts +28 -0
- package/dist/cli/utils/metrics/index.js +100 -0
- package/dist/cli/utils/template-processor.d.ts +10 -0
- package/dist/cli/utils/template-processor.js +188 -0
- package/dist/cli/utils/validate-path.d.ts +80 -0
- package/dist/cli/utils/validate-path.js +180 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +8 -0
- package/dist/templates/agents/aj-team/apo-documentation-specialist.md.template +572 -0
- package/dist/templates/agents/aj-team/bas-quality-gate.md.template +906 -0
- package/dist/templates/agents/aj-team/bon-dependency-manager.md.template +636 -0
- package/dist/templates/agents/aj-team/cap-configuration-specialist.md.template +670 -0
- package/dist/templates/agents/aj-team/dra-code-reviewer.md.template +768 -0
- package/dist/templates/agents/aj-team/kil-task-executor.md.template +764 -0
- package/dist/templates/agents/aj-team/uro-refactoring-specialist.md.template +759 -0
- package/dist/templates/agents/audit/juno-auditor.md.template +447 -0
- package/dist/templates/agents/deployment/ein-cicd.md.template +694 -0
- package/dist/templates/agents/deployment/ino-context.md.template +733 -0
- package/dist/templates/agents/deployment/tan-structure.md.template +661 -0
- package/dist/templates/agents/deployment/zen-knowledge.md.template +451 -0
- package/dist/templates/agents/leadership/aj-cc.md.template +462 -0
- package/dist/templates/agents/leadership/aj-maestro.md.template +943 -0
- package/dist/templates/agents/leadership/aly-cto.md.template +407 -0
- package/dist/templates/agents/planning/eus-decomposer.md.template +496 -0
- package/dist/templates/agents/planning/mon-requirements.md.template +323 -0
- package/dist/templates/agents/planning/ror-design.md.template +465 -0
- package/dist/templates/agents/planning/tra-planner.md.template +432 -0
- package/dist/templates/ci/cd.yml.template +175 -0
- package/dist/templates/ci/ci.yml.template +196 -0
- package/dist/templates/ci/generic-ci.yml +115 -0
- package/dist/templates/ci/github-actions.yml +86 -0
- package/dist/templates/ci/gitlab-ci.yml +103 -0
- package/dist/templates/claude/EMPLOYEE-DIRECTORY.md.template +545 -0
- package/dist/templates/documentation/ROOT-README.md.template +307 -0
- package/dist/templates/documentation/SUBDIRECTORY-README.md.template +261 -0
- package/dist/templates/investigations/bug.md.template +484 -0
- package/dist/templates/investigations/feature.md.template +564 -0
- package/dist/templates/investigations/performance.md.template +625 -0
- package/dist/templates/investigations/security.md.template +714 -0
- package/dist/templates/investigations/technical.md.template +433 -0
- package/dist/templates/knowledge-base/AI-DEVELOPMENT-GUIDE.md.template +957 -0
- package/dist/templates/knowledge-base/ARCHITECTURE.md.template +452 -0
- package/dist/templates/knowledge-base/CODING-PRINCIPLES.md.template +750 -0
- package/dist/templates/knowledge-base/DOCUMENTATION-CRITERIA.md.template +1118 -0
- package/dist/templates/knowledge-base/ISSUES.md.template +539 -0
- package/dist/templates/knowledge-base/TESTING-PRINCIPLES.md.template +894 -0
- package/dist/templates/knowledge-base/Technical-Debt.md.template +640 -0
- package/dist/templates/knowledge-base/To-do.md.template +407 -0
- package/dist/templates/knowledge-base/Trinity.md.template +464 -0
- package/dist/templates/linting/flutter/.pre-commit-config.yaml.template +27 -0
- package/dist/templates/linting/flutter/analysis_options.yaml.template +26 -0
- package/dist/templates/linting/nodejs/.eslintrc-commonjs.json.template +19 -0
- package/dist/templates/linting/nodejs/.eslintrc-esm.json.template +19 -0
- package/dist/templates/linting/nodejs/.eslintrc-typescript.json.template +22 -0
- package/dist/templates/linting/nodejs/.pre-commit-config.yaml.template +51 -0
- package/dist/templates/linting/nodejs/.prettierrc.json.template +10 -0
- package/dist/templates/linting/python/.flake8.template +16 -0
- package/dist/templates/linting/python/.pre-commit-config.yaml.template +30 -0
- package/dist/templates/linting/python/pyproject.toml.template +38 -0
- package/dist/templates/linting/rust/.pre-commit-config.yaml.template +28 -0
- package/dist/templates/linting/rust/clippy.toml.template +14 -0
- package/dist/templates/linting/rust/rustfmt.toml.template +12 -0
- package/dist/templates/root/CLAUDE.md.template +65 -0
- package/dist/templates/root/TRINITY.md.template +52 -0
- package/dist/templates/shared/claude-commands/trinity-agents.md.template +168 -0
- package/dist/templates/shared/claude-commands/trinity-audit.md.template +646 -0
- package/dist/templates/shared/claude-commands/trinity-changelog.md.template +624 -0
- package/dist/templates/shared/claude-commands/trinity-continue.md.template +549 -0
- package/dist/templates/shared/claude-commands/trinity-create-investigation.md.template +232 -0
- package/dist/templates/shared/claude-commands/trinity-decompose.md.template +181 -0
- package/dist/templates/shared/claude-commands/trinity-design.md.template +347 -0
- package/dist/templates/shared/claude-commands/trinity-docs.md.template +2093 -0
- package/dist/templates/shared/claude-commands/trinity-end.md.template +397 -0
- package/dist/templates/shared/claude-commands/trinity-init.md.template +606 -0
- package/dist/templates/shared/claude-commands/trinity-investigate-templates.md.template +725 -0
- package/dist/templates/shared/claude-commands/trinity-orchestrate.md.template +1061 -0
- package/dist/templates/shared/claude-commands/trinity-plan-investigation.md.template +135 -0
- package/dist/templates/shared/claude-commands/trinity-plan.md.template +201 -0
- package/dist/templates/shared/claude-commands/trinity-readme.md.template +1971 -0
- package/dist/templates/shared/claude-commands/trinity-requirements.md.template +148 -0
- package/dist/templates/shared/claude-commands/trinity-start.md.template +268 -0
- package/dist/templates/shared/claude-commands/trinity-verify.md.template +453 -0
- package/dist/templates/shared/claude-commands/trinity-workorder.md.template +249 -0
- package/dist/templates/source/base-CLAUDE.md.template +310 -0
- package/dist/templates/source/flutter-CLAUDE.md.template +593 -0
- package/dist/templates/source/nodejs-CLAUDE.md.template +531 -0
- package/dist/templates/source/python-CLAUDE.md.template +510 -0
- package/dist/templates/source/react-CLAUDE.md.template +513 -0
- package/dist/templates/source/rust-CLAUDE.md.template +653 -0
- package/dist/templates/source/tests-CLAUDE.md.template +432 -0
- package/dist/templates/trinity/CLAUDE.md.template +372 -0
- package/dist/templates/work-orders/ANALYSIS-TEMPLATE.md.template +276 -0
- package/dist/templates/work-orders/AUDIT-TEMPLATE.md.template +262 -0
- package/dist/templates/work-orders/IMPLEMENTATION-TEMPLATE.md.template +260 -0
- package/dist/templates/work-orders/INVESTIGATION-TEMPLATE.md.template +206 -0
- package/dist/templates/work-orders/PATTERN-TEMPLATE.md.template +320 -0
- package/dist/templates/work-orders/VERIFICATION-TEMPLATE.md.template +273 -0
- package/package.json +94 -0
|
@@ -0,0 +1,625 @@
|
|
|
1
|
+
# Performance Investigation: {{title}}
|
|
2
|
+
|
|
3
|
+
**Investigation ID:** {{investigationId}}
|
|
4
|
+
**Created:** {{createdAt}}
|
|
5
|
+
**Investigator:** {{investigator}}
|
|
6
|
+
**Status:** {{status}}
|
|
7
|
+
**Priority:** {{priority}}
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## ⚡ Performance Issue Summary
|
|
12
|
+
|
|
13
|
+
**Brief Description:**
|
|
14
|
+
{{description}}
|
|
15
|
+
|
|
16
|
+
**Observed Performance:**
|
|
17
|
+
- Current metric: [e.g., 2000ms response time]
|
|
18
|
+
- Target metric: [e.g., 500ms response time]
|
|
19
|
+
- Gap: [e.g., 1500ms slower than target]
|
|
20
|
+
|
|
21
|
+
**Affected Operations:**
|
|
22
|
+
-
|
|
23
|
+
|
|
24
|
+
**User Impact:**
|
|
25
|
+
- [ ] Page load slow
|
|
26
|
+
- [ ] API timeouts
|
|
27
|
+
- [ ] Database queries slow
|
|
28
|
+
- [ ] High memory usage
|
|
29
|
+
- [ ] High CPU usage
|
|
30
|
+
- [ ] Application crashes/restarts
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 🔍 Trinity Method Guided Questions
|
|
35
|
+
|
|
36
|
+
### Performance Baseline
|
|
37
|
+
|
|
38
|
+
**1. Current Metrics**
|
|
39
|
+
- What is the current performance?
|
|
40
|
+
- Response time (p50):
|
|
41
|
+
- Response time (p95):
|
|
42
|
+
- Response time (p99):
|
|
43
|
+
- Throughput (req/sec):
|
|
44
|
+
- Error rate:
|
|
45
|
+
|
|
46
|
+
- When is performance worst?
|
|
47
|
+
- [ ] Always slow
|
|
48
|
+
- [ ] Peak hours (specify):
|
|
49
|
+
- [ ] After certain actions
|
|
50
|
+
- [ ] After deployment
|
|
51
|
+
- [ ] With large datasets
|
|
52
|
+
|
|
53
|
+
**2. Historical Performance**
|
|
54
|
+
- How has performance changed over time?
|
|
55
|
+
- 1 week ago:
|
|
56
|
+
- 1 month ago:
|
|
57
|
+
- 6 months ago:
|
|
58
|
+
|
|
59
|
+
- When did performance start degrading?
|
|
60
|
+
Date/Time:
|
|
61
|
+
|
|
62
|
+
- What changed at that time?
|
|
63
|
+
- [ ] Code deployment
|
|
64
|
+
- [ ] Traffic increase
|
|
65
|
+
- [ ] Data growth
|
|
66
|
+
- [ ] Infrastructure change
|
|
67
|
+
- [ ] Configuration change
|
|
68
|
+
|
|
69
|
+
### Bottleneck Identification
|
|
70
|
+
|
|
71
|
+
**3. Where is the slowness?**
|
|
72
|
+
- [ ] Frontend (browser rendering)
|
|
73
|
+
- [ ] Network (latency, bandwidth)
|
|
74
|
+
- [ ] API server (request processing)
|
|
75
|
+
- [ ] Database (query execution)
|
|
76
|
+
- [ ] External services (third-party APIs)
|
|
77
|
+
- [ ] File I/O (disk operations)
|
|
78
|
+
|
|
79
|
+
- How do you know?
|
|
80
|
+
Evidence:
|
|
81
|
+
|
|
82
|
+
**4. Resource Utilization**
|
|
83
|
+
- CPU usage:
|
|
84
|
+
- Current: X%
|
|
85
|
+
- Peak: Y%
|
|
86
|
+
- Baseline: Z%
|
|
87
|
+
|
|
88
|
+
- Memory usage:
|
|
89
|
+
- Current: X MB/GB
|
|
90
|
+
- Peak: Y MB/GB
|
|
91
|
+
- Baseline: Z MB/GB
|
|
92
|
+
|
|
93
|
+
- Disk I/O:
|
|
94
|
+
- Read: X MB/s
|
|
95
|
+
- Write: Y MB/s
|
|
96
|
+
|
|
97
|
+
- Network I/O:
|
|
98
|
+
- Inbound: X MB/s
|
|
99
|
+
- Outbound: Y MB/s
|
|
100
|
+
|
|
101
|
+
**5. Known Performance Issues**
|
|
102
|
+
- Are there N+1 query problems?
|
|
103
|
+
- Are there memory leaks?
|
|
104
|
+
- Are there inefficient algorithms (O(n²))?
|
|
105
|
+
- Are there blocking operations?
|
|
106
|
+
- Are results being cached?
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## 📊 Performance Profiling
|
|
111
|
+
|
|
112
|
+
### Browser Profiling (Frontend)
|
|
113
|
+
|
|
114
|
+
**Chrome DevTools Performance:**
|
|
115
|
+
```bash
|
|
116
|
+
# Steps to capture profile:
|
|
117
|
+
1. Open Chrome DevTools (F12)
|
|
118
|
+
2. Go to Performance tab
|
|
119
|
+
3. Click Record
|
|
120
|
+
4. Perform slow operation
|
|
121
|
+
5. Stop recording
|
|
122
|
+
6. Analyze flame graph
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**Key Metrics:**
|
|
126
|
+
- Time to First Byte (TTFB):
|
|
127
|
+
- First Contentful Paint (FCP):
|
|
128
|
+
- Largest Contentful Paint (LCP):
|
|
129
|
+
- Time to Interactive (TTI):
|
|
130
|
+
- Total Blocking Time (TBT):
|
|
131
|
+
- Cumulative Layout Shift (CLS):
|
|
132
|
+
|
|
133
|
+
**Bottlenecks Found:**
|
|
134
|
+
-
|
|
135
|
+
|
|
136
|
+
### Backend Profiling
|
|
137
|
+
|
|
138
|
+
**Node.js Profiling:**
|
|
139
|
+
```bash
|
|
140
|
+
# Generate CPU profile
|
|
141
|
+
node --prof app.js
|
|
142
|
+
node --prof-process isolate-*.log > profile.txt
|
|
143
|
+
|
|
144
|
+
# Heap snapshot for memory
|
|
145
|
+
node --inspect app.js
|
|
146
|
+
# Open chrome://inspect, take heap snapshot
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
**Python Profiling:**
|
|
150
|
+
```bash
|
|
151
|
+
# cProfile
|
|
152
|
+
python -m cProfile -o output.prof app.py
|
|
153
|
+
python -m pstats output.prof
|
|
154
|
+
|
|
155
|
+
# memory_profiler
|
|
156
|
+
python -m memory_profiler app.py
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**Findings:**
|
|
160
|
+
-
|
|
161
|
+
|
|
162
|
+
### Database Profiling
|
|
163
|
+
|
|
164
|
+
**Query Analysis:**
|
|
165
|
+
```sql
|
|
166
|
+
-- PostgreSQL
|
|
167
|
+
EXPLAIN ANALYZE
|
|
168
|
+
SELECT ...;
|
|
169
|
+
|
|
170
|
+
-- MySQL
|
|
171
|
+
EXPLAIN
|
|
172
|
+
SELECT ...;
|
|
173
|
+
|
|
174
|
+
-- Check slow query log
|
|
175
|
+
SHOW VARIABLES LIKE 'slow_query_log';
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
**Slow Queries Identified:**
|
|
179
|
+
1. Query: `[SQL]`
|
|
180
|
+
- Execution time: X ms
|
|
181
|
+
- Rows scanned: Y
|
|
182
|
+
- Indexes used: [index names]
|
|
183
|
+
|
|
184
|
+
2. Query: `[SQL]`
|
|
185
|
+
- Execution time: X ms
|
|
186
|
+
- Rows scanned: Y
|
|
187
|
+
- Indexes used: [index names]
|
|
188
|
+
|
|
189
|
+
**N+1 Query Problems:**
|
|
190
|
+
-
|
|
191
|
+
|
|
192
|
+
**Missing Indexes:**
|
|
193
|
+
-
|
|
194
|
+
|
|
195
|
+
### Application Performance Monitoring (APM)
|
|
196
|
+
|
|
197
|
+
**Tool:** [e.g., New Relic, DataDog, Sentry]
|
|
198
|
+
|
|
199
|
+
**Traces:**
|
|
200
|
+
- Slowest transactions:
|
|
201
|
+
1. [Transaction name] - X ms
|
|
202
|
+
2. [Transaction name] - Y ms
|
|
203
|
+
|
|
204
|
+
- Most time-consuming operations:
|
|
205
|
+
1. [Operation] - X% of time
|
|
206
|
+
2. [Operation] - Y% of time
|
|
207
|
+
|
|
208
|
+
**Screenshots:**
|
|
209
|
+
- [Link to APM trace screenshot]
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## 🔬 Investigation Plan
|
|
214
|
+
|
|
215
|
+
### Phase 1: Measure & Profile
|
|
216
|
+
**Goal:** Establish baseline and identify bottlenecks
|
|
217
|
+
|
|
218
|
+
**Steps:**
|
|
219
|
+
1. [ ] Run performance benchmarks (before optimization)
|
|
220
|
+
2. [ ] Profile CPU usage
|
|
221
|
+
3. [ ] Profile memory usage
|
|
222
|
+
4. [ ] Analyze database queries
|
|
223
|
+
5. [ ] Review network waterfalls
|
|
224
|
+
6. [ ] Identify top 3 bottlenecks
|
|
225
|
+
|
|
226
|
+
**Benchmark Commands:**
|
|
227
|
+
```bash
|
|
228
|
+
# Load testing
|
|
229
|
+
artillery quick --count 100 --num 10 http://localhost:3000
|
|
230
|
+
|
|
231
|
+
# Or k6
|
|
232
|
+
k6 run load-test.js
|
|
233
|
+
|
|
234
|
+
# Or Apache Bench
|
|
235
|
+
ab -n 1000 -c 10 http://localhost:3000/api/endpoint
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
**Baseline Metrics (before optimization):**
|
|
239
|
+
- p50 response time: X ms
|
|
240
|
+
- p95 response time: Y ms
|
|
241
|
+
- p99 response time: Z ms
|
|
242
|
+
- Requests/sec: N
|
|
243
|
+
- Error rate: M%
|
|
244
|
+
|
|
245
|
+
### Phase 2: Optimize Top Bottleneck
|
|
246
|
+
**Goal:** Fix the slowest operation first
|
|
247
|
+
|
|
248
|
+
**Top Bottleneck:**
|
|
249
|
+
[Description]
|
|
250
|
+
|
|
251
|
+
**Optimization Approach:**
|
|
252
|
+
- [ ] Add caching
|
|
253
|
+
- [ ] Optimize algorithm (O(n²) → O(n log n))
|
|
254
|
+
- [ ] Add database index
|
|
255
|
+
- [ ] Reduce data fetched
|
|
256
|
+
- [ ] Paginate results
|
|
257
|
+
- [ ] Use connection pooling
|
|
258
|
+
- [ ] Implement lazy loading
|
|
259
|
+
- [ ] Compress responses
|
|
260
|
+
- [ ] Other: [specify]
|
|
261
|
+
|
|
262
|
+
**Expected Improvement:**
|
|
263
|
+
- Current: X ms
|
|
264
|
+
- Target: Y ms
|
|
265
|
+
- Improvement: Z% faster
|
|
266
|
+
|
|
267
|
+
### Phase 3: Validate & Measure
|
|
268
|
+
**Goal:** Confirm optimization worked
|
|
269
|
+
|
|
270
|
+
**Steps:**
|
|
271
|
+
1. [ ] Re-run benchmarks (after optimization)
|
|
272
|
+
2. [ ] Compare before/after metrics
|
|
273
|
+
3. [ ] Verify no regressions
|
|
274
|
+
4. [ ] Load test with realistic traffic
|
|
275
|
+
5. [ ] Monitor in production
|
|
276
|
+
|
|
277
|
+
**After Optimization Metrics:**
|
|
278
|
+
- p50 response time: X ms (was Y ms) → Z% improvement
|
|
279
|
+
- p95 response time: X ms (was Y ms) → Z% improvement
|
|
280
|
+
- p99 response time: X ms (was Y ms) → Z% improvement
|
|
281
|
+
- Requests/sec: N (was M) → Z% improvement
|
|
282
|
+
- Error rate: X% (was Y%) → Z% change
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## 🎯 Optimization Strategies
|
|
287
|
+
|
|
288
|
+
### Caching Strategies
|
|
289
|
+
|
|
290
|
+
**What to Cache:**
|
|
291
|
+
- [ ] Database query results
|
|
292
|
+
- [ ] API responses
|
|
293
|
+
- [ ] Computed values
|
|
294
|
+
- [ ] Static assets
|
|
295
|
+
- [ ] Session data
|
|
296
|
+
|
|
297
|
+
**Caching Layers:**
|
|
298
|
+
- [ ] In-memory (Redis, Memcached)
|
|
299
|
+
- [ ] HTTP caching (CDN, browser)
|
|
300
|
+
- [ ] Application-level caching
|
|
301
|
+
- [ ] Database query caching
|
|
302
|
+
|
|
303
|
+
**Cache Implementation:**
|
|
304
|
+
```typescript
|
|
305
|
+
// Example caching code
|
|
306
|
+
const cacheKey = generateKey(params);
|
|
307
|
+
let result = await cache.get(cacheKey);
|
|
308
|
+
|
|
309
|
+
if (!result) {
|
|
310
|
+
result = await expensiveOperation(params);
|
|
311
|
+
await cache.set(cacheKey, result, 3600); // 1 hour TTL
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return result;
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### Database Optimizations
|
|
318
|
+
|
|
319
|
+
**Indexing:**
|
|
320
|
+
```sql
|
|
321
|
+
-- Add indexes for slow queries
|
|
322
|
+
CREATE INDEX idx_users_email ON users(email);
|
|
323
|
+
CREATE INDEX idx_orders_user_created ON orders(user_id, created_at);
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
**Query Optimization:**
|
|
327
|
+
```sql
|
|
328
|
+
-- ❌ Bad: SELECT *
|
|
329
|
+
SELECT * FROM users WHERE email = 'test@example.com';
|
|
330
|
+
|
|
331
|
+
-- ✅ Good: SELECT specific fields
|
|
332
|
+
SELECT id, name, email FROM users WHERE email = 'test@example.com';
|
|
333
|
+
|
|
334
|
+
-- ❌ Bad: N+1 queries
|
|
335
|
+
SELECT * FROM orders; -- 100 orders
|
|
336
|
+
SELECT * FROM users WHERE id = 1; -- Query for each order
|
|
337
|
+
|
|
338
|
+
-- ✅ Good: JOIN
|
|
339
|
+
SELECT orders.*, users.name
|
|
340
|
+
FROM orders
|
|
341
|
+
JOIN users ON orders.user_id = users.id;
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
**Connection Pooling:**
|
|
345
|
+
```typescript
|
|
346
|
+
// Configure connection pool
|
|
347
|
+
const pool = new Pool({
|
|
348
|
+
max: 20, // Max connections
|
|
349
|
+
idleTimeoutMillis: 30000,
|
|
350
|
+
connectionTimeoutMillis: 2000,
|
|
351
|
+
});
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### Algorithm Optimizations
|
|
355
|
+
|
|
356
|
+
**Time Complexity Improvements:**
|
|
357
|
+
- [ ] O(n²) → O(n log n) [sorting]
|
|
358
|
+
- [ ] O(n) → O(1) [use HashMap/Set]
|
|
359
|
+
- [ ] O(n!) → O(n²) [dynamic programming]
|
|
360
|
+
|
|
361
|
+
**Example:**
|
|
362
|
+
```typescript
|
|
363
|
+
// ❌ Bad: O(n²) nested loops
|
|
364
|
+
function findDuplicates(arr) {
|
|
365
|
+
for (let i = 0; i < arr.length; i++) {
|
|
366
|
+
for (let j = i + 1; j < arr.length; j++) {
|
|
367
|
+
if (arr[i] === arr[j]) return true;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return false;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// ✅ Good: O(n) using Set
|
|
374
|
+
function findDuplicates(arr) {
|
|
375
|
+
const seen = new Set();
|
|
376
|
+
for (const item of arr) {
|
|
377
|
+
if (seen.has(item)) return true;
|
|
378
|
+
seen.add(item);
|
|
379
|
+
}
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
### Frontend Optimizations
|
|
385
|
+
|
|
386
|
+
**Code Splitting:**
|
|
387
|
+
```javascript
|
|
388
|
+
// Lazy load components
|
|
389
|
+
const HeavyComponent = lazy(() => import('./HeavyComponent'));
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
**Image Optimization:**
|
|
393
|
+
- [ ] Use WebP format
|
|
394
|
+
- [ ] Implement lazy loading
|
|
395
|
+
- [ ] Use responsive images
|
|
396
|
+
- [ ] Compress images
|
|
397
|
+
- [ ] Use CDN
|
|
398
|
+
|
|
399
|
+
**Bundle Size Reduction:**
|
|
400
|
+
```bash
|
|
401
|
+
# Analyze bundle
|
|
402
|
+
npm run build -- --analyze
|
|
403
|
+
|
|
404
|
+
# Remove unused dependencies
|
|
405
|
+
npx depcheck
|
|
406
|
+
|
|
407
|
+
# Use production builds
|
|
408
|
+
NODE_ENV=production npm run build
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
---
|
|
412
|
+
|
|
413
|
+
## 📈 Performance Budgets
|
|
414
|
+
|
|
415
|
+
### Target Metrics
|
|
416
|
+
- **Response Time:**
|
|
417
|
+
- p50: < 200ms
|
|
418
|
+
- p95: < 500ms
|
|
419
|
+
- p99: < 1000ms
|
|
420
|
+
|
|
421
|
+
- **Throughput:**
|
|
422
|
+
- Minimum: 100 req/sec
|
|
423
|
+
- Target: 500 req/sec
|
|
424
|
+
|
|
425
|
+
- **Resource Usage:**
|
|
426
|
+
- CPU: < 70%
|
|
427
|
+
- Memory: < 80%
|
|
428
|
+
- Disk I/O: < 50MB/s
|
|
429
|
+
|
|
430
|
+
- **Web Vitals:**
|
|
431
|
+
- LCP: < 2.5s
|
|
432
|
+
- FID: < 100ms
|
|
433
|
+
- CLS: < 0.1
|
|
434
|
+
|
|
435
|
+
### Performance Regression Prevention
|
|
436
|
+
|
|
437
|
+
**Automated Performance Tests:**
|
|
438
|
+
```typescript
|
|
439
|
+
// Performance test example
|
|
440
|
+
describe('Performance: getUserOrders', () => {
|
|
441
|
+
it('should complete in < 500ms for 1000 orders', async () => {
|
|
442
|
+
const start = performance.now();
|
|
443
|
+
await getUserOrders(userId);
|
|
444
|
+
const duration = performance.now() - start;
|
|
445
|
+
|
|
446
|
+
expect(duration).toBeLessThan(500);
|
|
447
|
+
});
|
|
448
|
+
});
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
**CI/CD Performance Gates:**
|
|
452
|
+
```yaml
|
|
453
|
+
# GitHub Actions example
|
|
454
|
+
- name: Performance Test
|
|
455
|
+
run: npm run test:performance
|
|
456
|
+
|
|
457
|
+
- name: Check Performance Budget
|
|
458
|
+
run: |
|
|
459
|
+
if [ $P95_RESPONSE_TIME -gt 500 ]; then
|
|
460
|
+
echo "Performance regression detected"
|
|
461
|
+
exit 1
|
|
462
|
+
fi
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
---
|
|
466
|
+
|
|
467
|
+
## 💡 Root Cause Analysis
|
|
468
|
+
|
|
469
|
+
### Performance Bottleneck
|
|
470
|
+
[Detailed explanation of what is causing slowness]
|
|
471
|
+
|
|
472
|
+
### Why Analysis
|
|
473
|
+
1. **Why is the system slow?**
|
|
474
|
+
Answer:
|
|
475
|
+
|
|
476
|
+
2. **Why does that cause slowness?**
|
|
477
|
+
Answer:
|
|
478
|
+
|
|
479
|
+
3. **Why does that happen?**
|
|
480
|
+
Answer:
|
|
481
|
+
|
|
482
|
+
4. **Why wasn't this optimized earlier?**
|
|
483
|
+
Answer:
|
|
484
|
+
|
|
485
|
+
5. **What changed to make this noticeable?**
|
|
486
|
+
Answer: [Root cause]
|
|
487
|
+
|
|
488
|
+
---
|
|
489
|
+
|
|
490
|
+
## 🔧 Solution
|
|
491
|
+
|
|
492
|
+
### Optimizations Implemented
|
|
493
|
+
**1. [Optimization Name]**
|
|
494
|
+
- Description:
|
|
495
|
+
- Expected improvement:
|
|
496
|
+
- Actual improvement:
|
|
497
|
+
|
|
498
|
+
**2. [Optimization Name]**
|
|
499
|
+
- Description:
|
|
500
|
+
- Expected improvement:
|
|
501
|
+
- Actual improvement:
|
|
502
|
+
|
|
503
|
+
### Code Changes
|
|
504
|
+
**Files Modified:**
|
|
505
|
+
- `path/to/file.ts`
|
|
506
|
+
|
|
507
|
+
**Key Changes:**
|
|
508
|
+
```diff
|
|
509
|
+
- // Slow code
|
|
510
|
+
+ // Fast code
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
### Infrastructure Changes
|
|
514
|
+
-
|
|
515
|
+
|
|
516
|
+
---
|
|
517
|
+
|
|
518
|
+
## ✅ Success Criteria
|
|
519
|
+
|
|
520
|
+
**Performance Targets Met:**
|
|
521
|
+
- [ ] Response time < 500ms (p95)
|
|
522
|
+
- [ ] Throughput > 100 req/sec
|
|
523
|
+
- [ ] CPU usage < 70%
|
|
524
|
+
- [ ] Memory usage < 80%
|
|
525
|
+
- [ ] No performance regressions
|
|
526
|
+
- [ ] User-reported slowness resolved
|
|
527
|
+
|
|
528
|
+
**Validation:**
|
|
529
|
+
- [ ] Load tests pass
|
|
530
|
+
- [ ] Production metrics within budget
|
|
531
|
+
- [ ] No errors from optimization
|
|
532
|
+
- [ ] Monitoring confirms improvement
|
|
533
|
+
|
|
534
|
+
---
|
|
535
|
+
|
|
536
|
+
## 📋 DELIVERABLE REQUIREMENTS
|
|
537
|
+
|
|
538
|
+
### Investigation Report Format
|
|
539
|
+
**Filename:** `INV-{{investigationId}}-findings-[TIMESTAMP].md`
|
|
540
|
+
**Location:** `trinity/reports/`
|
|
541
|
+
|
|
542
|
+
### Required Sections
|
|
543
|
+
1. **Investigation Summary** - Performance issue overview and user impact
|
|
544
|
+
2. **Findings** - Bottleneck analysis, profiling results, and root cause
|
|
545
|
+
3. **Performance Metrics** - Before/after comparison with specific measurements
|
|
546
|
+
4. **Optimization Strategy** - Detailed approach with expected improvements
|
|
547
|
+
5. **Testing Results** - Load test results, benchmarks, and validation data
|
|
548
|
+
6. **Recommendations** - Work orders to create, monitoring to add, long-term improvements
|
|
549
|
+
|
|
550
|
+
### Evidence to Provide
|
|
551
|
+
- Profiling screenshots (CPU, memory, network)
|
|
552
|
+
- APM traces showing bottlenecks
|
|
553
|
+
- Before/after benchmark results (p50, p95, p99)
|
|
554
|
+
- Database query execution plans (EXPLAIN ANALYZE)
|
|
555
|
+
- Load test results with graphs
|
|
556
|
+
- Resource utilization metrics
|
|
557
|
+
|
|
558
|
+
---
|
|
559
|
+
|
|
560
|
+
## ✅ AFTER COMPLETION
|
|
561
|
+
|
|
562
|
+
When investigation is complete:
|
|
563
|
+
1. **Create Investigation Report:**
|
|
564
|
+
- [ ] Save findings report to `trinity/reports/INV-{{investigationId}}-findings-[TIMESTAMP].md`
|
|
565
|
+
- [ ] Include all required sections listed above
|
|
566
|
+
- [ ] Attach all evidence and supporting documentation
|
|
567
|
+
|
|
568
|
+
2. **Move Investigation File:**
|
|
569
|
+
- [ ] Move this investigation file (INV-{{investigationId}}.md) to `trinity/sessions/`
|
|
570
|
+
- [ ] Keep report in `trinity/reports/` until end of session
|
|
571
|
+
|
|
572
|
+
3. **Session Cleanup:**
|
|
573
|
+
- [ ] Run `/trinity-end` to archive both investigation and report
|
|
574
|
+
- [ ] Investigation will be archived to `trinity/archive/investigations/YYYY-MM-DD/`
|
|
575
|
+
- [ ] Report will be archived to `trinity/archive/reports/YYYY-MM-DD/`
|
|
576
|
+
|
|
577
|
+
4. **Clean Slate:**
|
|
578
|
+
- [ ] Verify `trinity/sessions/` is empty (ready for next session)
|
|
579
|
+
- [ ] Verify `trinity/reports/` is empty (ready for next session)
|
|
580
|
+
|
|
581
|
+
---
|
|
582
|
+
|
|
583
|
+
## 📚 Reference Documentation
|
|
584
|
+
|
|
585
|
+
**Trinity Method Core:**
|
|
586
|
+
- [Trinity Method Protocols](../../CLAUDE.md) - Root Trinity guidance
|
|
587
|
+
- [Investigation Requirements](../../trinity/CLAUDE.md#investigation-protocols) - Investigation-first methodology
|
|
588
|
+
- [Agent Directory](../../.claude/EMPLOYEE-DIRECTORY.md) - 19-agent Trinity team
|
|
589
|
+
|
|
590
|
+
**Knowledge Base:**
|
|
591
|
+
- [Architecture](../../trinity/knowledge-base/ARCHITECTURE.md) - System architecture and patterns
|
|
592
|
+
- [Known Issues](../../trinity/knowledge-base/ISSUES.md) - Issue patterns database
|
|
593
|
+
- [Technical Debt](../../trinity/knowledge-base/Technical-Debt.md) - Debt tracking
|
|
594
|
+
- [Testing Standards](../../trinity/knowledge-base/TESTING-PRINCIPLES.md) - Test requirements
|
|
595
|
+
- [Coding Standards](../../trinity/knowledge-base/CODING-PRINCIPLES.md) - Code quality
|
|
596
|
+
|
|
597
|
+
**Investigation Protocols:**
|
|
598
|
+
- READ-ONLY: No file modifications during investigation
|
|
599
|
+
- Document findings thoroughly
|
|
600
|
+
- Provide evidence-based recommendations
|
|
601
|
+
- Implementation requires separate approval
|
|
602
|
+
|
|
603
|
+
---
|
|
604
|
+
|
|
605
|
+
## 📚 Lessons Learned
|
|
606
|
+
|
|
607
|
+
### What Worked
|
|
608
|
+
-
|
|
609
|
+
|
|
610
|
+
### What Didn't Work
|
|
611
|
+
-
|
|
612
|
+
|
|
613
|
+
### Prevention Strategy
|
|
614
|
+
-
|
|
615
|
+
|
|
616
|
+
---
|
|
617
|
+
|
|
618
|
+
**Investigation Status:** {{status}}
|
|
619
|
+
**Priority:** {{priority}}
|
|
620
|
+
**Created:** {{createdAt}}
|
|
621
|
+
**Last Updated:** {{lastUpdated}}
|
|
622
|
+
**Next Review:** {{nextReview}}
|
|
623
|
+
**Investigator:** {{investigator}}
|
|
624
|
+
|
|
625
|
+
**Performance Improvement:** [X% faster]
|