dw-kit 1.3.0 → 1.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.dw/core/ROLES.md CHANGED
@@ -1,257 +1,257 @@
1
- <!-- core-version: 1.0 -->
2
-
3
- # Team Roles & Authority
4
-
5
- > **Nguyên tắc**: Roles = capabilities, không phải hierarchy.
6
- > Config `team.roles` quyết định phases nào available, không phải quality tier.
7
-
8
- ---
9
-
10
- ## Role Overview
11
-
12
- | Role | Ký hiệu config | Core responsibility | Decision authority |
13
- |------|----------------|--------------------|--------------------|
14
- | Developer | `dev` | Implementation, testing | Code-level decisions |
15
- | Tech Lead | `techlead` | Architecture, code standards | Architecture decisions, plan approval |
16
- | Business Analyst | `ba` | Requirements, user stories | Requirements sign-off |
17
- | QC Engineer | `qc` | Test planning, quality verification | QA sign-off (Layer 4) |
18
- | Product Manager | `pm` | Progress visibility, metrics | Sprint planning, backlog priority |
19
-
20
- > `dev` luôn required. Các roles khác là optional — không có thì phase đó gracefully degrade.
21
-
22
- ---
23
-
24
- ## Developer (`dev`)
25
-
26
- **Trách nhiệm chính**: Research → Plan → Execute → Commit
27
-
28
- ### Phases Developer Owns
29
-
30
- | Phase | Responsibility |
31
- |-------|---------------|
32
- | Initialize | Tạo task docs, scope assessment |
33
- | Understand | Codebase research, context gathering |
34
- | Plan | Solution design, subtask breakdown |
35
- | Execute | Implementation, TDD, subtask commits |
36
- | Verify | Self-review (Layer 1), automated gates (Layer 2) |
37
- | Close | Commit, effort log, handoff |
38
-
39
- ### Decision Authority
40
-
41
- - Code implementation decisions
42
- - Library/dependency choices (minor)
43
- - Subtask ordering và approach (trong scope của plan approved)
44
- - **DỪNG và hỏi khi**: architecture change, API contract change, scope expansion
45
-
46
- ### Best Practices
47
-
48
- - Commit nhỏ, thường xuyên (mỗi subtask = 1 commit)
49
- - Update progress file sau mỗi subtask
50
- - Không implement ngoài scope plan đã approve
51
- - Phát hiện giả định sai → ghi Changelog + hỏi TL trước khi tiếp tục
52
-
53
- ---
54
-
55
- ## Tech Lead (`techlead`)
56
-
57
- **Trách nhiệm chính**: Architecture quality, standards enforcement, plan approval
58
-
59
- ### Phases TL Owns
60
-
61
- | Phase | Responsibility |
62
- |-------|---------------|
63
- | Plan | Architecture review, approve plan trước Execute |
64
- | Execute | Unblock architecture decisions during implementation |
65
- | Verify | Code review (Layer 3 — architecture focus) |
66
- | Close | Final technical sign-off |
67
-
68
- ### Decision Authority
69
-
70
- - Architecture decisions (service boundaries, patterns, data models)
71
- - Plan approval: **explicit gate** — Execute không bắt đầu khi chưa có TL approve
72
- - A/B testing resolution: TL chọn approach khi hai approaches không rõ ưu/nhược
73
- - Technical debt acknowledgment: quyết định "acceptable" hay "must fix"
74
-
75
- ### Architecture Review Checklist
76
-
77
- ```
78
- [ ] Approach consistent với codebase patterns?
79
- [ ] Scalability implications acceptable?
80
- [ ] Security design đúng?
81
- [ ] API contract backward compatible (hoặc migration plan có)?
82
- [ ] Subtask breakdown hợp lý? Dependencies đúng?
83
- [ ] Risks identified và có mitigation?
84
- ```
85
-
86
- ### TL không có?
87
-
88
- - Plan vẫn proceed nhưng developer self-review architecture decisions
89
- - Ghi rõ trong plan: "Architecture decision by dev (no TL review)"
90
- - Architecture decisions nên bảo thủ hơn khi không có TL
91
-
92
- ---
93
-
94
- ## Business Analyst (`ba`)
95
-
96
- **Trách nhiệm chính**: Requirements clarity, user stories, acceptance criteria
97
-
98
- ### Phases BA Owns
99
-
100
- | Phase | Responsibility |
101
- |-------|---------------|
102
- | Initialize | Requirements gathering, user stories |
103
- | Plan | Review subtask acceptance criteria |
104
- | Verify | Acceptance criteria verification |
105
-
106
- ### Decision Authority
107
-
108
- - Requirements sign-off: "dev builds the right thing"
109
- - Scope boundary: in-scope vs out-of-scope
110
- - Acceptance criteria: testable, specific, agreed
111
-
112
- ### Requirements Output Format
113
-
114
- ```markdown
115
- ## User Story
116
- As a [role], I want [goal] so that [benefit].
117
-
118
- ## Acceptance Criteria
119
- Given [precondition]
120
- When [action]
121
- Then [outcome]
122
-
123
- ## Out of Scope
124
- - [explicitly excluded items]
125
-
126
- ## Edge Cases to Handle
127
- - [edge case 1]
128
- - [edge case 2]
129
- ```
130
-
131
- ### BA không có?
132
-
133
- - Developer writes requirements từ conversation với stakeholder
134
- - Requirements review là developer + TL (không có independent BA)
135
- - Risk cao hơn về misunderstood requirements — tăng frequency of check-ins
136
-
137
- ---
138
-
139
- ## QC Engineer (`qc`)
140
-
141
- **Trách nhiệm chính**: Test planning, independent quality verification
142
-
143
- ### Phases QC Owns
144
-
145
- | Phase | Responsibility |
146
- |-------|---------------|
147
- | Plan | Test plan tạo song song với dev plan |
148
- | Verify | Execute test plan, Layer 4 sign-off |
149
-
150
- ### Decision Authority
151
-
152
- - QA sign-off: **explicit gate** cho `thorough` depth — không thể self-approve
153
- - Bug severity classification
154
- - Regression scope: gì cần test lại sau change
155
-
156
- ### Test Plan Structure
157
-
158
- ```markdown
159
- ## Test Cases
160
- ### TC-1: [Test case name]
161
- - **Given**: [precondition]
162
- - **When**: [action]
163
- - **Then**: [expected result]
164
- - **Priority**: P1/P2/P3
165
-
166
- ## Regression Checklist
167
- - [ ] [Feature 1 không bị ảnh hưởng]
168
- - [ ] [Feature 2 không bị ảnh hưởng]
169
-
170
- ## Security Checklist (nếu applicable)
171
- - [ ] Input validation
172
- - [ ] Auth/authz checks
173
- - [ ] No data exposure
174
-
175
- ## Performance Checklist (nếu applicable)
176
- - [ ] Response time acceptable
177
- - [ ] No N+1 queries introduced
178
- ```
179
-
180
- ### QC không có?
181
-
182
- - Developer tự execute test plan (nếu có) hoặc manual verification
183
- - Layer 4 QA sign-off skip — nhưng automated gates (Layer 4a) vẫn chạy
184
- - Risk cao hơn về undiscovered bugs
185
-
186
- ---
187
-
188
- ## Product Manager (`pm`)
189
-
190
- **Trách nhiệm chính**: Progress visibility, metrics, sprint planning
191
-
192
- ### Phases PM Owns
193
-
194
- | Phase | Responsibility |
195
- |-------|---------------|
196
- | Initialize | Sprint planning, priority |
197
- | Close | Sprint review, velocity tracking |
198
- | Standalone: Reports | Dashboard generation |
199
-
200
- ### PM View
201
-
202
- PM không cần đọc code — PM đọc:
203
- - Progress files (status per subtask)
204
- - Dashboard reports (velocity, metrics)
205
- - Sprint review summaries
206
-
207
- ### Dashboard Metrics
208
-
209
- | Metric | Source | Update frequency |
210
- |--------|--------|-----------------|
211
- | Tasks: done/in-progress/blocked | Progress files | Real-time |
212
- | Velocity | Closed tasks per sprint | Per sprint |
213
- | Estimate accuracy | Estimate vs actual | Per task |
214
- | DORA: deployment frequency | Git history | Per release |
215
- | DORA: lead time | Task start → deploy | Per release |
216
-
217
- ---
218
-
219
- ## Multi-Role Workflow
220
-
221
- Full team workflow (tất cả roles):
222
-
223
- ```
224
- BA: /dw-requirements → requirements doc + user stories
225
-
226
- TL: /dw-arch-review → architecture decision + approve
227
-
228
- Dev: /dw-task-init → task docs
229
- Dev: /dw-research → codebase analysis
230
- Dev+QC: /dw-plan → dev plan + test plan (parallel)
231
-
232
- TL approve plan
233
-
234
- Dev: /dw-execute → TDD implementation, commits
235
-
236
- TL: /dw-review → architecture + code review
237
-
238
- QC: manual/auto testing → Layer 4 verification
239
-
240
- Dev: /dw-commit → pre-commit gates
241
-
242
- PM: /dw-dashboard → visibility, metrics
243
- ```
244
-
245
- Không phải mọi task cần full chain. `default_depth` + available roles quyết định.
246
-
247
- ---
248
-
249
- ## Role-Depth Matrix
250
-
251
- | Role | Quick | Standard | Thorough |
252
- |------|-------|----------|----------|
253
- | dev | required | required | required |
254
- | techlead | not needed | arch decisions only | full review + approval |
255
- | ba | not needed | requirements check | full requirements |
256
- | qc | not needed | not needed | full test plan + sign-off |
257
- | pm | not needed | optional | dashboard |
1
+ <!-- core-version: 1.0 -->
2
+
3
+ # Team Roles & Authority
4
+
5
+ > **Nguyên tắc**: Roles = capabilities, không phải hierarchy.
6
+ > Config `team.roles` quyết định phases nào available, không phải quality tier.
7
+
8
+ ---
9
+
10
+ ## Role Overview
11
+
12
+ | Role | Ký hiệu config | Core responsibility | Decision authority |
13
+ |------|----------------|--------------------|--------------------|
14
+ | Developer | `dev` | Implementation, testing | Code-level decisions |
15
+ | Tech Lead | `techlead` | Architecture, code standards | Architecture decisions, plan approval |
16
+ | Business Analyst | `ba` | Requirements, user stories | Requirements sign-off |
17
+ | QC Engineer | `qc` | Test planning, quality verification | QA sign-off (Layer 4) |
18
+ | Product Manager | `pm` | Progress visibility, metrics | Sprint planning, backlog priority |
19
+
20
+ > `dev` luôn required. Các roles khác là optional — không có thì phase đó gracefully degrade.
21
+
22
+ ---
23
+
24
+ ## Developer (`dev`)
25
+
26
+ **Trách nhiệm chính**: Research → Plan → Execute → Commit
27
+
28
+ ### Phases Developer Owns
29
+
30
+ | Phase | Responsibility |
31
+ |-------|---------------|
32
+ | Initialize | Tạo task docs, scope assessment |
33
+ | Understand | Codebase research, context gathering |
34
+ | Plan | Solution design, subtask breakdown |
35
+ | Execute | Implementation, TDD, subtask commits |
36
+ | Verify | Self-review (Layer 1), automated gates (Layer 2) |
37
+ | Close | Commit, effort log, handoff |
38
+
39
+ ### Decision Authority
40
+
41
+ - Code implementation decisions
42
+ - Library/dependency choices (minor)
43
+ - Subtask ordering và approach (trong scope của plan approved)
44
+ - **DỪNG và hỏi khi**: architecture change, API contract change, scope expansion
45
+
46
+ ### Best Practices
47
+
48
+ - Commit nhỏ, thường xuyên (mỗi subtask = 1 commit)
49
+ - Update progress file sau mỗi subtask
50
+ - Không implement ngoài scope plan đã approve
51
+ - Phát hiện giả định sai → ghi Changelog + hỏi TL trước khi tiếp tục
52
+
53
+ ---
54
+
55
+ ## Tech Lead (`techlead`)
56
+
57
+ **Trách nhiệm chính**: Architecture quality, standards enforcement, plan approval
58
+
59
+ ### Phases TL Owns
60
+
61
+ | Phase | Responsibility |
62
+ |-------|---------------|
63
+ | Plan | Architecture review, approve plan trước Execute |
64
+ | Execute | Unblock architecture decisions during implementation |
65
+ | Verify | Code review (Layer 3 — architecture focus) |
66
+ | Close | Final technical sign-off |
67
+
68
+ ### Decision Authority
69
+
70
+ - Architecture decisions (service boundaries, patterns, data models)
71
+ - Plan approval: **explicit gate** — Execute không bắt đầu khi chưa có TL approve
72
+ - A/B testing resolution: TL chọn approach khi hai approaches không rõ ưu/nhược
73
+ - Technical debt acknowledgment: quyết định "acceptable" hay "must fix"
74
+
75
+ ### Architecture Review Checklist
76
+
77
+ ```
78
+ [ ] Approach consistent với codebase patterns?
79
+ [ ] Scalability implications acceptable?
80
+ [ ] Security design đúng?
81
+ [ ] API contract backward compatible (hoặc migration plan có)?
82
+ [ ] Subtask breakdown hợp lý? Dependencies đúng?
83
+ [ ] Risks identified và có mitigation?
84
+ ```
85
+
86
+ ### TL không có?
87
+
88
+ - Plan vẫn proceed nhưng developer self-review architecture decisions
89
+ - Ghi rõ trong plan: "Architecture decision by dev (no TL review)"
90
+ - Architecture decisions nên bảo thủ hơn khi không có TL
91
+
92
+ ---
93
+
94
+ ## Business Analyst (`ba`)
95
+
96
+ **Trách nhiệm chính**: Requirements clarity, user stories, acceptance criteria
97
+
98
+ ### Phases BA Owns
99
+
100
+ | Phase | Responsibility |
101
+ |-------|---------------|
102
+ | Initialize | Requirements gathering, user stories |
103
+ | Plan | Review subtask acceptance criteria |
104
+ | Verify | Acceptance criteria verification |
105
+
106
+ ### Decision Authority
107
+
108
+ - Requirements sign-off: "dev builds the right thing"
109
+ - Scope boundary: in-scope vs out-of-scope
110
+ - Acceptance criteria: testable, specific, agreed
111
+
112
+ ### Requirements Output Format
113
+
114
+ ```markdown
115
+ ## User Story
116
+ As a [role], I want [goal] so that [benefit].
117
+
118
+ ## Acceptance Criteria
119
+ Given [precondition]
120
+ When [action]
121
+ Then [outcome]
122
+
123
+ ## Out of Scope
124
+ - [explicitly excluded items]
125
+
126
+ ## Edge Cases to Handle
127
+ - [edge case 1]
128
+ - [edge case 2]
129
+ ```
130
+
131
+ ### BA không có?
132
+
133
+ - Developer writes requirements từ conversation với stakeholder
134
+ - Requirements review là developer + TL (không có independent BA)
135
+ - Risk cao hơn về misunderstood requirements — tăng frequency of check-ins
136
+
137
+ ---
138
+
139
+ ## QC Engineer (`qc`)
140
+
141
+ **Trách nhiệm chính**: Test planning, independent quality verification
142
+
143
+ ### Phases QC Owns
144
+
145
+ | Phase | Responsibility |
146
+ |-------|---------------|
147
+ | Plan | Test plan tạo song song với dev plan |
148
+ | Verify | Execute test plan, Layer 4 sign-off |
149
+
150
+ ### Decision Authority
151
+
152
+ - QA sign-off: **explicit gate** cho `thorough` depth — không thể self-approve
153
+ - Bug severity classification
154
+ - Regression scope: gì cần test lại sau change
155
+
156
+ ### Test Plan Structure
157
+
158
+ ```markdown
159
+ ## Test Cases
160
+ ### TC-1: [Test case name]
161
+ - **Given**: [precondition]
162
+ - **When**: [action]
163
+ - **Then**: [expected result]
164
+ - **Priority**: P1/P2/P3
165
+
166
+ ## Regression Checklist
167
+ - [ ] [Feature 1 không bị ảnh hưởng]
168
+ - [ ] [Feature 2 không bị ảnh hưởng]
169
+
170
+ ## Security Checklist (nếu applicable)
171
+ - [ ] Input validation
172
+ - [ ] Auth/authz checks
173
+ - [ ] No data exposure
174
+
175
+ ## Performance Checklist (nếu applicable)
176
+ - [ ] Response time acceptable
177
+ - [ ] No N+1 queries introduced
178
+ ```
179
+
180
+ ### QC không có?
181
+
182
+ - Developer tự execute test plan (nếu có) hoặc manual verification
183
+ - Layer 4 QA sign-off skip — nhưng automated gates (Layer 4a) vẫn chạy
184
+ - Risk cao hơn về undiscovered bugs
185
+
186
+ ---
187
+
188
+ ## Product Manager (`pm`)
189
+
190
+ **Trách nhiệm chính**: Progress visibility, metrics, sprint planning
191
+
192
+ ### Phases PM Owns
193
+
194
+ | Phase | Responsibility |
195
+ |-------|---------------|
196
+ | Initialize | Sprint planning, priority |
197
+ | Close | Sprint review, velocity tracking |
198
+ | Standalone: Reports | Dashboard generation |
199
+
200
+ ### PM View
201
+
202
+ PM không cần đọc code — PM đọc:
203
+ - Progress files (status per subtask)
204
+ - Dashboard reports (velocity, metrics)
205
+ - Sprint review summaries
206
+
207
+ ### Dashboard Metrics
208
+
209
+ | Metric | Source | Update frequency |
210
+ |--------|--------|-----------------|
211
+ | Tasks: done/in-progress/blocked | Progress files | Real-time |
212
+ | Velocity | Closed tasks per sprint | Per sprint |
213
+ | Estimate accuracy | Estimate vs actual | Per task |
214
+ | DORA: deployment frequency | Git history | Per release |
215
+ | DORA: lead time | Task start → deploy | Per release |
216
+
217
+ ---
218
+
219
+ ## Multi-Role Workflow
220
+
221
+ Full team workflow (tất cả roles):
222
+
223
+ ```
224
+ BA: /dw:requirements → requirements doc + user stories
225
+
226
+ TL: /dw:arch-review → architecture decision + approve
227
+
228
+ Dev: /dw:task-init → task docs
229
+ Dev: /dw:research → codebase analysis
230
+ Dev+QC: /dw:plan → dev plan + test plan (parallel)
231
+
232
+ TL approve plan
233
+
234
+ Dev: /dw:execute → TDD implementation, commits
235
+
236
+ TL: /dw:review → architecture + code review
237
+
238
+ QC: manual/auto testing → Layer 4 verification
239
+
240
+ Dev: /dw:commit → pre-commit gates
241
+
242
+ PM: /dw:dashboard → visibility, metrics
243
+ ```
244
+
245
+ Không phải mọi task cần full chain. `default_depth` + available roles quyết định.
246
+
247
+ ---
248
+
249
+ ## Role-Depth Matrix
250
+
251
+ | Role | Quick | Standard | Thorough |
252
+ |------|-------|----------|----------|
253
+ | dev | required | required | required |
254
+ | techlead | not needed | arch decisions only | full review + approval |
255
+ | ba | not needed | requirements check | full requirements |
256
+ | qc | not needed | not needed | full test plan + sign-off |
257
+ | pm | not needed | optional | dashboard |
package/MIGRATION-v1.3.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Migration Guide — dw-kit v1.2.x → v1.3
2
2
 
