dw-kit 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/.claude/hooks/post-write.sh +64 -58
  2. package/.claude/hooks/pre-commit-gate.sh +96 -90
  3. package/.claude/hooks/privacy-block.sh +99 -94
  4. package/.claude/hooks/progress-ping.sh +53 -47
  5. package/.claude/hooks/safety-guard.sh +60 -54
  6. package/.claude/hooks/scout-block.sh +88 -82
  7. package/.claude/hooks/session-init.sh +91 -74
  8. package/.claude/hooks/stop-check.sh +88 -36
  9. package/.claude/hooks/telemetry-log.sh +34 -0
  10. package/.claude/rules/code-style.md +37 -37
  11. package/.claude/rules/commit-standards.md +37 -37
  12. package/.claude/rules/dw.md +136 -0
  13. package/.claude/settings.json +120 -99
  14. package/.claude/skills/dw-arch-review/SKILL.md +119 -119
  15. package/.claude/skills/dw-archive/SKILL.md +81 -81
  16. package/.claude/skills/dw-commit/SKILL.md +81 -81
  17. package/.claude/skills/dw-config-init/SKILL.md +91 -91
  18. package/.claude/skills/dw-config-validate/SKILL.md +75 -75
  19. package/.claude/skills/dw-dashboard/SKILL.md +209 -209
  20. package/.claude/skills/dw-debug/SKILL.md +97 -97
  21. package/.claude/skills/dw-decision/SKILL.md +116 -0
  22. package/.claude/skills/dw-docs-update/SKILL.md +125 -125
  23. package/.claude/skills/dw-estimate/SKILL.md +90 -90
  24. package/.claude/skills/dw-execute/SKILL.md +98 -98
  25. package/.claude/skills/dw-flow/SKILL.md +274 -274
  26. package/.claude/skills/dw-handoff/SKILL.md +81 -81
  27. package/.claude/skills/dw-kit-report/SKILL.md +152 -152
  28. package/.claude/skills/dw-log-work/SKILL.md +69 -69
  29. package/.claude/skills/dw-onboard/SKILL.md +201 -201
  30. package/.claude/skills/dw-plan/SKILL.md +125 -125
  31. package/.claude/skills/dw-prompt/SKILL.md +62 -62
  32. package/.claude/skills/dw-requirements/SKILL.md +98 -98
  33. package/.claude/skills/dw-research/SKILL.md +114 -114
  34. package/.claude/skills/dw-retroactive/SKILL.md +311 -311
  35. package/.claude/skills/dw-review/SKILL.md +66 -66
  36. package/.claude/skills/dw-rollback/SKILL.md +90 -90
  37. package/.claude/skills/dw-sprint-review/SKILL.md +99 -99
  38. package/.claude/skills/dw-task-init/SKILL.md +59 -59
  39. package/.claude/skills/dw-test-plan/SKILL.md +113 -113
  40. package/.claude/skills/dw-thinking/SKILL.md +70 -70
  41. package/.claude/skills/dw-upgrade/SKILL.md +72 -72
  42. package/.dw/config/dw.config.yml +82 -82
  43. package/.dw/core/PILLARS.md +122 -0
  44. package/.dw/core/templates/v2/spec.md +68 -0
  45. package/.dw/core/templates/v2/tracking.md +62 -0
  46. package/.dw/core/v14-evaluation-protocol.md +118 -0
  47. package/CLAUDE.md +42 -39
  48. package/MIGRATION-v1.3.md +201 -0
  49. package/README.md +43 -6
  50. package/package.json +86 -84
  51. package/src/cli.mjs +45 -9
  52. package/src/commands/dashboard.mjs +116 -0
  53. package/src/commands/doctor.mjs +165 -149
  54. package/src/commands/init.mjs +339 -332
  55. package/src/commands/metrics.mjs +165 -0
  56. package/src/commands/upgrade.mjs +297 -262
  57. package/src/lib/active-index.mjs +87 -0
  58. package/src/lib/copy.mjs +118 -110
  59. package/src/lib/cut-analysis.mjs +161 -0
  60. package/src/lib/telemetry.mjs +80 -0
  61. package/.claude/rules/dw-core.md +0 -100
  62. package/.claude/rules/dw-skills.md +0 -53
  63. package/.claude/rules/workflow-rules.md +0 -77
