@drafthq/draft 2.7.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 (158) hide show
  1. package/.claude-plugin/marketplace.json +38 -0
  2. package/.claude-plugin/plugin.json +26 -0
  3. package/LICENSE +21 -0
  4. package/README.md +272 -0
  5. package/bin/README.md +49 -0
  6. package/cli/bin/draft.js +13 -0
  7. package/cli/src/cli.js +113 -0
  8. package/cli/src/hosts/claude-code.js +46 -0
  9. package/cli/src/hosts/codex.js +33 -0
  10. package/cli/src/hosts/cursor.js +50 -0
  11. package/cli/src/hosts/index.js +24 -0
  12. package/cli/src/hosts/opencode.js +39 -0
  13. package/cli/src/installer.js +61 -0
  14. package/cli/src/lib/fsx.js +34 -0
  15. package/cli/src/lib/graph.js +23 -0
  16. package/cli/src/lib/log.js +32 -0
  17. package/cli/src/lib/paths.js +14 -0
  18. package/core/agents/architect.md +338 -0
  19. package/core/agents/debugger.md +193 -0
  20. package/core/agents/ops.md +104 -0
  21. package/core/agents/planner.md +158 -0
  22. package/core/agents/rca.md +314 -0
  23. package/core/agents/reviewer.md +256 -0
  24. package/core/agents/writer.md +110 -0
  25. package/core/guardrails/README.md +4 -0
  26. package/core/guardrails/code-quality.md +4 -0
  27. package/core/guardrails/dependency-triage.md +4 -0
  28. package/core/guardrails/design-norms.md +4 -0
  29. package/core/guardrails/language-standards.md +4 -0
  30. package/core/guardrails/review-checks.md +4 -0
  31. package/core/guardrails/secure-patterns.md +4 -0
  32. package/core/guardrails/security.md +4 -0
  33. package/core/guardrails.md +22 -0
  34. package/core/knowledge-base.md +127 -0
  35. package/core/methodology.md +1221 -0
  36. package/core/shared/condensation.md +224 -0
  37. package/core/shared/context-verify.md +44 -0
  38. package/core/shared/cross-skill-dispatch.md +127 -0
  39. package/core/shared/discovery-schema.md +75 -0
  40. package/core/shared/draft-context-loading.md +282 -0
  41. package/core/shared/git-report-metadata.md +106 -0
  42. package/core/shared/graph-query.md +239 -0
  43. package/core/shared/graph-usage-report.md +22 -0
  44. package/core/shared/jira-sync.md +170 -0
  45. package/core/shared/parallel-analysis.md +386 -0
  46. package/core/shared/parallel-fanout.md +10 -0
  47. package/core/shared/pattern-learning.md +146 -0
  48. package/core/shared/red-flags.md +58 -0
  49. package/core/shared/template-contract.md +22 -0
  50. package/core/shared/template-hygiene.md +10 -0
  51. package/core/shared/tool-resolver.md +10 -0
  52. package/core/shared/vcs-commands.md +97 -0
  53. package/core/shared/verification-gates.md +47 -0
  54. package/core/templates/CHANGELOG.md +70 -0
  55. package/core/templates/ai-context-export.md +8 -0
  56. package/core/templates/ai-context.md +270 -0
  57. package/core/templates/ai-profile.md +41 -0
  58. package/core/templates/architecture.md +203 -0
  59. package/core/templates/dependency-graph.md +103 -0
  60. package/core/templates/discovery.md +79 -0
  61. package/core/templates/guardrails.md +143 -0
  62. package/core/templates/hld.md +327 -0
  63. package/core/templates/intake-questions.md +403 -0
  64. package/core/templates/jira.md +119 -0
  65. package/core/templates/lld.md +283 -0
  66. package/core/templates/metadata.json +66 -0
  67. package/core/templates/plan.md +130 -0
  68. package/core/templates/product.md +110 -0
  69. package/core/templates/rca.md +86 -0
  70. package/core/templates/root-architecture.md +127 -0
  71. package/core/templates/root-product.md +53 -0
  72. package/core/templates/root-tech-stack.md +117 -0
  73. package/core/templates/service-index.md +55 -0
  74. package/core/templates/session-summary.md +8 -0
  75. package/core/templates/spec.md +165 -0
  76. package/core/templates/tech-matrix.md +101 -0
  77. package/core/templates/tech-stack.md +169 -0
  78. package/core/templates/track-architecture.md +311 -0
  79. package/core/templates/workflow.md +187 -0
  80. package/integrations/agents/AGENTS.md +24384 -0
  81. package/integrations/copilot/.github/copilot-instructions.md +24384 -0
  82. package/integrations/gemini/.gemini.md +26 -0
  83. package/package.json +53 -0
  84. package/scripts/fetch-memory-engine.sh +116 -0
  85. package/scripts/lib.sh +256 -0
  86. package/scripts/tools/_lib.sh +220 -0
  87. package/scripts/tools/adr-index.sh +117 -0
  88. package/scripts/tools/check-graph-usage-report.sh +95 -0
  89. package/scripts/tools/check-scope-conflicts.sh +139 -0
  90. package/scripts/tools/check-skill-line-caps.sh +115 -0
  91. package/scripts/tools/check-template-noop.sh +87 -0
  92. package/scripts/tools/check-track-hygiene.sh +230 -0
  93. package/scripts/tools/classify-files.sh +231 -0
  94. package/scripts/tools/cycle-detect.sh +75 -0
  95. package/scripts/tools/detect-test-framework.sh +135 -0
  96. package/scripts/tools/diff-templates-vs-tracks.sh +176 -0
  97. package/scripts/tools/emit-skill-metrics.sh +71 -0
  98. package/scripts/tools/fix-whitespace.sh +192 -0
  99. package/scripts/tools/freshness-check.sh +143 -0
  100. package/scripts/tools/git-metadata.sh +203 -0
  101. package/scripts/tools/graph-callers.sh +74 -0
  102. package/scripts/tools/graph-impact.sh +93 -0
  103. package/scripts/tools/graph-snapshot.sh +102 -0
  104. package/scripts/tools/hotspot-rank.sh +75 -0
  105. package/scripts/tools/manage-symlinks.sh +85 -0
  106. package/scripts/tools/mermaid-from-graph.sh +92 -0
  107. package/scripts/tools/migrate-track-frontmatter.sh +241 -0
  108. package/scripts/tools/parse-git-log.sh +135 -0
  109. package/scripts/tools/parse-reports.sh +114 -0
  110. package/scripts/tools/render-track.sh +145 -0
  111. package/scripts/tools/run-coverage.sh +153 -0
  112. package/scripts/tools/scan-markers.sh +144 -0
  113. package/scripts/tools/skill-caps.conf +24 -0
  114. package/scripts/tools/validate-frontmatter.sh +125 -0
  115. package/scripts/tools/verify-citations.sh +250 -0
  116. package/scripts/tools/verify-doc-anchors.sh +204 -0
  117. package/scripts/tools/verify-graph-binary.sh +154 -0
  118. package/skills/GRAPH.md +332 -0
  119. package/skills/adr/SKILL.md +374 -0
  120. package/skills/assist-review/SKILL.md +49 -0
  121. package/skills/bughunt/SKILL.md +668 -0
  122. package/skills/bughunt/references/regression-tests.md +399 -0
  123. package/skills/change/SKILL.md +267 -0
  124. package/skills/coverage/SKILL.md +336 -0
  125. package/skills/debug/SKILL.md +201 -0
  126. package/skills/decompose/SKILL.md +656 -0
  127. package/skills/deep-review/SKILL.md +326 -0
  128. package/skills/deploy-checklist/SKILL.md +254 -0
  129. package/skills/discover/SKILL.md +66 -0
  130. package/skills/docs/SKILL.md +42 -0
  131. package/skills/documentation/SKILL.md +197 -0
  132. package/skills/draft/SKILL.md +177 -0
  133. package/skills/draft/context-files.md +57 -0
  134. package/skills/draft/intent-mapping.md +37 -0
  135. package/skills/draft/quality-guide.md +51 -0
  136. package/skills/graph/SKILL.md +107 -0
  137. package/skills/impact/SKILL.md +86 -0
  138. package/skills/implement/SKILL.md +794 -0
  139. package/skills/incident-response/SKILL.md +245 -0
  140. package/skills/index/SKILL.md +848 -0
  141. package/skills/init/SKILL.md +1784 -0
  142. package/skills/init/references/architecture-spec.md +1259 -0
  143. package/skills/integrations/SKILL.md +53 -0
  144. package/skills/jira/SKILL.md +577 -0
  145. package/skills/jira/references/review.md +1322 -0
  146. package/skills/learn/SKILL.md +478 -0
  147. package/skills/new-track/SKILL.md +841 -0
  148. package/skills/ops/SKILL.md +57 -0
  149. package/skills/plan/SKILL.md +60 -0
  150. package/skills/quick-review/SKILL.md +216 -0
  151. package/skills/revert/SKILL.md +178 -0
  152. package/skills/review/SKILL.md +1114 -0
  153. package/skills/standup/SKILL.md +183 -0
  154. package/skills/status/SKILL.md +183 -0
  155. package/skills/tech-debt/SKILL.md +318 -0
  156. package/skills/testing-strategy/SKILL.md +195 -0
  157. package/skills/tour/SKILL.md +38 -0
  158. package/skills/upload/SKILL.md +117 -0