3
- **Target version:** 1.3.0
4
- **Ship date:** 2026-05-12 (target)
5
- **Status:** In Progress
3
+ **Current version:** 1.3.4
4
+ **Patch chain:** 1.3.0 → 1.3.1 (task-init + retroactive emit v2) → 1.3.2 (task-doc health metric) → 1.3.3 (writer skills v1/v2 compat + docs cleanup) → 1.3.4 (/dw:plan Quick Debate)
5
+ **Status:** Shipped
6
6
 
7
7
  This guide documents all user-visible changes in v1.3. v1.3 is **fully backward compatible** with v1.2.x — existing projects continue to work. New features are opt-in.
8
8
 
@@ -17,7 +17,8 @@ This guide documents all user-visible changes in v1.3. v1.3 is **fully backward
17
17
  | ACTIVE index | `.dw/tasks/ACTIVE.md` auto-generated | New feature |
18
18
  | Telemetry | Local-only metrics in `.dw/metrics/events.jsonl` | Opt-out via `DW_NO_TELEMETRY=1` |
19
19
  | Solo preset | `dw init --preset solo` available | New option |
20
- | Skill naming | `/dw-*` may be renamed to `/dw:*` (pending harness verification) | **Potentially breaking** |
20
+ | Skill naming | `/dw-*` renamed to `/dw:*` (verified working in Claude CLI) | **Breaking** — update custom prompts |
21
+ | `/dw:plan` debate | Quick Debate (red/blue self-critique) integrated — depth-driven | v1.3.4 opt-in for standard, default for thorough |
21
22
  | Archive | 8 Done tasks moved to `.dw/tasks/archive/` in dw-kit repo itself | No user impact |