@@ -1,209 +1,209 @@
1
- ---
2
- name: dw-dashboard
3
- description: "Tạo báo cáo tổng hợp cho PM: trạng thái tasks, metrics DORA, effort tracking, velocity. Ghi ra file report để share."
4
- argument-hint: "[sprint-name | period: last-week | last-month | all]"
5
- allowed-tools:
6
- - Read
7
- - Glob
8
- - Grep
9
- - "Bash(git log *)"
10
- - "Bash(git diff *)"
11
- - "Bash(ls *)"
12
- ---
13
-
14
- # PM Dashboard — Báo Cáo Dự Án
15
-
16
- Period: **$ARGUMENTS**
17
-
18
- ## Đọc Config
19
-
20
- Đọc `.dw/config/dw.config.yml`:
21
- - `paths.tasks` → location task docs
22
- - `tracking.log_work` → có data effort tracking không
23
- - `workflow.default_depth` → level of reporting detail
24
-
25
- ## Thu Thập Dữ Liệu
26
-
27
- ### 1. Tasks Overview
28
- ```bash
29
- ls {paths.tasks}/ # danh sách tasks
30
- ```
31
-
32
- Đọc từng `*-progress.md` để lấy:
33
- - Trạng thái (Not Started / In Progress / Blocked / Done)
34
- - Subtasks done/total
35
- - Blockers hiện tại
36
-
37
- ### 2. Git Metrics (DORA)
38
- ```bash
39
- # Commits trong period
40
- git log --oneline --after="[start-date]" --before="[end-date]"
41
-
42
- # Lead time: time from first commit to merge
43
- git log --format="%H %ad" --date=short
44
-
45
- # Frequency
46
- git log --format="%ad" --date=short | sort | uniq -c
47
- ```
48
-
49
- ### 3. Effort Data
50
- Đọc `{.dw/metrics}/effort-log.json` nếu có.
51
-
52
- ### 4. Quality Metrics
53
- Đọc review reports (nếu có) để lấy:
54
- - Critical issues found/fixed
55
- - Test coverage trend
56
-
57
- ## Tính DORA Metrics
58
-
59
- ```
60
- Deployment Frequency = commits merged / working days
61
- Lead Time = avg(merge_date - first_commit_date) per feature
62
- Change Failure Rate = (hotfixes + rollbacks) / total deploys × 100%
63
- MTTR = avg time from incident_detected to resolved
64
- ```
65
-
66
- So sánh với thresholds trong config và xếp loại: Elite / High / Medium / Low.
67
-
68
- ## Tính DORA Tự Động Từ Git
69
-
70
- ```bash
71
- # Deployment frequency (commits/merges per day trong period)
72
- git log --oneline --after="[start]" --before="[end]" | wc -l
73
-
74
- # Lead time: trung bình từ commit đầu đến commit cuối của mỗi feature branch
75
- git log --format="%H %ad %s" --date=iso --after="[start]"
76
-
77
- # Change failure rate: đếm commits có message chứa "fix", "hotfix", "revert"
78
- git log --oneline --after="[start]" | grep -iE "(hotfix|revert|fix:)" | wc -l
79
-
80
- # MTTR: thời gian từ "fix commit" đến "hotfix commit" liền sau (nếu có)
81
- ```
82
-
83
- Xếp loại theo DORA elite benchmarks: Deployment Frequency (daily), Lead Time (<1h), MTTR (<1h), Change Failure Rate (<5%).
84
-
85
- ## Tạo Report (Markdown + HTML)
86
-
87
- Ghi ra `{paths.reports}/dashboard-[date].md` VÀ `{paths.reports}/dashboard-[date].html`:
88
-
89
- ```markdown
90
- # Dashboard: [Project Name]
91
- ## Period: $ARGUMENTS | Generated: [date]
92
-
93
- ---
94
-
95
- ## 🎯 Tóm Tắt Nhanh (Executive Summary)
96
-
97
- | Metric | Giá trị | Trend | Target |
98
- |--------|---------|-------|--------|
99
- | Tasks Done | X/Y | ↑ | |
100
- | Velocity | Xh/week | → | |
101
- | Blocked Tasks | X | ↓ better | 0 |
102
- | Estimation Accuracy | X% | | >80% |
103
-
104
- ---
105
-
106
- ## 📋 Trạng Thái Tasks
107
-
108
- | Task | Trạng thái | Progress | Blockers | ETA |
109
- |------|-----------|----------|----------|-----|
110
- | task-a | ✅ Done | 100% | — | — |
111
- | task-b | 🔄 In Progress | 60% | — | [date] |
112
- | task-c | ❌ Blocked | 30% | [mô tả] | TBD |
113
-
114
- ---
115
-
116
- ## 📊 DORA Metrics
117
-
118
- | Metric | Giá trị | Level | Mục tiêu |
119
- |--------|---------|-------|----------|
120
- | Deployment Frequency | X/week | 🟡 High | Elite: daily |
121
- | Lead Time | X days | 🟢 High | Elite: <1 day |
122
- | Change Failure Rate | X% | 🟢 Elite | <5% |
123
- | MTTR | X hours | 🟡 High | Elite: <1h |
124
-
125
- > Thang điểm: 🟢 Elite | 🔵 High | 🟡 Medium | 🔴 Low
126
-
127
- ---
128
-
129
- ## ⏱️ Effort & Velocity
130
-
131
- | Dev | Estimated | Actual | Accuracy | Tasks |
132
- |----|----------|--------|----------|-------|
133
- | [name] | Xh | Yh | Z% | N |
134
- | **Team** | **Xh** | **Yh** | **Z%** | **N** |
135
-
136
- **Velocity**: X story-points/sprint (or X hours/week)
137
-
138
- ---
139
-
140
- ## 🔍 Highlights
141
-
142
- ### ✅ Điểm tốt tuần này
143
- - [Achievement 1]
144
-
145
- ### ⚠️ Rủi ro cần theo dõi
146
- - [Risk 1] — Owner: [name]
147
-
148
- ### 🎯 Focus tuần tới
149
- - [Priority 1]
150
- ```
151
-
152
- ## HTML Report
153
-
154
- File HTML được generate kèm với markdown:
155
-
156
- ```html
157
- <!DOCTYPE html>
158
- <html lang="vi">
159
- <head>
160
- <meta charset="UTF-8">
161
- <title>Dashboard: [Project] — [Period]</title>
162
- <style>
163
- body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
164
- max-width: 960px; margin: 40px auto; padding: 0 20px; color: #333; }
165
- h1 { color: #1a1a2e; border-bottom: 3px solid #4361ee; padding-bottom: 8px; }
166
- h2 { color: #16213e; margin-top: 32px; }
167
- table { width: 100%; border-collapse: collapse; margin: 16px 0; }
168
- th { background: #4361ee; color: white; padding: 10px 12px; text-align: left; }
169
- td { padding: 9px 12px; border-bottom: 1px solid #e9ecef; }
170
- tr:hover { background: #f8f9fa; }
171
- .badge-elite { background: #2ecc71; color: white; padding: 2px 8px; border-radius: 12px; font-size: 12px; }
172
- .badge-high { background: #3498db; color: white; padding: 2px 8px; border-radius: 12px; font-size: 12px; }
173
- .badge-medium{ background: #f39c12; color: white; padding: 2px 8px; border-radius: 12px; font-size: 12px; }
174
- .badge-low { background: #e74c3c; color: white; padding: 2px 8px; border-radius: 12px; font-size: 12px; }
175
- .summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin: 20px 0; }
176
- .summary-card { background: #f8f9fa; border-left: 4px solid #4361ee;
177
- padding: 16px; border-radius: 4px; }
178
- .summary-card .value { font-size: 28px; font-weight: 700; color: #4361ee; }
179
- .summary-card .label { font-size: 13px; color: #666; margin-top: 4px; }
180
- footer { margin-top: 48px; font-size: 12px; color: #999; border-top: 1px solid #eee; padding-top: 12px; }
181
- </style>
182
- </head>
183
- <body>
184
- <h1>Dashboard: [Project Name]</h1>
185
- <p>Period: <strong>[period]</strong> &nbsp;|&nbsp; Generated: [date]</p>
186
-
187
- <div class="summary-grid">
188
- <div class="summary-card"><div class="value">[X/Y]</div><div class="label">Tasks Done</div></div>
189
- <div class="summary-card"><div class="value">[X]h</div><div class="label">Velocity / week</div></div>
190
- <div class="summary-card"><div class="value">[X]%</div><div class="label">Est. Accuracy</div></div>
191
- <div class="summary-card"><div class="value">[X]</div><div class="label">Blocked Tasks</div></div>
192
- </div>
193
-
194
- <!-- Tasks table, DORA table, Effort table — populate từ data thu thập -->
195
- [CONTENT_PLACEHOLDER]
196
-
197
- <footer>Generated by dv-workflow-kit &nbsp;|&nbsp; <a href="../.dw/tasks/">Task Docs</a></footer>
198
- </body>
199
- </html>
200
- ```
201
-
202
- Điền `[CONTENT_PLACEHOLDER]` với các bảng HTML tương ứng với nội dung markdown report.
203
-
204
- ## Lưu & Thông Báo
205
-
206
- Sau khi tạo:
207
- - Thông báo đường dẫn: `{paths.reports}/dashboard-[date].md` và `.html`
208
- - Tóm tắt 3-5 bullets cho PM đọc nhanh
209
- - Gợi ý: "Mở file .html trong browser để xem report đẹp hơn. Share .md qua Slack/email."
1
+ ---
2
+ name: dw:dashboard
3
+ description: "Tạo báo cáo tổng hợp cho PM: trạng thái tasks, metrics DORA, effort tracking, velocity. Ghi ra file report để share."
4
+ argument-hint: "[sprint-name | period: last-week | last-month | all]"
5
+ allowed-tools:
6
+ - Read
7
+ - Glob
8
+ - Grep
9
+ - "Bash(git log *)"
10
+ - "Bash(git diff *)"
11
+ - "Bash(ls *)"
12
+ ---
13
+
14
+ # PM Dashboard — Báo Cáo Dự Án
15
+
16
+ Period: **$ARGUMENTS**
17
+
18
+ ## Đọc Config
19
+
20
+ Đọc `.dw/config/dw.config.yml`:
21
+ - `paths.tasks` → location task docs
22
+ - `tracking.log_work` → có data effort tracking không
23
+ - `workflow.default_depth` → level of reporting detail
24
+
25
+ ## Thu Thập Dữ Liệu
26
+
27
+ ### 1. Tasks Overview
28
+ ```bash
29
+ ls {paths.tasks}/ # danh sách tasks
30
+ ```
31
+
32
+ Đọc từng `*-progress.md` để lấy:
33
+ - Trạng thái (Not Started / In Progress / Blocked / Done)
34
+ - Subtasks done/total
35
+ - Blockers hiện tại
36
+
37
+ ### 2. Git Metrics (DORA)
38
+ ```bash
39
+ # Commits trong period
40
+ git log --oneline --after="[start-date]" --before="[end-date]"
41
+
42
+ # Lead time: time from first commit to merge
43
+ git log --format="%H %ad" --date=short
44
+
45
+ # Frequency
46
+ git log --format="%ad" --date=short | sort | uniq -c
47
+ ```
48
+
49
+ ### 3. Effort Data
50
+ Đọc `{.dw/metrics}/effort-log.json` nếu có.
51
+
52
+ ### 4. Quality Metrics
53
+ Đọc review reports (nếu có) để lấy:
54
+ - Critical issues found/fixed
55
+ - Test coverage trend
56
+
57
+ ## Tính DORA Metrics
58
+
59
+ ```
60
+ Deployment Frequency = commits merged / working days
61
+ Lead Time = avg(merge_date - first_commit_date) per feature
62
+ Change Failure Rate = (hotfixes + rollbacks) / total deploys × 100%
63
+ MTTR = avg time from incident_detected to resolved
64
+ ```
65
+
66
+ So sánh với thresholds trong config và xếp loại: Elite / High / Medium / Low.
67
+
68
+ ## Tính DORA Tự Động Từ Git
69
+
70
+ ```bash
71
+ # Deployment frequency (commits/merges per day trong period)
72
+ git log --oneline --after="[start]" --before="[end]" | wc -l
73
+
74
+ # Lead time: trung bình từ commit đầu đến commit cuối của mỗi feature branch
75
+ git log --format="%H %ad %s" --date=iso --after="[start]"
76
+
77
+ # Change failure rate: đếm commits có message chứa "fix", "hotfix", "revert"
78
+ git log --oneline --after="[start]" | grep -iE "(hotfix|revert|fix:)" | wc -l
79
+
80
+ # MTTR: thời gian từ "fix commit" đến "hotfix commit" liền sau (nếu có)
81
+ ```
82
+
83
+ Xếp loại theo DORA elite benchmarks: Deployment Frequency (daily), Lead Time (<1h), MTTR (<1h), Change Failure Rate (<5%).
84
+
85
+ ## Tạo Report (Markdown + HTML)
86
+
87
+ Ghi ra `{paths.reports}/dashboard-[date].md` VÀ `{paths.reports}/dashboard-[date].html`:
88
+
89
+ ```markdown
90
+ # Dashboard: [Project Name]
91
+ ## Period: $ARGUMENTS | Generated: [date]
92
+
93
+ ---
94
+
95
+ ## 🎯 Tóm Tắt Nhanh (Executive Summary)
96
+
97
+ | Metric | Giá trị | Trend | Target |
98
+ |--------|---------|-------|--------|
99
+ | Tasks Done | X/Y | ↑ | |
100
+ | Velocity | Xh/week | → | |
101
+ | Blocked Tasks | X | ↓ better | 0 |
102
+ | Estimation Accuracy | X% | | >80% |
103
+
104
+ ---
105
+
106
+ ## 📋 Trạng Thái Tasks
107
+
108
+ | Task | Trạng thái | Progress | Blockers | ETA |
109
+ |------|-----------|----------|----------|-----|
110
+ | task-a | ✅ Done | 100% | — | — |
111
+ | task-b | 🔄 In Progress | 60% | — | [date] |
112
+ | task-c | ❌ Blocked | 30% | [mô tả] | TBD |
113
+
114
+ ---
115
+
116
+ ## 📊 DORA Metrics
117
+
118
+ | Metric | Giá trị | Level | Mục tiêu |
119
+ |--------|---------|-------|----------|
120
+ | Deployment Frequency | X/week | 🟡 High | Elite: daily |
121
+ | Lead Time | X days | 🟢 High | Elite: <1 day |
122
+ | Change Failure Rate | X% | 🟢 Elite | <5% |
123
+ | MTTR | X hours | 🟡 High | Elite: <1h |
124
+
125
+ > Thang điểm: 🟢 Elite | 🔵 High | 🟡 Medium | 🔴 Low
126
+
127
+ ---
128
+
129
+ ## ⏱️ Effort & Velocity
130
+
131
+ | Dev | Estimated | Actual | Accuracy | Tasks |
132
+ |----|----------|--------|----------|-------|
133
+ | [name] | Xh | Yh | Z% | N |
134
+ | **Team** | **Xh** | **Yh** | **Z%** | **N** |
135
+
136
+ **Velocity**: X story-points/sprint (or X hours/week)
137
+
138
+ ---
139
+
140
+ ## 🔍 Highlights
141
+
142
+ ### ✅ Điểm tốt tuần này
143
+ - [Achievement 1]
144
+
145
+ ### ⚠️ Rủi ro cần theo dõi
146
+ - [Risk 1] — Owner: [name]
147
+
148
+ ### 🎯 Focus tuần tới
149
+ - [Priority 1]
150
+ ```
151
+
152
+ ## HTML Report
153
+
154
+ File HTML được generate kèm với markdown:
155
+
156
+ ```html
157
+ <!DOCTYPE html>
158
+ <html lang="vi">
159
+ <head>
160
+ <meta charset="UTF-8">
161
+ <title>Dashboard: [Project] — [Period]</title>
162
+ <style>
163
+ body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
164
+ max-width: 960px; margin: 40px auto; padding: 0 20px; color: #333; }
165
+ h1 { color: #1a1a2e; border-bottom: 3px solid #4361ee; padding-bottom: 8px; }
166
+ h2 { color: #16213e; margin-top: 32px; }
167
+ table { width: 100%; border-collapse: collapse; margin: 16px 0; }
168
+ th { background: #4361ee; color: white; padding: 10px 12px; text-align: left; }
169
+ td { padding: 9px 12px; border-bottom: 1px solid #e9ecef; }
170
+ tr:hover { background: #f8f9fa; }
171
+ .badge-elite { background: #2ecc71; color: white; padding: 2px 8px; border-radius: 12px; font-size: 12px; }
172
+ .badge-high { background: #3498db; color: white; padding: 2px 8px; border-radius: 12px; font-size: 12px; }
173
+ .badge-medium{ background: #f39c12; color: white; padding: 2px 8px; border-radius: 12px; font-size: 12px; }
174
+ .badge-low { background: #e74c3c; color: white; padding: 2px 8px; border-radius: 12px; font-size: 12px; }
175
+ .summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin: 20px 0; }
176
+ .summary-card { background: #f8f9fa; border-left: 4px solid #4361ee;
177
+ padding: 16px; border-radius: 4px; }
178
+ .summary-card .value { font-size: 28px; font-weight: 700; color: #4361ee; }
179
+ .summary-card .label { font-size: 13px; color: #666; margin-top: 4px; }
180
+ footer { margin-top: 48px; font-size: 12px; color: #999; border-top: 1px solid #eee; padding-top: 12px; }
181
+ </style>
182
+ </head>
183
+ <body>
184
+ <h1>Dashboard: [Project Name]</h1>
185
+ <p>Period: <strong>[period]</strong> &nbsp;|&nbsp; Generated: [date]</p>
186
+
187
+ <div class="summary-grid">
188
+ <div class="summary-card"><div class="value">[X/Y]</div><div class="label">Tasks Done</div></div>
189
+ <div class="summary-card"><div class="value">[X]h</div><div class="label">Velocity / week</div></div>
190
+ <div class="summary-card"><div class="value">[X]%</div><div class="label">Est. Accuracy</div></div>
191
+ <div class="summary-card"><div class="value">[X]</div><div class="label">Blocked Tasks</div></div>
192
+ </div>
193
+
194
+ <!-- Tasks table, DORA table, Effort table — populate từ data thu thập -->
195
+ [CONTENT_PLACEHOLDER]
196
+
197
+ <footer>Generated by dv-workflow-kit &nbsp;|&nbsp; <a href="../.dw/tasks/">Task Docs</a></footer>
198
+ </body>
199
+ </html>
200
+ ```
201
+
202
+ Điền `[CONTENT_PLACEHOLDER]` với các bảng HTML tương ứng với nội dung markdown report.
203
+
204
+ ## Lưu & Thông Báo
205
+
206
+ Sau khi tạo:
207
+ - Thông báo đường dẫn: `{paths.reports}/dashboard-[date].md` và `.html`
208
+ - Tóm tắt 3-5 bullets cho PM đọc nhanh
209
+ - Gợi ý: "Mở file .html trong browser để xem report đẹp hơn. Share .md qua Slack/email."
@@ -1,97 +1,97 @@
1
- ---
2
- name: dw-debug
3
- description: "Debug có hệ thống theo quy trình Investigate → Diagnose → Fix. Dùng khi gặp lỗi, test fail, hoặc behavior bất thường."
4
- argument-hint: "[mô tả vấn đề]"
5
- ---
6
-
7
- # Debug Có Hệ Thống
8
-
9
- Vấn đề: **$ARGUMENTS**
10
-
11
- ## Đọc Config
12
-
13
- Đọc `.dw/config/dw.config.yml` → `paths.tasks`, `workflow.default_depth`.
14
-
15
- ---
16
-
17
- ## Phase 1: INVESTIGATE — Thu thập thông tin
18
-
19
- ### 1.1 Xác định symptoms
20
- - Error message đầy đủ là gì? (stack trace, log)
21
- - Reproduction steps: làm gì để trigger lỗi?
22
- - Xảy ra lần đầu khi nào? Có gì thay đổi gần đây?
23
- - Tần suất: always / flaky / one-time?
24
- - Môi trường: dev / staging / production?
25
-
26
- ### 1.2 Thu thập evidence
27
- ```bash
28
- # Git: thay đổi gần đây
29
- git log --oneline -10
30
- git diff HEAD~3
31
-
32
- # Tìm error trong code
33
- grep -r "[error keyword]" --include="*.ts"
34
- ```
35
-
36
- ### 1.3 Xác định phạm vi
37
- - Feature nào bị ảnh hưởng?
38
- - Chỉ 1 user hay tất cả?
39
- - Data cụ thể nào trigger lỗi?
40
-
41
- ---
42
-
43
- ## Phase 2: DIAGNOSE — Tìm root cause
44
-
45
- ### 2.1 Đặt giả thuyết
46
- Liệt kê 2-4 giả thuyết có thể về nguyên nhân, ưu tiên từ khả năng cao nhất.
47
-
48
- ### 2.2 Kiểm chứng từng giả thuyết
49
- - Đọc code liên quan
50
- - Trace data flow
51
- - Kiểm tra config, environment variables
52
- - Xem test coverage có bỏ sót case này không
53
-
54
- ### 2.3 Thu hẹp phạm vi
55
- - Loại trừ dần từng giả thuyết
56
- - Tìm exact line/function gây lỗi
57
- - Xác định root cause (không phải symptom)
58
-
59
- ---
60
-
61
- ## Phase 3: FIX — Sửa và verify
62
-
63
- ### 3.1 Implement fix tối thiểu
64
- - Fix đúng root cause, không phải workaround
65
- - Không thay đổi scope ngoài bug fix
66
-
67
- ### 3.2 Viết regression test TRƯỚC khi fix
68
- ```
69
- // Test phải FAIL trước fix, PASS sau fix
70
- test("should handle [edge case that caused bug]", () => { ... })
71
- ```
72
-
73
- ### 3.3 Verify
74
- - Test mới pass
75
- - Existing tests không bị break
76
- - Manual verify reproduction steps
77
-
78
- ### 3.4 Ghi lại
79
-
80
- ```markdown
81
- ## Debug Report
82
-
83
- **Root Cause**: [giải thích ngắn gọn]
84
- **Fix**: [mô tả thay đổi]
85
- **Prevention**: [làm sao tránh lặp lại]
86
- **Test added**: [tên test]
87
- ```
88
-
89
- ---
90
-
91
- ## Khi Bị Bí
92
-
93
- Nếu sau 2 giả thuyết vẫn không tìm được root cause:
94
- 1. Mô rộng hơn: xem toàn bộ data flow
95
- 2. Thêm logging tạm thời để narrow down
96
- 3. Bisect git: `git bisect` để tìm commit gây lỗi
97
- 4. Hỏi: trình bày findings cho user, propose next steps
1
+ ---
2
+ name: dw:debug
3
+ description: "Debug có hệ thống theo quy trình Investigate → Diagnose → Fix. Dùng khi gặp lỗi, test fail, hoặc behavior bất thường."
4
+ argument-hint: "[mô tả vấn đề]"
5
+ ---
6
+
7
+ # Debug Có Hệ Thống
8
+
9
+ Vấn đề: **$ARGUMENTS**
10
+
11
+ ## Đọc Config
12
+
13
+ Đọc `.dw/config/dw.config.yml` → `paths.tasks`, `workflow.default_depth`.
14
+
15
+ ---
16
+
17
+ ## Phase 1: INVESTIGATE — Thu thập thông tin
18
+
19
+ ### 1.1 Xác định symptoms
20
+ - Error message đầy đủ là gì? (stack trace, log)
21
+ - Reproduction steps: làm gì để trigger lỗi?
22
+ - Xảy ra lần đầu khi nào? Có gì thay đổi gần đây?
23
+ - Tần suất: always / flaky / one-time?
24
+ - Môi trường: dev / staging / production?
25
+
26
+ ### 1.2 Thu thập evidence
27
+ ```bash
28
+ # Git: thay đổi gần đây
29
+ git log --oneline -10
30
+ git diff HEAD~3
31
+
32
+ # Tìm error trong code
33
+ grep -r "[error keyword]" --include="*.ts"
34
+ ```
35
+
36
+ ### 1.3 Xác định phạm vi
37
+ - Feature nào bị ảnh hưởng?
38
+ - Chỉ 1 user hay tất cả?
39
+ - Data cụ thể nào trigger lỗi?
40
+
41
+ ---
42
+
43
+ ## Phase 2: DIAGNOSE — Tìm root cause
44
+
45
+ ### 2.1 Đặt giả thuyết
46
+ Liệt kê 2-4 giả thuyết có thể về nguyên nhân, ưu tiên từ khả năng cao nhất.
47
+
48
+ ### 2.2 Kiểm chứng từng giả thuyết
49
+ - Đọc code liên quan
50
+ - Trace data flow
51
+ - Kiểm tra config, environment variables
52
+ - Xem test coverage có bỏ sót case này không
53
+
54
+ ### 2.3 Thu hẹp phạm vi
55
+ - Loại trừ dần từng giả thuyết
56
+ - Tìm exact line/function gây lỗi
57
+ - Xác định root cause (không phải symptom)
58
+
59
+ ---
60
+
61
+ ## Phase 3: FIX — Sửa và verify
62
+
63
+ ### 3.1 Implement fix tối thiểu
64
+ - Fix đúng root cause, không phải workaround
65
+ - Không thay đổi scope ngoài bug fix
66
+
67
+ ### 3.2 Viết regression test TRƯỚC khi fix
68
+ ```
69
+ // Test phải FAIL trước fix, PASS sau fix
70
+ test("should handle [edge case that caused bug]", () => { ... })
71
+ ```
72
+
73
+ ### 3.3 Verify
74
+ - Test mới pass
75
+ - Existing tests không bị break
76
+ - Manual verify reproduction steps
77
+
78
+ ### 3.4 Ghi lại
79
+
80
+ ```markdown
81
+ ## Debug Report
82
+
83
+ **Root Cause**: [giải thích ngắn gọn]
84
+ **Fix**: [mô tả thay đổi]
85
+ **Prevention**: [làm sao tránh lặp lại]
86
+ **Test added**: [tên test]
87
+ ```
88
+
89
+ ---
90
+
91
+ ## Khi Bị Bí
92
+
93
+ Nếu sau 2 giả thuyết vẫn không tìm được root cause:
94
+ 1. Mô rộng hơn: xem toàn bộ data flow
95
+ 2. Thêm logging tạm thời để narrow down
96
+ 3. Bisect git: `git bisect` để tìm commit gây lỗi
97
+ 4. Hỏi: trình bày findings cho user, propose next steps