@@ -0,0 +1,336 @@
1
+ ---
2
+ name: coverage
3
+ description: Compute code coverage for active track or module. Targets 95%+ coverage with report and justification for uncovered lines. Complements TDD workflow.
4
+ ---
5
+
6
+ # Coverage Report
7
+
8
+ You are computing and reporting code coverage for the active track or a specific module. This complements the TDD workflow — TDD is the process (write test, implement, refactor), coverage is the measurement (how much code do those tests exercise).
9
+
10
+ ## Red Flags - STOP if you're:
11
+
12
+ - Reporting coverage without actually running the coverage tool
13
+ - Making up coverage percentages
14
+ - Skipping uncovered line analysis
15
+ - Not presenting the report for developer approval
16
+ - Treating this as a replacement for TDD (it's not — TDD stays in `/draft:implement`)
17
+
18
+ ---
19
+
20
+ ## Step 1: Load Context
21
+
22
+ 1. Read `draft/tech-stack.md` for test framework and language info
23
+ 2. Find active track from `draft/tracks.md`
24
+ 3. If track has `architecture.md` (track-level) or project has `.ai-context.md`, identify current module for scoping
25
+ 4. Look for `coverage_target` in `draft/workflow.md`. Check for per-module targets first (see Per-Module Coverage Enforcement below); if absent, default to 95%.
26
+ 5. Check if `draft/tracks/<id>/bughunt-report-latest.md` (track scope) or `draft/bughunt-report-latest.md` (project scope) exists for cross-referencing (see Coverage-Bughunt Cross-Reference below)
27
+
28
+ If no active track and no argument provided:
29
+ - Tell user: "No active track. Provide a path or track ID, or run `/draft:new-track` first."
30
+
31
+ ## Step 2: Detect Coverage Tool
32
+
33
+ **Preferred:** use the deterministic `detect-test-framework.sh` wrapper — it emits JSON `{languages:[{language,framework,runner_command,test_globs,config_file}]}`. Resolve via the canonical tool resolver (see [core/shared/tool-resolver.md](../../core/shared/tool-resolver.md)):
34
+
35
+ ```bash
36
+ DRAFT_TOOLS="${DRAFT_PLUGIN_ROOT:-$HOME/.claude/plugins/draft}/scripts/tools"
37
+ [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$HOME/.cursor/plugins/local/draft/scripts/tools"
38
+ [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$PWD/scripts/tools"
39
+ [ -x "$DRAFT_TOOLS/detect-test-framework.sh" ] && \
40
+ bash "$DRAFT_TOOLS/detect-test-framework.sh" --root .
41
+ ```
42
+
43
+ If the script is unavailable or returns `framework: unknown`, fall back to the heuristic table below:
44
+
45
+ | Language | Coverage Tools |
46
+ |----------|---------------|
47
+ | JavaScript/TypeScript | `jest --coverage`, `vitest --coverage`, `c8`, `nyc` |
48
+ | Python | `pytest --cov`, `coverage run`, `coverage.py` |
49
+ | Go | `go test -coverprofile=coverage.out` |
50
+ | Rust | `cargo tarpaulin`, `cargo llvm-cov` |
51
+ | C/C++ | `gcov`, `lcov` |
52
+ | Java/Kotlin | `jacoco`, `gradle jacocoTestReport` |
53
+ | Ruby | `simplecov` |
54
+
55
+ **Detection order (fallback path):**
56
+ 1. Check `tech-stack.md` for explicit testing section
57
+ 2. Check config files (`jest.config.*`, `vitest.config.*`, `pytest.ini`, `setup.cfg`, `pyproject.toml`, `.nycrc`)
58
+ 3. Check `package.json` scripts for coverage commands
59
+ 4. If not detectable, ask the developer which tool and command to use
60
+
61
+ ## Step 3: Determine Scope
62
+
63
+ **Priority order:**
64
+ 1. If argument provided (path or module name): use as scope filter
65
+ 2. If track has `architecture.md` (or project has `.ai-context.md`) with an in-progress module: scope to that module's files
66
+ 3. If active track exists: scope to files changed in the track (use `git diff` against base branch)
67
+ 4. Fallback: run coverage for entire project
68
+
69
+ Build the coverage command with the appropriate scope/filter flags.
70
+
71
+ ## Step 4: Run Coverage
72
+
73
+ **Preferred:** invoke the normalized `run-coverage.sh` dispatcher — it dispatches to the language-specific runner and emits a normalized JSON `{language,tool,total:{lines,branches},per_file:[{path,lines,branches,uncovered_lines}]}`. This avoids per-language ad-hoc parsing in Step 5.
74
+
75
+ ```bash
76
+ # DRAFT_TOOLS resolved in Step 2 above
77
+ [ -x "$DRAFT_TOOLS/run-coverage.sh" ] && \
78
+ bash "$DRAFT_TOOLS/run-coverage.sh" --root .
79
+ ```
80
+
81
+ If the script is unavailable or returns `tool: unsupported`:
82
+ 1. Execute the coverage command. Request machine-readable output when possible: `--json` for Jest, `--cov-report=json` for pytest, `-coverprofile` for Go, `--coverage-output-format json` for dotnet.
83
+ 2. Capture full output
84
+ 3. If command fails:
85
+ - Check if dependencies are installed (test framework, coverage plugin)
86
+ - Suggest installation command
87
+ - Ask developer to fix and retry
88
+
89
+ ## Step 5: Parse and Present Report
90
+
91
+ Parse coverage output and present in a standardized format:
92
+
93
+ ```
94
+ ---
95
+ COVERAGE REPORT
96
+ ---
97
+ Track: [track-id]
98
+ Module: [module name, if applicable]
99
+ Target: [from workflow.md, default 95%]
100
+
101
+ SUMMARY
102
+ ---
103
+ Overall: 87.3% (target: 95%) ← BELOW TARGET
104
+
105
+ PER-FILE BREAKDOWN
106
+ ---
107
+ src/auth/middleware.ts 96.2% PASS
108
+ src/auth/jwt.ts 72.1% FAIL
109
+ src/auth/types.ts 100.0% PASS
110
+
111
+ UNCOVERED LINES
112
+ ---
113
+ src/auth/jwt.ts:45-52 Error handler for malformed token
114
+ src/auth/jwt.ts:78 Defensive null check (unreachable via public API)
115
+
116
+ ---
117
+ ```
118
+
119
+ ## Step 6: Branch/Condition Coverage (Optional)
120
+
121
+ If the project's test framework supports branch/condition coverage (e.g., Istanbul, coverage.py branch mode), execute this step. Otherwise skip to Step 7.
122
+
123
+ Beyond line coverage, evaluate branch coverage for modules with complex conditional logic:
124
+
125
+ 1. **When to apply:** If the module contains nested conditionals, switch statements, or complex boolean expressions, line coverage alone is insufficient. 100% line coverage can miss untested branches in complex if/else/switch logic.
126
+ 2. **Branch coverage** measures whether every branch of every decision point has been exercised. Enable it with the appropriate flag:
127
+ - Jest/Vitest: `--coverage --coverageReporters=json-summary` (branch data included by default)
128
+ - pytest: `--cov --cov-branch`
129
+ - Go: `go test -covermode=count` (counts execution per branch)
130
+ - JaCoCo: branch coverage reported by default
131
+ - lcov/gcov: `--rc lcov_branch_coverage=1`
132
+ 3. **MC/DC (Modified Condition/Decision Coverage)** — For safety-critical modules (auth, payments, crypto), recommend MC/DC analysis. MC/DC requires that each condition in a decision independently affects the outcome. This is the standard in DO-178C (avionics) and referenced in ISTQB Advanced Test Analyst syllabi.
133
+ - Present MC/DC gaps separately from standard branch coverage gaps
134
+ - Flag any boolean expression with 3+ conditions as an MC/DC candidate
135
+
136
+ Include branch coverage percentage in the report alongside line coverage when branch analysis is performed.
137
+
138
+ ## Step 7: Analyze Gaps
139
+
140
+ For files below target (using per-module targets when configured — see Per-Module Coverage Enforcement):
141
+
142
+ 1. **Identify uncovered lines** - List specific line ranges and what they contain
143
+ 2. **Classify each gap:**
144
+ - **Testable** - Can and should be covered. Suggest specific test to write.
145
+ - **Defensive** - Assertions, error handlers for impossible states. Acceptable to leave uncovered.
146
+ - **Infrastructure** - Framework boilerplate, main entry points. Usually acceptable.
147
+ - **Legacy/Brownfield** - Modules with 0% or very low coverage that need refactoring. Apply Characterization Testing (see below).
148
+ 3. **Suggest tests** for testable gaps:
149
+ ```
150
+ SUGGESTED TESTS
151
+ ─────────────────────────────────────────────────────────
152
+ 1. Test malformed JWT token handling (jwt.ts:45-52)
153
+ - Input: token with invalid signature
154
+ - Expected: throws AuthError with code INVALID_TOKEN
155
+
156
+ 2. Test expired token rejection (jwt.ts:60-65)
157
+ - Input: token with exp in the past
158
+ - Expected: throws AuthError with code TOKEN_EXPIRED
159
+ ```
160
+
161
+ ## Step 7b: Characterization Testing (Brownfield/Legacy Code)
162
+
163
+ When encountering modules with 0% or very low coverage that need refactoring, do not attempt to write unit tests for untested legacy code directly. Instead, apply the Golden Master / Approval Testing approach (ref: Michael Feathers, "Working Effectively with Legacy Code"):
164
+
165
+ 1. **Create Golden Master baselines** — Generate fixed-seed inputs that exercise the module's public interface. Capture all outputs (return values, side effects, logs) as the approved baseline.
166
+ 2. **Lock behavior with approval tests** — Any change that alters the captured output triggers a test failure, making the current behavior explicit and protected.
167
+ 3. **Refactor under Golden Master safety net** — With approval tests guarding against regressions, refactor the module incrementally.
168
+ 4. **Write proper unit tests via TDD during refactoring** — As you extract and clarify logic, write focused unit tests using RED → GREEN → REFACTOR.
169
+ 5. **Remove approval tests** — Once proper unit test coverage meets the target, retire the Golden Master tests.
170
+
171
+ **Tool references:**
172
+ - ApprovalTests (https://approvaltests.com/) — available for Java, C#, Python, JS, and more
173
+ - Verify (.NET) — snapshot testing library
174
+
175
+ Present characterization testing recommendations in the gap analysis when applicable.
176
+
177
+ ## Step 7c: Mutation Testing Awareness
178
+
179
+ After measuring line coverage (and branch coverage if applicable), prompt the engineer to consider mutation testing for critical modules. Mutation testing introduces small code changes (mutants) into the source; if existing tests still pass, the mutant "survived," indicating weak test assertions even at high line coverage.
180
+
181
+ **When to recommend:** Modules at 90%+ line coverage that are high-risk (auth, payments, crypto, data persistence) or where past bugs have occurred. Mutation testing is most valuable when line coverage is already high but test quality is uncertain.
182
+
183
+ **Mutation score** = killed mutants / total non-equivalent mutants. Target: 80%+ for critical modules.
184
+
185
+ **Tool recommendations by language:**
186
+
187
+ | Language | Tool | Reference |
188
+ |----------|------|-----------|
189
+ | Java | PIT | https://pitest.org/ |
190
+ | JavaScript/TypeScript | Stryker | https://stryker-mutator.io/ |
191
+ | Python | mutmut | (Mutation testing tool) |
192
+ | Rust | cargo-mutants | (Mutation testing tool) |
193
+ | C# | Stryker.NET | https://stryker-mutator.io/ |
194
+ | Go | go-mutesting | (Mutation testing tool) |
195
+
196
+ **Reference:** Google's mutation testing program is used by 6,000+ engineers and processes approximately 30% of all code diffs, validating that mutation testing scales to large codebases.
197
+
198
+ Include mutation testing recommendations in the report when applicable, but do not block coverage completion on mutation analysis — it is advisory.
199
+
200
+ ## Step 7d: Coverage-Bughunt Cross-Reference
201
+
202
+ If a bughunt report exists (`draft/tracks/<id>/bughunt-report-latest.md` or `draft/bughunt-report-latest.md`):
203
+
204
+ 1. **Parse bughunt findings** — Extract file paths and line ranges of confirmed or suspected bugs.
205
+ 2. **Cross-reference with uncovered code paths** — Identify bughunt findings that fall in uncovered lines.
206
+ 3. **Flag as highest-priority test gaps** — Confirmed bugs in uncovered code are the most dangerous gaps. Present them prominently:
207
+ ```
208
+ BUGHUNT CROSS-REFERENCE
209
+ ─────────────────────────────────────────────────────────
210
+ ⚠ CRITICAL: Bug "Race condition in session refresh" (bughunt #3)
211
+ at src/auth/session.ts:112-118 — IN UNCOVERED CODE
212
+ → Write a test that exposes this bug FIRST before fixing
213
+
214
+ ⚠ HIGH: Bug "Missing null check on user lookup" (bughunt #7)
215
+ at src/users/repository.ts:45 — IN UNCOVERED CODE
216
+ → Write a regression test targeting this path
217
+ ```
218
+ 4. **Prioritize suggested tests** — Tests that cover bughunt-flagged code should appear first in the SUGGESTED TESTS section.
219
+
220
+ ## Per-Module Coverage Enforcement
221
+
222
+ Instead of applying a single global coverage target, support differentiated targets by module risk level. Check `draft/workflow.md` for a `coverage_targets` section:
223
+
224
+ ```yaml
225
+ # Example workflow.md configuration
226
+ coverage_targets:
227
+ high_risk: 95 # auth, payments, crypto, data persistence
228
+ business_logic: 85
229
+ infrastructure: 70
230
+ generated: exclude
231
+ modules:
232
+ src/auth/: high_risk
233
+ src/payments/: high_risk
234
+ src/crypto/: high_risk
235
+ src/db/: high_risk
236
+ src/api/handlers/: business_logic
237
+ src/utils/: infrastructure
238
+ src/generated/: generated
239
+ ```
240
+
241
+ **If no per-module configuration exists**, apply these defaults and inform the developer:
242
+
243
+ | Risk Level | Target | Applies To |
244
+ |------------|--------|------------|
245
+ | High-risk | 95%+ | Auth, payments, crypto, data persistence modules |
246
+ | Business logic | 85%+ | Core domain logic, API handlers |
247
+ | Infrastructure | 70%+ | Utilities, glue code, configuration |
248
+ | Generated | Exclude | Auto-generated code, proto stubs, ORM models |
249
+
250
+ **Classification heuristic:** Infer module risk from directory names and file content when explicit configuration is absent. Flag the inferred classification in the report so the developer can correct it.
251
+
252
+ In the coverage report, show per-module targets alongside actual coverage:
253
+ ```
254
+ PER-FILE BREAKDOWN (module-level targets)
255
+ ---
256
+ src/auth/middleware.ts 96.2% [high_risk: 95%] PASS
257
+ src/auth/jwt.ts 72.1% [high_risk: 95%] FAIL
258
+ src/utils/logger.ts 75.0% [infrastructure: 70%] PASS
259
+ src/generated/api.ts — [generated: excluded]
260
+ ```
261
+
262
+ ## Step 8: Developer Review
263
+
264
+ ### CHECKPOINT (MANDATORY)
265
+
266
+ **STOP.** Present the full coverage report and gap analysis.
267
+
268
+ Ask developer:
269
+ - Accept current coverage? (if at or above target)
270
+ - Write additional tests for testable gaps?
271
+ - Justify and document acceptable uncovered lines?
272
+ - Adjust coverage target for this track?
273
+
274
+ **Wait for developer approval before recording results.**
275
+
276
+ ## Step 9: Record Results
277
+
278
+ After developer approves:
279
+
280
+ 1. **Update plan.md** - Add coverage note to the relevant phase:
281
+ ```markdown
282
+ **Coverage:** 96.2% (target: 95%) - PASS
283
+ - Uncovered: defensive null checks in jwt.ts (justified)
284
+ ```
285
+
286
+ 2. **Update architecture context** — update the project-level `draft/architecture.md` with coverage data (not a track-level architecture file), then run the Condensation Subroutine (defined in `core/shared/condensation.md`) to regenerate `draft/.ai-context.md`. The Condensation Subroutine only applies to the project-level `draft/architecture.md` → `draft/.ai-context.md` pipeline:
287
+ ```markdown
288
+ - **Status:** [x] Complete (Coverage: 96.2%)
289
+ ```
290
+
291
+ 3. **Update metadata.json** - Add coverage field if not present:
292
+ ```json
293
+ {
294
+ "coverage": {
295
+ "overall": 96.2,
296
+ "target": 95,
297
+ "timestamp": "2025-01-15T10:30:00Z"
298
+ }
299
+ }
300
+ ```
301
+
302
+ 4. **Write detailed coverage report** to `draft/tracks/<id>/coverage-report-<timestamp>.md` (where `<timestamp>` is generated via `date +%Y-%m-%dT%H%M`, e.g., `2026-03-15T1430`) with YAML frontmatter (include `project`, `track_id`, `generated_by: "draft:coverage"`, `generated_at`, `git` metadata matching other skills) and timestamped entries for historical tracking.
303
+
304
+ After writing the timestamped report, create a symlink pointing to it:
305
+ ```bash
306
+ ln -sf coverage-report-<timestamp>.md draft/tracks/<id>/coverage-report-latest.md
307
+ ```
308
+
309
+ Previous timestamped reports are preserved. The `-latest.md` symlink always points to the most recent report.
310
+
311
+ ## Completion
312
+
313
+ Announce:
314
+ ```
315
+ Coverage report complete.
316
+
317
+ Overall: [percentage]% (target: [target]%)
318
+ Status: [PASS / BELOW TARGET]
319
+ Files analyzed: [count]
320
+ Gaps documented: [count testable] testable, [count justified] justified
321
+
322
+ Report: draft/tracks/<id>/coverage-report-<timestamp>.md (symlink: coverage-report-latest.md)
323
+
324
+ Results recorded in:
325
+ - plan.md (phase notes)
326
+ - architecture.md → .ai-context.md (module status, via Condensation Subroutine) [if applicable]
327
+ - metadata.json (coverage data)
328
+ ```
329
+
330
+ ## Re-running Coverage
331
+
332
+ When coverage is run again on the same track/module:
333
+ 1. Compare with previous results from metadata.json. If no previous coverage data found in metadata.json, skip delta comparison and report current values only.
334
+ 2. Show delta: "Coverage improved from 87.3% to 96.2% (+8.9%)"
335
+ 3. Highlight newly covered lines
336
+ 4. Update all records with latest results
@@ -0,0 +1,201 @@
1
+ ---
2
+ name: debug
3
+ description: Structured debugging session. Reproduce, isolate, diagnose, and fix bugs using systematic investigation. Invoked by /draft:new-track for bug tracks or directly for ad-hoc debugging.
4
+ ---
5
+
6
+ # Debug
7
+
8
+ You are conducting a structured debugging session following systematic investigation methodology.
9
+
10
+ ## MANDATORY GRAPH LOOKUP (read before Isolate/Diagnose)
11
+
12
+ When `draft/graph/schema.yaml` exists, this skill **must** follow the graph-first lookup contract in [core/shared/graph-query.md](../../core/shared/graph-query.md) §Mandatory Lookup Contract. During Steps 3–4 (Isolate, Diagnose):
13
+
14
+ 1. Locate the suspect file's module via `draft/graph/architecture.json` (`.packages`) before tracing data flow.
15
+ 2. Use `scripts/tools/graph-callers.sh --repo . --symbol <fn>` to enumerate call sites of suspect functions — not `grep`.
16
+ 3. Use `scripts/tools/graph-impact.sh --repo . --file <path>` to size the blast radius before proposing a fix.
17
+ 4. Cross-check `draft/graph/hotspots.jsonl` to know whether the file is high-fanIn (any fix needs extra caution).
18
+
19
+ Filesystem `grep` is reserved for source-text scans (literal error strings, stack-trace symbols when the graph misses). Use the fallback sentence on graph miss.
20
+
21
+ ## Red Flags — STOP if you're:
22
+
23
+ See [shared red flags](../../core/shared/red-flags.md) — applies to all code-touching skills.
24
+
25
+ Skill-specific:
26
+ - Making code changes before reproducing the bug
27
+ - Guessing at the cause instead of tracing data/control flow
28
+ - Trying multiple fixes simultaneously ("shotgun debugging")
29
+ - Skipping reproduction steps because "I think I know the issue"
30
+ - Writing tests without asking the developer first (bug/RCA contexts)
31
+
32
+ **No fixes without root cause investigation first.**
33
+
34
+ ---
35
+
36
+ ## Pre-Check
37
+
38
+ ### 0. Capture Git Context
39
+
40
+ Before starting, capture the current git state:
41
+
42
+ ```bash
43
+ git branch --show-current # Current branch name
44
+ git rev-parse --short HEAD # Current commit hash
45
+ ```
46
+
47
+ Store this for the debug report header. The session is scoped to this specific branch/commit.
48
+
49
+ ### 1. Verify Draft Context (Optional)
50
+
51
+ ```bash
52
+ ls draft/ 2>/dev/null
53
+ ```
54
+
55
+ Debug can run standalone (without draft context) or within a draft track. If `draft/` exists, load context for richer investigation.
56
+
57
+ ### 2. Load Draft Context (if available)
58
+
59
+ Read and follow the base procedure in `core/shared/draft-context-loading.md`.
60
+
61
+ Key context for debugging:
62
+ - `.ai-context.md` — Module boundaries, data flows, invariants (crucial for tracing)
63
+ - `tech-stack.md` — Language-specific debugging tools and techniques
64
+ - `guardrails.md` — Known anti-patterns that may be causing the issue
65
+ - `draft/graph/` (MANDATORY when present) — Load `architecture.json` for dependency/module context and `hotspots.jsonl` for complexity awareness. Use `scripts/tools/graph-callers.sh --repo . --symbol <fn>` to find all callers, and `scripts/tools/graph-impact.sh --repo . --file <path>` to size blast radius before any fix. See [core/shared/graph-query.md](../../core/shared/graph-query.md).
66
+
67
+ ## Step 1: Parse Arguments
68
+
69
+ Check for arguments:
70
+ - `/draft:debug` — Interactive: ask what's broken
71
+ - `/draft:debug <description>` — Start with the described problem
72
+ - `/draft:debug track <id>` — Debug within a specific track context (load spec.md, plan.md)
73
+ - `/draft:debug <JIRA-KEY>` — Pull context from Jira ticket via MCP
74
+
75
+ If a Jira ticket is provided:
76
+ 1. Pull ticket via Jira MCP: `get_issue()`, `get_issue_description()`, `get_issue_comments()`
77
+ 2. Extract: URLs, log paths, stack traces, reproduction steps, affected services
78
+ 3. Use `curl`/`wget` to fetch any URLs mentioned (dashboards, error pages, API responses)
79
+ 4. Use `ssh` to access log locations on remote nodes (if paths like `/home/log/`, node IPs mentioned)
80
+ 5. Collect all gathered data into a triage context bundle
81
+
82
+ ## Step 2: Reproduce
83
+
84
+ **Goal:** Confirm the bug exists and establish reproduction steps.
85
+
86
+ 1. **Identify the symptom** — Exact error message, unexpected behavior, or performance degradation
87
+ 2. **Establish reproduction steps** — Minimum steps to trigger the issue consistently
88
+ 3. **Capture evidence** — Error messages, stack traces, log output (verbatim, not summarized)
89
+ 4. **Classify reproducibility:**
90
+ - Always reproducible — proceed to Step 3
91
+ - Intermittent — document frequency, conditions, patterns (time, load, data-dependent); proceed to Step 3 with the failure mode tagged `intermittent` in the hypothesis log
92
+ - Cannot reproduce — **halt diagnostic claims.** Do not proceed to Step 4 (Diagnose) until reproduction is established or the user explicitly opts into hypothesis work without reproduction. Hypotheses formed without reproduction routinely converge on confidently-wrong root causes. If the user opts in: every hypothesis must be tagged `unreproduced` and the final report must mark the root cause as `unconfirmed pending repro`.
93
+
94
+ Reference `core/agents/debugger.md` Phase 1 for detailed investigation techniques.
95
+
96
+ ## Step 3: Isolate
97
+
98
+ **Goal:** Narrow the failure to a specific code path.
99
+
100
+ 1. **Trace data flow** — Follow data from input to failure point, documenting each hop with `file:line` references
101
+ 2. **Trace control flow** — Map the execution path, identify where it diverges from expected behavior
102
+ 3. **Differential analysis** — Compare working vs failing cases:
103
+ | Aspect | Working Case | Failing Case | Difference |
104
+ |--------|-------------|-------------|------------|
105
+ 4. **Check boundaries** — Reference `.ai-context.md` module boundaries to scope the investigation
106
+
107
+ Reference `core/agents/debugger.md` Phase 2 for language-specific debugging techniques.
108
+
109
+ ## Step 4: Diagnose
110
+
111
+ **Goal:** Confirm root cause with evidence.
112
+
113
+ **Ground-truth gate (per hypothesis):** Before forming hypothesis N, **open and Read** the file at the `file:line` you are about to cite. Quote the relevant lines in the hypothesis log. A hypothesis written from graph metadata or recollection is a [Ground-Truth Red Flag](../../core/shared/red-flags.md) G4 violation — it produces hypothesis loops on assumptions rather than evidence.
114
+
115
+ 1. **Form hypothesis** — "The bug is caused by [X] at `file:line` because [evidence quoted from Read]"
116
+ 2. **Predict outcome** — "If this hypothesis is correct, then [Y] should be observable"
117
+ 3. **Test minimally** — Smallest possible test to prove or disprove
118
+ 4. **Record result** — Document in hypothesis log:
119
+
120
+ | # | Hypothesis (cite + quote) | Test | Prediction | Actual | Result |
121
+ |---|--------------------------|------|-----------|--------|--------|
122
+ | 1 | [description with `path:line` and quoted line] | [test] | [expected] | [actual] | Confirmed/Rejected |
123
+
124
+ **If hypothesis fails:** Return to Step 3 with updated understanding. After 3 failed cycles, escalate (see Error Handling). Do not increase confidence on a rejected hypothesis just because alternatives are running out — that's how anchoring bias produces wrong root causes.
125
+
126
+ Reference `core/agents/debugger.md` Phase 3 and `core/agents/rca.md` for 5 Whys analysis.
127
+
128
+ ## Step 5: Fix (with Developer Approval)
129
+
130
+ **Goal:** Fix the root cause with minimal change.
131
+
132
+ ### Test Writing Guardrail
133
+
134
+ **STOP.** Before writing any test:
135
+ ```
136
+ ASK: "Root cause confirmed: [summary]. Want me to write a regression test for this fix? [Y/n]"
137
+ ```
138
+ - If accepted: write regression test first (fails before fix, passes after)
139
+ - If declined: note "Tests: developer-handled" and proceed to fix
140
+
141
+ ### Fix Implementation
142
+
143
+ 1. **Minimal fix** — Address root cause only, no "while we're here" improvements
144
+ 2. **Stay in blast radius** — No changes to adjacent modules without explicit approval
145
+ 3. **Run existing tests** — Verify no regressions
146
+ 4. **Document root cause** — Add findings to Debug Report
147
+
148
+ ## Step 6: Generate Debug Report
149
+
150
+ **MANDATORY: Include YAML frontmatter with git metadata.** Follow `core/shared/git-report-metadata.md`.
151
+
152
+ Include the report header table immediately after frontmatter:
153
+
154
+ ```markdown
155
+ | Field | Value |
156
+ |-------|-------|
157
+ | **Branch** | `{LOCAL_BRANCH}` → `{REMOTE/BRANCH}` |
158
+ | **Commit** | `{SHORT_SHA}` — {COMMIT_MESSAGE} |
159
+ | **Generated** | {ISO_TIMESTAMP} |
160
+ | **Synced To** | `{FULL_SHA}` |
161
+ ```
162
+
163
+ Save to:
164
+ - Track-scoped: `draft/tracks/<id>/debug-report.md`
165
+ - Standalone: `draft/debug-report-<timestamp>.md` with symlink `debug-report-latest.md`
166
+
167
+ ```bash
168
+ TIMESTAMP=$(date +%Y-%m-%dT%H%M)
169
+ # Example: draft/debug-report-2026-03-15T1430.md
170
+ ln -sf debug-report-${TIMESTAMP}.md draft/debug-report-latest.md
171
+ ```
172
+
173
+ ## Mandatory Self-Check (before debug report)
174
+
175
+ Before printing the debug report, internally verify and report:
176
+
177
+ 1. **Graph files queried** — JSONL files loaded plus any live graph query-tool invocations.
178
+ 2. **Layer 1 files deliberately skipped** — list any context sections skipped.
179
+ 3. **Filesystem grep fallback justification** — for every `grep`/`find` run, name the concept it searched for.
180
+
181
+ If `draft/graph/schema.yaml` does not exist, set `Graph files queried: NONE` and use justification `graph data unavailable`.
182
+
183
+ ## Graph Usage Report (append to debug report)
184
+
185
+ Emit the canonical footer from [core/shared/graph-usage-report.md](../../core/shared/graph-usage-report.md) §Canonical footer. The lint hook `scripts/tools/check-graph-usage-report.sh` validates the section on save.
186
+ ## Cross-Skill Dispatch
187
+
188
+ - **Auto-invoked by:** `/draft:new-track` (bug tracks — Offer tier), `/draft:implement` (blocked tasks — Offer tier)
189
+ - **Invokes:** RCA agent (`core/agents/rca.md`) for 5 Whys and blast radius analysis
190
+ - **Feeds into:** `/draft:new-track` spec.md (reproduction and root cause sections via Detect+Auto-Feed)
191
+ - **Suggests at completion:**
192
+ - "Run `/draft:regression` to find the exact commit that introduced this bug"
193
+ - "Run `/draft:new-track` to create a bug fix track from these findings"
194
+ - **Jira sync:** If ticket linked, attach debug report and post summary via `core/shared/jira-sync.md`
195
+
196
+ ## Error Handling
197
+
198
+ **If cannot reproduce:** Gather more context — check environment differences, ask for additional logs, check if the issue is environment-specific.
199
+ **If no draft context:** Run standalone with generic debugging methodology. Recommend `/draft:init` for richer context.
200
+ **After 3 failed hypothesis cycles:** Document all findings, list what's been eliminated, escalate — consider architectural review or external input.
201
+ **If MCP unavailable for Jira:** Skip Jira context gathering, proceed with available information.