22
23
 
23
24
  ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dw-kit",
3
- "version": "1.3.0",
3
+ "version": "1.3.4",
4
4
  "description": "AI development workflow toolkit — structured, quality-assured, team-ready. From requirements to dashboard.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,5 +1,5 @@
1
1
  import { readEvents, summarize } from '../lib/telemetry.mjs';
2
- import { analyze, THRESHOLDS } from '../lib/cut-analysis.mjs';
2
+ import { analyze, analyzeTaskDocs, THRESHOLDS, TASK_DOC_THRESHOLDS } from '../lib/cut-analysis.mjs';
3
3
  import { banner, log, info, warn, ok, err } from '../lib/ui.mjs';
4
4
  import chalk from 'chalk';
5
5
 
@@ -162,4 +162,24 @@ function cutAnalysisReport(opts) {
162
162
  log(` Hook: avg_latency > ${THRESHOLDS.hook.maxAvgLatencyMs}ms OR fires/session > ${THRESHOLDS.hook.maxFiresPerSession}`);
163
163
  log('');
164
164
  info('Caveat: "devs" proxied by unique session hashes — undercounts real headcount.');
165
+
166
+ // Task doc health — invalidation trigger for 3→2 file consolidation (ADR-0001)
167
+ const td = analyzeTaskDocs(process.cwd());
168
+ if (td && td.totalTasks > 0) {
169
+ log('');
170
+ log(chalk.bold('Task Doc Health (ADR-0001 invalidation signal for 3→2 consolidation)'));
171
+ log(` Tasks total: ${td.totalTasks} (v2=${td.v2Count}, v1=${td.v1Count})`);
172
+ log(` tracking.md lines: avg=${td.avgTrackingLines} max=${td.maxTrackingLines}`);
173
+ log(` Tasks with ≥3 md files: ${td.extraFilesCount} (${td.extraFilesPct}%)`);
174
+ if (td.triggers.length === 0) {
175
+ ok('No task-doc invalidation triggers fired — 3→2 consolidation holding.');
176
+ } else {
177
+ for (const t of td.triggers) {
178
+ err(t);
179
+ }
180
+ }
181
+ log('');
182
+ info('Task doc thresholds:');
183
+ log(` avg_tracking_lines > ${TASK_DOC_THRESHOLDS.trackingLinesWarn} OR pct_tasks_with_3plus_files > ${TASK_DOC_THRESHOLDS.extraFilesPctWarn}%`);
184
+ }
165
185
  }
