@haposoft/cafekit 0.3.2 → 0.3.6

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.
@@ -19,7 +19,8 @@
19
19
  },
20
20
  "skills": {
21
21
  "required": [
22
- "specs"
22
+ "specs",
23
+ "impact-analysis"
23
24
  ]
24
25
  },
25
26
  "agents": {
@@ -0,0 +1,271 @@
1
+ ---
2
+ name: impact-analysis
3
+ description: "Phân tích tác động code changes và tạo test scenarios. Sử dụng sau khi sửa code, trước commit, hoặc khi cần kiểm tra regression. Tự động phát hiện affected files, dependencies, edge cases."
4
+ argument-hint: "[files] OR auto"
5
+ version: 1.0.0
6
+ ---
7
+
8
+ # Impact Analysis - Phân Tích Tác Động & Test Guidance
9
+
10
+ Phân tích tác động của code changes và đưa ra hướng dẫn test chi tiết để tránh regression bugs.
11
+
12
+ ## Arguments
13
+
14
+ - **Default (no args)**: Phân tích git diff gần nhất
15
+ - **`auto`**: Tự động phát hiện changes và phân tích
16
+ - **`{files}`**: Phân tích files cụ thể (comma-separated)
17
+
18
+ ## Khi Nào Sử Dụng
19
+
20
+ ✅ **Nên dùng:**
21
+ - Sau khi sửa code, trước khi commit
22
+ - Trước khi tạo Pull Request
23
+ - Sau khi fix bug (đảm bảo không tạo bug mới)
24
+ - Khi refactor code (verify không phá functionality)
25
+ - Khi thêm feature mới (tìm integration points)
26
+
27
+ ❌ **Không cần:**
28
+ - Chỉ sửa documentation
29
+ - Chỉ sửa comments
30
+ - Thay đổi config không ảnh hưởng logic
31
+
32
+ ## Quick Start
33
+
34
+ ```bash
35
+ # Phân tích changes gần nhất
36
+ /impact-analysis
37
+
38
+ # Tự động detect và phân tích
39
+ /impact-analysis auto
40
+
41
+ # Phân tích files cụ thể
42
+ /impact-analysis src/api/auth.ts,src/components/Login.tsx
43
+ ```
44
+
45
+ ## Workflow
46
+
47
+ ### 0. Auto-Detect Project Type (NEW)
48
+
49
+ Load `references/project-detection.md` để:
50
+ - Tự động detect project type (React Native, Next.js, Node.js API, etc.)
51
+ - Load appropriate profile với patterns và edge cases
52
+ - Check for custom config file (`impact-analysis.config.js`)
53
+ - Merge custom config với default profile
54
+
55
+ ### 1. Detect Changes
56
+
57
+ Load `references/change-detection.md` để:
58
+ - Phát hiện files đã thay đổi (git diff)
59
+ - Phân loại thay đổi (backend/frontend/database)
60
+ - Đánh giá mức độ risk
61
+
62
+ ### 2. Scout Dependencies
63
+
64
+ Load `references/dependency-scouting.md` để:
65
+ - Tìm files import/sử dụng code đã sửa
66
+ - Phát hiện reverse dependencies
67
+ - Xác định integration points
68
+
69
+ **Advanced**: Load `references/industry-techniques.md` để:
70
+ - Sử dụng Call Graph Analysis (Technique #2)
71
+ - Sử dụng Dependency Graph tools
72
+ - Áp dụng AST-based analysis (Technique #3) cho semantic changes
73
+
74
+ ### 3. Identify Edge Cases
75
+
76
+ Load `references/edge-case-identification.md` để:
77
+ - Phân tích data flow
78
+ - Tìm boundary conditions
79
+ - Xác định error scenarios
80
+ - Phát hiện race conditions
81
+
82
+ **Advanced**: Load `references/industry-techniques.md` để:
83
+ - Sử dụng Static Analysis (Technique #4) cho data/control flow
84
+ - Sử dụng Type Analysis cho type compatibility
85
+ - Áp dụng Test-Based Analysis (Technique #6) cho coverage mapping
86
+
87
+ ### 4. Generate Test Scenarios
88
+
89
+ Load `references/test-scenario-generation.md` để:
90
+ - Tạo happy path scenarios
91
+ - Tạo error handling scenarios
92
+ - Tạo integration test scenarios
93
+ - Tạo regression test checklist
94
+
95
+ ### 5. Create Report
96
+
97
+ Load `references/report-template.md` để:
98
+ - Tổng hợp findings
99
+ - Đánh giá risk
100
+ - Đưa ra recommendations
101
+ - Tạo actionable checklist
102
+
103
+ ## Output
104
+
105
+ ```markdown
106
+ # Impact Analysis Report
107
+
108
+ ## 📋 Summary
109
+ - Changed: 3 files
110
+ - Affected: 12 components
111
+ - Risk: Medium
112
+ - Test Time: ~30 mins
113
+
114
+ ## 🔍 Changes
115
+ {detailed analysis}
116
+
117
+ ## 🔗 Dependencies
118
+ {affected files}
119
+
120
+ ## ⚠️ Edge Cases
121
+ {identified issues}
122
+
123
+ ## 🧪 Test Scenarios
124
+ {detailed scenarios}
125
+
126
+ ## ✅ Checklist
127
+ {actionable items}
128
+ ```
129
+
130
+ ## Integration
131
+
132
+ ### With Code Review
133
+
134
+ ```
135
+ 1. Make changes
136
+ 2. /impact-analysis
137
+ 3. Review findings
138
+ 4. /review (includes impact report)
139
+ ```
140
+
141
+ ### With Testing
142
+
143
+ ```
144
+ 1. /impact-analysis
145
+ 2. Get test scenarios
146
+ 3. /test (execute scenarios)
147
+ 4. Verify all pass
148
+ ```
149
+
150
+ ## References
151
+
152
+ ### Core References
153
+ - `references/project-detection.md` - Auto-detect project type & load profile
154
+ - `references/change-detection.md` - Git diff analysis
155
+ - `references/dependency-scouting.md` - Finding affected files
156
+ - `references/edge-case-identification.md` - Edge case patterns
157
+ - `references/test-scenario-generation.md` - Test templates
158
+ - `references/report-template.md` - Output format
159
+
160
+ ### Advanced References
161
+ - `references/industry-techniques.md` - 9 techniques từ industry & research
162
+ - `references/practical-techniques-guide.md` - Detailed implementation guide
163
+ - `references/react-native-customization.md` - React Native specific guide
164
+
165
+ ### Scripts
166
+ - `scripts/README.md` - Helper scripts documentation
167
+ - `scripts/ast-analyze.js` - AST-based analysis
168
+ - `scripts/find-dependencies.sh` - Dependency analysis
169
+ - `scripts/calculate-risk.js` - Risk scoring
170
+ - `scripts/run-analysis.sh` - Master script
171
+
172
+ ## Advanced Techniques
173
+
174
+ Skill này hỗ trợ advanced analysis techniques từ industry:
175
+
176
+ ### Available Scripts
177
+
178
+ Located in `scripts/` directory:
179
+
180
+ 1. **ast-analyze.js** - AST-based semantic analysis
181
+ - Detect function signature changes
182
+ - Identify breaking changes
183
+ - Compare before/after versions
184
+
185
+ 2. **find-dependencies.sh** - Comprehensive dependency analysis
186
+ - Find all affected files
187
+ - Map API consumers
188
+ - Identify integration points
189
+
190
+ 3. **calculate-risk.js** - Automated risk scoring
191
+ - Multi-factor risk assessment
192
+ - Actionable recommendations
193
+ - JSON output for CI/CD
194
+
195
+ 4. **run-analysis.sh** - Master script
196
+ - Run all techniques
197
+ - Generate comprehensive report
198
+ - Markdown output
199
+
200
+ ### Usage
201
+
202
+ ```bash
203
+ # Quick risk check
204
+ node scripts/calculate-risk.js
205
+
206
+ # Full analysis
207
+ ./scripts/run-analysis.sh
208
+
209
+ # Specific files
210
+ ./scripts/run-analysis.sh --files "file1.ts,file2.ts"
211
+ ```
212
+
213
+ See `scripts/README.md` for detailed documentation.
214
+
215
+ ## Best Practices
216
+
217
+ 1. **Run early** - Phân tích ngay sau khi code, không đợi đến commit
218
+ 2. **Focus on risk** - Ưu tiên high-risk changes
219
+ 3. **Automate** - Integrate vào workflow tự động (pre-commit, CI/CD)
220
+ 4. **Document** - Lưu findings để reference sau
221
+ 5. **Verify** - Luôn chạy tests sau khi có scenarios
222
+ 6. **Use scripts** - Leverage advanced techniques cho deep analysis
223
+
224
+ ## Examples
225
+
226
+ ### Example 1: API Change
227
+
228
+ ```bash
229
+ # Changed: src/api/users.ts (added new field)
230
+ /impact-analysis
231
+
232
+ # Output:
233
+ # - Affected: 5 frontend components using user data
234
+ # - Edge cases: Null handling, backward compatibility
235
+ # - Test: Verify old clients still work
236
+ ```
237
+
238
+ ### Example 2: Database Migration
239
+
240
+ ```bash
241
+ # Changed: prisma/schema.prisma (renamed column)
242
+ /impact-analysis
243
+
244
+ # Output:
245
+ # - Affected: 15 queries using old column name
246
+ # - Edge cases: Migration rollback, data integrity
247
+ # - Test: Verify all queries updated
248
+ ```
249
+
250
+ ### Example 3: Component Refactor
251
+
252
+ ```bash
253
+ # Changed: components/Button.tsx (props interface)
254
+ /impact-analysis
255
+
256
+ # Output:
257
+ # - Affected: 23 components using Button
258
+ # - Edge cases: TypeScript errors, missing props
259
+ # - Test: Visual regression, interaction tests
260
+ ```
261
+
262
+ ## Troubleshooting
263
+
264
+ **Q: Không detect được changes?**
265
+ A: Check git status, đảm bảo có staged/committed changes
266
+
267
+ **Q: Quá nhiều affected files?**
268
+ A: Sử dụng `--scope` để giới hạn phạm vi
269
+
270
+ **Q: Test scenarios không đủ?**
271
+ A: Load `edge-case-identification.md` và review manual
@@ -0,0 +1,270 @@
1
+ # Change Detection - Phát Hiện Thay Đổi
2
+
3
+ Phương pháp phát hiện và phân loại code changes để phân tích tác động.
4
+
5
+ ## Git Commands
6
+
7
+ ### 1. Detect Recent Changes
8
+
9
+ ```bash
10
+ # Changes chưa commit
11
+ git diff --name-only
12
+
13
+ # Changes đã staged
14
+ git diff --cached --name-only
15
+
16
+ # Changes trong commit gần nhất
17
+ git diff --name-only HEAD~1
18
+
19
+ # Changes so với branch khác
20
+ git diff --name-only main...HEAD
21
+
22
+ # Xem chi tiết thay đổi
23
+ git diff HEAD~1
24
+
25
+ # Xem thống kê
26
+ git diff --stat HEAD~1
27
+ ```
28
+
29
+ ### 2. Get Change Details
30
+
31
+ ```bash
32
+ # Số dòng thay đổi
33
+ git diff --numstat HEAD~1
34
+
35
+ # Files và số lượng changes
36
+ git diff --shortstat HEAD~1
37
+
38
+ # Chỉ xem added/deleted files
39
+ git diff --diff-filter=AD --name-only HEAD~1
40
+ ```
41
+
42
+ ### 3. Historical Analysis
43
+
44
+ ```bash
45
+ # Xem lịch sử file
46
+ git log --oneline -10 {file}
47
+
48
+ # Xem ai sửa dòng nào
49
+ git blame {file}
50
+
51
+ # Xem changes của commit cụ thể
52
+ git show {commit-hash}
53
+ ```
54
+
55
+ ## Change Classification
56
+
57
+ ### Backend Changes
58
+
59
+ **Indicators:**
60
+ - Files: `*.ts`, `*.js`, `*.py`, `*.go` trong `src/api/`, `src/services/`, `src/controllers/`
61
+ - Patterns: API routes, database queries, business logic
62
+
63
+ **Risk Level:**
64
+ - **High**: Authentication, authorization, payment, data validation
65
+ - **Medium**: CRUD operations, utility functions
66
+ - **Low**: Logging, comments, formatting
67
+
68
+ **Check:**
69
+ ```bash
70
+ # API endpoints changed
71
+ grep -r "router\." {changed-files}
72
+ grep -r "app\.(get|post|put|delete)" {changed-files}
73
+
74
+ # Database queries
75
+ grep -r "prisma\." {changed-files}
76
+ grep -r "SELECT\|INSERT\|UPDATE\|DELETE" {changed-files}
77
+ ```
78
+
79
+ ### Frontend Changes
80
+
81
+ **Indicators:**
82
+ - Files: `*.tsx`, `*.jsx`, `*.vue`, `*.svelte` trong `src/components/`, `src/pages/`
83
+ - Patterns: Components, hooks, state management
84
+
85
+ **Risk Level:**
86
+ - **High**: Authentication UI, payment forms, data entry
87
+ - **Medium**: Display components, navigation
88
+ - **Low**: Styling, text changes
89
+
90
+ **Check:**
91
+ ```bash
92
+ # Component props changed
93
+ grep -r "interface.*Props" {changed-files}
94
+
95
+ # State management
96
+ grep -r "useState\|useEffect\|useContext" {changed-files}
97
+
98
+ # API calls
99
+ grep -r "fetch\|axios\|api\." {changed-files}
100
+ ```
101
+
102
+ ### Database Changes
103
+
104
+ **Indicators:**
105
+ - Files: `*.prisma`, `*.sql`, `migrations/*.sql`
106
+ - Patterns: Schema changes, migrations
107
+
108
+ **Risk Level:**
109
+ - **Critical**: Column deletion, type changes, constraint changes
110
+ - **High**: New required columns, index changes
111
+ - **Medium**: New optional columns, new tables
112
+ - **Low**: Comments, formatting
113
+
114
+ **Check:**
115
+ ```bash
116
+ # Schema changes
117
+ git diff schema.prisma
118
+
119
+ # Migration files
120
+ ls -la migrations/ | tail -5
121
+
122
+ # Find affected queries
123
+ grep -r "{table_name}" src/
124
+ ```
125
+
126
+ ### Configuration Changes
127
+
128
+ **Indicators:**
129
+ - Files: `.env`, `config/*.ts`, `package.json`, `tsconfig.json`
130
+ - Patterns: Environment variables, dependencies, build config
131
+
132
+ **Risk Level:**
133
+ - **Critical**: Database URL, API keys, auth secrets
134
+ - **High**: Dependencies version, build settings
135
+ - **Medium**: Feature flags, timeouts
136
+ - **Low**: Comments, formatting
137
+
138
+ **Check:**
139
+ ```bash
140
+ # Env changes
141
+ git diff .env.example
142
+
143
+ # Dependency changes
144
+ git diff package.json | grep -A5 -B5 "dependencies"
145
+
146
+ # Config changes
147
+ git diff config/
148
+ ```
149
+
150
+ ## Change Metrics
151
+
152
+ ### Lines of Code (LOC)
153
+
154
+ ```bash
155
+ # Total LOC changed
156
+ git diff --stat HEAD~1 | tail -1
157
+
158
+ # Per file
159
+ git diff --numstat HEAD~1
160
+ ```
161
+
162
+ **Risk Assessment:**
163
+ - **< 50 LOC**: Low risk
164
+ - **50-200 LOC**: Medium risk
165
+ - **> 200 LOC**: High risk (consider splitting)
166
+
167
+ ### File Count
168
+
169
+ ```bash
170
+ # Count changed files
171
+ git diff --name-only HEAD~1 | wc -l
172
+ ```
173
+
174
+ **Risk Assessment:**
175
+ - **1-3 files**: Low risk
176
+ - **4-10 files**: Medium risk
177
+ - **> 10 files**: High risk (wide impact)
178
+
179
+ ### Change Type
180
+
181
+ ```bash
182
+ # Added lines
183
+ git diff HEAD~1 | grep "^+" | wc -l
184
+
185
+ # Deleted lines
186
+ git diff HEAD~1 | grep "^-" | wc -l
187
+ ```
188
+
189
+ **Risk Assessment:**
190
+ - **More additions**: New feature (test new paths)
191
+ - **More deletions**: Refactor (test existing paths)
192
+ - **Balanced**: Modification (test both)
193
+
194
+ ## Automated Detection Script
195
+
196
+ ```bash
197
+ #!/bin/bash
198
+ # detect-changes.sh
199
+
200
+ echo "=== Change Detection ==="
201
+
202
+ # Get changed files
203
+ CHANGED_FILES=$(git diff --name-only HEAD~1)
204
+ FILE_COUNT=$(echo "$CHANGED_FILES" | wc -l)
205
+
206
+ echo "Files changed: $FILE_COUNT"
207
+ echo ""
208
+
209
+ # Classify by type
210
+ BACKEND=$(echo "$CHANGED_FILES" | grep -E "src/(api|services|controllers)" | wc -l)
211
+ FRONTEND=$(echo "$CHANGED_FILES" | grep -E "src/(components|pages)" | wc -l)
212
+ DATABASE=$(echo "$CHANGED_FILES" | grep -E "prisma|migrations" | wc -l)
213
+ CONFIG=$(echo "$CHANGED_FILES" | grep -E "\.env|config|package\.json" | wc -l)
214
+
215
+ echo "Backend: $BACKEND files"
216
+ echo "Frontend: $FRONTEND files"
217
+ echo "Database: $DATABASE files"
218
+ echo "Config: $CONFIG files"
219
+ echo ""
220
+
221
+ # Get LOC stats
222
+ git diff --stat HEAD~1 | tail -1
223
+
224
+ # Risk assessment
225
+ if [ $FILE_COUNT -gt 10 ] || [ $DATABASE -gt 0 ]; then
226
+ echo "Risk: HIGH"
227
+ elif [ $FILE_COUNT -gt 3 ]; then
228
+ echo "Risk: MEDIUM"
229
+ else
230
+ echo "Risk: LOW"
231
+ fi
232
+ ```
233
+
234
+ ## Output Format
235
+
236
+ ```json
237
+ {
238
+ "summary": {
239
+ "totalFiles": 5,
240
+ "linesAdded": 120,
241
+ "linesDeleted": 45,
242
+ "riskLevel": "medium"
243
+ },
244
+ "changes": [
245
+ {
246
+ "file": "src/api/auth.ts",
247
+ "type": "backend",
248
+ "category": "authentication",
249
+ "linesChanged": 67,
250
+ "risk": "high",
251
+ "reason": "Authentication logic modified"
252
+ },
253
+ {
254
+ "file": "src/components/Login.tsx",
255
+ "type": "frontend",
256
+ "category": "ui",
257
+ "linesChanged": 34,
258
+ "risk": "medium",
259
+ "reason": "Login form updated"
260
+ }
261
+ ]
262
+ }
263
+ ```
264
+
265
+ ## Integration Points
266
+
267
+ After detection, pass to:
268
+ 1. **Dependency Scouting** - Find affected files
269
+ 2. **Edge Case Identification** - Analyze risks
270
+ 3. **Test Scenario Generation** - Create tests