@@ -1,8 +1,17 @@
1
1
  // Cut Criteria Matrix — implements ADR-0001 v1.4 decision gate.
2
2
  // Consumes telemetry events, emits cut candidates with evidence.
3
3
 
4
+ import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
5
+ import { join } from 'node:path';
6
+
4
7
  const MS_PER_DAY = 24 * 60 * 60 * 1000;
5
8
 
9
+ // Task doc thresholds — invalidation triggers for 3→2 file consolidation (ADR-0001)
10
+ export const TASK_DOC_THRESHOLDS = {
11
+ trackingLinesWarn: 400, // avg tracking.md lines → reopen 3→2 decision
12
+ extraFilesPctWarn: 30, // % tasks with ≥3 md files → tasks re-growing structure
13
+ };
14
+
6
15
  // Never-cut: skills that are the workflow's load-bearing verbs.
7
16
  export const CRITICAL_SKILLS = new Set([
8
17
  'dw:flow', 'dw:task-init', 'dw:commit', 'dw:handoff',
@@ -133,6 +142,76 @@ function evaluateHook(name, events, totalSessions) {
133
142
  return { name, type: 'hook', qualify, stats: s, reasons };
134
143
  }
135
144
 
145
+ export function analyzeTaskDocs(rootDir = process.cwd()) {
146
+ const tasksDir = join(rootDir, '.dw', 'tasks');
147
+ if (!existsSync(tasksDir)) return null;
148
+
149
+ const entries = readdirSync(tasksDir).filter((name) => {
150
+ if (name === 'archive' || name === 'ACTIVE.md') return false;
151
+ try {
152
+ return statSync(join(tasksDir, name)).isDirectory();
153
+ } catch {
154
+ return false;
155
+ }
156
+ });
157
+
158
+ const tasks = [];
159
+ for (const name of entries) {
160
+ const dir = join(tasksDir, name);
161
+ let mdFiles;
162
+ try {
163
+ mdFiles = readdirSync(dir).filter((f) => f.endsWith('.md'));
164
+ } catch {
165
+ continue;
166
+ }
167
+ const hasSpec = mdFiles.includes('spec.md');
168
+ const hasTracking = mdFiles.includes('tracking.md');
169
+ const format = hasSpec && hasTracking ? 'v2' : mdFiles.some((f) => f.endsWith('-progress.md')) ? 'v1' : 'unknown';
170
+
171
+ let trackingLines = 0;
172
+ if (hasTracking) {
173
+ try {
174
+ trackingLines = readFileSync(join(dir, 'tracking.md'), 'utf8').split('\n').length;
175
+ } catch {
176
+ /* skip */
177
+ }
178
+ }
179
+
180
+ tasks.push({ name, format, mdFileCount: mdFiles.length, trackingLines });
181
+ }
182
+
183
+ const v2 = tasks.filter((t) => t.format === 'v2');
184
+ const avgTrackingLines =
185
+ v2.length > 0 ? Math.round(v2.reduce((s, t) => s + t.trackingLines, 0) / v2.length) : 0;
186
+ const maxTrackingLines = v2.length > 0 ? Math.max(...v2.map((t) => t.trackingLines)) : 0;
187
+ const extraFiles = tasks.filter((t) => t.mdFileCount >= 3);
188
+ const extraFilesPct = tasks.length > 0 ? Math.round((extraFiles.length / tasks.length) * 100) : 0;
189
+
190
+ const triggers = [];
191
+ if (avgTrackingLines > TASK_DOC_THRESHOLDS.trackingLinesWarn) {
192
+ triggers.push(
193
+ `avg_tracking_lines=${avgTrackingLines} > ${TASK_DOC_THRESHOLDS.trackingLinesWarn} — tracking.md phình → reopen 3→2 decision (ADR-0001)`
194
+ );
195
+ }
196
+ if (extraFilesPct > TASK_DOC_THRESHOLDS.extraFilesPctWarn) {
197
+ triggers.push(
198
+ `${extraFilesPct}% tasks have ≥3 md files > ${TASK_DOC_THRESHOLDS.extraFilesPctWarn}% — structure re-growing → reopen 3→2 decision (ADR-0001)`
199
+ );
200
+ }
201
+
202
+ return {
203
+ totalTasks: tasks.length,
204
+ v2Count: v2.length,
205
+ v1Count: tasks.filter((t) => t.format === 'v1').length,
206
+ avgTrackingLines,
207
+ maxTrackingLines,
208
+ extraFilesCount: extraFiles.length,
209
+ extraFilesPct,
210
+ triggers,
211
+ tasks,
212
+ };
213
+ }
214
+
136
215
  export function analyze(events) {
137
216
  const totalSessions = uniqueSessions(events);
138
217
  const totalDays = coverageDays(events);