@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,668 @@
1
+ ---
2
+ name: bughunt
3
+ description: "Performs an exhaustive 14-dimension bug hunt across the codebase using Draft context (architecture, tech-stack, product) for false-positive elimination. Generates a severity-ranked report with code evidence, data flow traces, and suggested fixes. Optionally writes regression tests. Use when the user asks to find bugs, audit code for defects, scan for vulnerabilities, or says 'hunt bugs', 'find bugs', or 'code audit'."
4
+ ---
5
+
6
+ # Bug Hunt
7
+
8
+ Conduct an exhaustive bug hunt on this Git repository, enhanced by Draft context when available.
9
+
10
+ ## Primary Deliverable
11
+
12
+ **The bug report is the primary deliverable.** Every verified bug MUST appear in the final report regardless of whether a regression test can be written. Regression tests are a supplementary output — helpful when possible, but never a filter for bug inclusion.
13
+
14
+ ## Relationship to Built-in Bug Hunt Agents
15
+
16
+ Some AI tools (e.g., Claude Code) provide a built-in `bughunt` agent that auto-discovers project structure and runs parallel sweeps. `/draft:bughunt` is **complementary, not competing**:
17
+
18
+ | | `/draft:bughunt` | Built-in bughunt agent |
19
+ |---|---|---|
20
+ | **Approach** | Context-driven methodology with 14 analysis dimensions and verification protocol | Auto-discovery with parallel sweep subagents |
21
+ | **Draft context** | Uses architecture, tech-stack, product, guardrails for false-positive elimination | No Draft context awareness |
22
+ | **Output** | Severity-ranked report with evidence | Inline fixes + regression tests |
23
+ | **Modifies code** | No (report + regression tests only) | Yes (finds AND fixes) |
24
+
25
+ **When to use which:** Use `/draft:bughunt` when you need context-aware analysis with structured evidence and false-positive elimination. Use the built-in agent when you want fast parallel sweeps with auto-fix capability. For maximum coverage, run both — `/draft:bughunt` catches context-specific bugs the built-in misses, and vice versa.
26
+
27
+ ## Red Flags - STOP if you're:
28
+
29
+ - Hunting for bugs without reading Draft context first (architecture.md, tech-stack.md, product.md)
30
+ - Reporting a finding without reproducing or tracing the code path
31
+ - Fixing production code instead of reporting bugs (bughunt reports bugs and writes regression tests — it doesn't fix source code)
32
+ - Assuming a pattern is buggy without checking if it's used successfully elsewhere
33
+ - Skipping the verification protocol (every bug needs evidence)
34
+ - Making up file locations or line numbers without reading the actual code
35
+ - Reporting framework-handled concerns as bugs without checking the docs
36
+ - **Skipping bugs because you can't write a test for them** — mark as N/A and still report
37
+
38
+ **Verify before you report. Evidence over assumptions.**
39
+
40
+ ---
41
+
42
+ ## Pre-Check
43
+
44
+ ### 0. Capture Git Context
45
+
46
+ Before starting analysis, capture the current git state:
47
+
48
+ ```bash
49
+ git branch --show-current # Current branch name
50
+ git rev-parse --short HEAD # Current commit hash
51
+ ```
52
+
53
+ Store this for the report header. All bugs found are relative to this specific branch/commit.
54
+
55
+ ### 1. Load Draft Context (if available)
56
+
57
+ Read and follow the base procedure in `core/shared/draft-context-loading.md`.
58
+
59
+ **Bug-hunt-specific context application:**
60
+ - Flag violations of intended architecture as bugs (coupling, boundary violations)
61
+ - Apply framework-specific checks from tech-stack (React anti-patterns, Node gotchas, etc.)
62
+ - Catch bugs that violate product requirements or user flows
63
+ - Prioritize areas relevant to active tracks
64
+ - **Leverage Critical Invariants** — Check for invariant violations across data safety, security, concurrency, ordering, idempotency categories
65
+ - **Leverage Concurrency Model** — Use thread/async model info for race condition and deadlock analysis
66
+ - **Leverage Error Handling** — Use failure modes and retry policies for reliability bug detection
67
+ - **Leverage Data State Machines** — Check for invalid state transitions, missing guard clauses, states with no exit path
68
+ - **Leverage Storage Topology** — Identify data loss risks at each tier (cache eviction without writeback, event log gaps, missing archive)
69
+ - **Leverage Consistency Boundaries** — Find bugs at eventual consistency seams (stale reads, lost events, missing reconciliation)
70
+ - **Leverage Failure Recovery Matrix** — Verify idempotency claims, check for partial failure states without recovery paths
71
+ - **Leverage Graph Data** (if `draft/graph/` exists) — Read `architecture.json` (`.packages`) for dependency awareness. Flag dependencies on unexpected modules. Flag code in modules involved in dependency cycles as higher risk. Use `hotspots.jsonl` to prioritize analysis of high-complexity, high-fanIn files. See `core/shared/graph-query.md`.
72
+ - **Leverage Learned Anti-Patterns** — If `draft/guardrails.md` exists, read the `## Learned Anti-Patterns` section. During the bug sweep, when a bug matches a learned anti-pattern, prefix the report entry with `[KNOWN-ANTI-PATTERN: {pattern name}]`. This distinguishes recurring documented patterns from newly discovered bugs, and signals that a systemic fix may be needed rather than a one-off patch.
73
+
74
+ ### 2. Confirm Scope
75
+
76
+ When invoked programmatically by `/draft:review` with `with-bughunt`, skip scope confirmation and inherit the scope from the calling command.
77
+
78
+ Otherwise, ask user to confirm scope:
79
+ - **Entire repo** - Full codebase analysis
80
+ - **Specific paths** - Target directories or files
81
+ - **Track-level** (specify `<track-id>`) - Focus on files relevant to a specific track
82
+
83
+ ### 3. Load Track Context (if track-level)
84
+
85
+ If running for a specific track, also load:
86
+ - [ ] `draft/tracks/<id>/spec.md` - Requirements, acceptance criteria, edge cases
87
+ - [ ] `draft/tracks/<id>/plan.md` - Implementation tasks, phases, dependencies
88
+
89
+ Use track context to:
90
+ - Verify implemented features match spec requirements
91
+ - Check edge cases listed in spec are handled
92
+ - Identify bugs in areas touched by the track's plan
93
+ - Focus analysis on files modified/created by the track
94
+
95
+ If no Draft context exists, proceed with code-only analysis.
96
+
97
+ ## Dimension Applicability Check
98
+
99
+ Before analyzing all 14 dimensions, determine which apply to this codebase:
100
+
101
+ - **Skip explicitly** rather than forcing analysis of N/A dimensions
102
+ - **Mark skipped dimensions** with reason in report summary
103
+
104
+ **Examples of skipping:**
105
+ - "N/A - no backend code" (skip dimensions 2, 8, 10 for frontend-only repo)
106
+ - "N/A - no UI components" (skip dimensions 5, 9, 14 for CLI tool)
107
+ - "N/A - no database" (skip dimension 2 for in-memory app)
108
+ - "N/A - no external integrations" (skip dimension 8)
109
+ - "N/A - no external dependencies" (skip dimension 12 for zero-dependency project)
110
+ - "N/A - no user-facing strings" (skip dimension 14 for libraries/APIs)
111
+
112
+ ## Analysis Dimensions
113
+
114
+ Analyze systematically across all applicable dimensions. Skip N/A dimensions explicitly (see Dimension Applicability Check above).
115
+
116
+ ### 1. Correctness
117
+ - Logical errors, invalid assumptions, edge cases
118
+ - Incorrect state transitions, stale or inconsistent UI state
119
+ - Error handling gaps, silent failures
120
+ - Off-by-one errors, boundary conditions
121
+
122
+ ### 2. Reliability & Resilience
123
+ - Crash paths, unhandled exceptions
124
+ - Reload/refresh behavior, retry logic
125
+ - UI behavior on partial backend failure
126
+ - Broken recovery after errors, navigation
127
+
128
+ ### 3. Security
129
+ - XSS, injection vectors, unsafe rendering
130
+ - Client-side trust assumptions
131
+ - Secrets, tokens, auth data exposure
132
+ - CSRF, insecure deserialization
133
+ - Path traversal, command injection
134
+ - **Taint tracking (end-to-end data flow analysis):**
135
+ - Identify all entry points: HTTP params, form data, file uploads, env vars, CLI args, message queue payloads, webhook bodies
136
+ - Trace user input to dangerous sinks: SQL queries, shell exec, eval, innerHTML, file path construction, URL construction, deserialization, template rendering
137
+ - For each sink, verify sanitization/validation exists on every path from source to sink
138
+ - Flag paths where unsanitized input reaches a sink without passing through a validator, encoder, or sanitizer
139
+ - Reference: OWASP Top 10, Meta Infer taint analysis methodology
140
+
141
+ ### 4. Performance (Backend + UI)
142
+ - Inefficient algorithms and data fetching
143
+ - Blocking work on main/UI thread
144
+ - Excessive re-renders, unnecessary state updates
145
+ - Unbounded memory growth (listeners, caches, stores)
146
+
147
+ ### 5. UI Responsiveness & Perceived Performance
148
+ - Long tasks blocking input
149
+ - Jank during scrolling, typing, resizing
150
+ - Layout thrashing, forced reflows
151
+ - Expensive animations or transitions
152
+ - Poor loading states, flicker, content shifts
153
+
154
+ ### 6. Concurrency & Ordering
155
+ - Race conditions between async calls
156
+ - Stale responses overwriting newer state
157
+ - Incorrect cancellation or debouncing
158
+ - Event ordering assumptions
159
+ - Deadlocks, livelocks
160
+
161
+ ### 7. State Management
162
+ - Source-of-truth violations
163
+ - Derived state bugs (computed from stale data)
164
+ - Global state misuse
165
+ - Memory leaks from subscriptions or observers
166
+ - Inconsistent state across components
167
+
168
+ ### 8. API & Contracts
169
+ - UI assumptions not guaranteed by backend
170
+ - Schema drift, weak typing, missing validation
171
+ - Backward compatibility risks
172
+ - Undocumented API behavior dependencies
173
+
174
+ ### 9. Accessibility & UX Correctness
175
+ - Keyboard navigation gaps
176
+ - Focus management bugs
177
+ - ARIA misuse or absence
178
+ - Broken tab order or unreadable states
179
+ - UI behavior that contradicts user intent
180
+ - Color contrast, screen reader compatibility
181
+
182
+ ### 10. Configuration & Build
183
+ - Fragile environment assumptions
184
+ - Build-time vs runtime config leaks
185
+ - Dev-only code shipping to prod
186
+ - Missing environment variable validation
187
+ - CI gaps affecting builds or tests
188
+
189
+ ### 11. Tests
190
+ - Missing coverage for critical flows
191
+ - Snapshot misuse (testing implementation, not behavior)
192
+ - Tests that assert implementation instead of behavior
193
+ - Mismatch between test and real user interaction
194
+ - Flaky tests, timing dependencies
195
+ - **Property-based testing gaps:** pure/mathematical functions without invariant-based tests (e.g., `encode(decode(x)) == x`, sorting idempotency, associativity)
196
+ - **Test isolation violations:** shared mutable state between test cases (global variables, singletons, class-level state modified in tests without reset)
197
+ - **Test double misuse:** mocks that leak state across tests, over-mocking (>3 mocks per test suggests testing wiring not behavior), stubs that diverge from real implementation behavior
198
+ - **Assertion density:** tests with zero or weak assertions (`assertTrue(true)`, `expect(result).toBeDefined()` only, empty catch blocks in test code, `assert result is not None` as sole check)
199
+ - **Flaky test patterns:** time-dependent assertions (sleep, Date.now, timestamps), port/file system assumptions, test ordering dependencies, non-deterministic data (random seeds, UUIDs without control)
200
+
201
+ ### 12. Dependency & Supply Chain Security
202
+ - **Known CVEs:** Check dependencies against known vulnerability databases (reference tools: Snyk, Trivy, OWASP Dependency-Check, `npm audit`, `pip-audit`, `cargo audit`, `go vuln`)
203
+ - **Unpinned dependency versions:** Lockfile freshness, use of version ranges (`^`, `~`, `*`, `>=`) without lockfile enforcement, missing lockfile entirely
204
+ - **Deprecated packages:** Dependencies with known deprecation notices, archived repositories, or no maintenance activity
205
+ - **License conflicts:** GPL dependencies in MIT/Apache projects, AGPL in proprietary code, incompatible license combinations in the dependency tree
206
+ - **Typosquatting risk:** Packages with names similar to popular ones (e.g., `lodahs` vs `lodash`, `reqeusts` vs `requests`), recently published packages with few downloads
207
+ - **Transitive dependency depth:** Deeply nested dependency chains (>5 levels) increase supply chain attack surface; flag packages that pull in disproportionate transitive trees
208
+ - Reference: Google OSS-Fuzz, Microsoft SDL, OpenSSF Scorecard
209
+
210
+ ### 13. Algorithmic Complexity
211
+ - **Quadratic or worse loops:** O(n^2) or worse nested loops over collections (nested `.filter()` inside `.map()`, repeated linear scans, cartesian joins in application code)
212
+ - **Regex catastrophic backtracking:** Nested quantifiers (`(a+)+`, `(a|a)*`), unbounded repetition with overlapping alternatives — flag any regex applied to user-controlled input
213
+ - **Unbounded recursion:** Recursive functions without depth limits, missing base cases, or base cases that depend on external/mutable state
214
+ - **Cache invalidation storms:** Cache miss triggering expensive recomputation that itself invalidates caches, thundering herd on cache expiry without jitter/locking
215
+ - **Hot path inefficiency:** Sorting/searching in hot paths without appropriate data structures (linear scan where hash map suffices, repeated sorting of same collection, string concatenation in loops)
216
+
217
+ ### 14. Internationalization & Localization
218
+ - **Hardcoded user-facing strings:** Strings displayed to users embedded directly in source code rather than externalized to resource files/i18n frameworks
219
+ - **Locale-sensitive operations without locale parameter:** String comparison (`<`, `>`, `localeCompare` without locale), date formatting (`toLocaleDateString` without explicit locale), number formatting, sorting (alphabetical sort that assumes ASCII ordering)
220
+ - **RTL layout issues:** Hardcoded LTR assumptions in UI code (absolute `left`/`right` positioning, directional margin/padding, text alignment assumptions)
221
+ - **Unicode handling bugs:** String length vs byte length confusion, missing normalization (NFC/NFD), emoji handling (multi-codepoint sequences split incorrectly, `string.length` vs grapheme count), surrogate pair handling in substring operations
222
+
223
+ ## Bug Verification Protocol
224
+
225
+ **CRITICAL: No bug is valid without verification.** Before declaring any finding as a bug, complete ALL applicable verification steps:
226
+
227
+ ### Verification Checklist (for each potential bug)
228
+
229
+ 1. **Code Path Verification**
230
+ - [ ] Read the actual code at the suspected location
231
+ - [ ] Trace the data flow from input to the bug location
232
+ - [ ] Check if there are guards, validators, or error handlers upstream
233
+ - [ ] Verify the code path is actually reachable in production
234
+
235
+ 2. **Context Cross-Reference**
236
+ - [ ] Check `.ai-context.md` (or `architecture.md`) — Is this behavior intentional by design?
237
+ - [ ] Check `tech-stack.md` — Does the framework handle this case?
238
+ - [ ] Check `tech-stack.md` `## Accepted Patterns` — Is this pattern explicitly documented as intentional?
239
+ - [ ] Check `product.md` — Is this actually a requirement violation?
240
+ - [ ] Check existing tests — Is this behavior already tested and expected?
241
+
242
+ 3. **Framework/Library Verification**
243
+ - [ ] Read official docs for the specific method/pattern in question
244
+ - [ ] Quote relevant doc section proving this is/isn't handled
245
+ - [ ] Check framework version in tech-stack.md (behavior may vary by version)
246
+ - [ ] Look for middleware, interceptors, or global handlers that may address the issue
247
+
248
+ **Example Framework Documentation Quote:**
249
+ "React automatically escapes JSX content to prevent XSS (React Docs: Main Concepts > JSX). However, `dangerouslySetInnerHTML` bypasses this protection. Framework version: React 18.2.0 (from tech-stack.md)."
250
+
251
+ 4. **Codebase Pattern Check**
252
+ - [ ] Search for similar patterns elsewhere in codebase
253
+ - [ ] If pattern is used consistently, verify it's actually buggy (not just unfamiliar)
254
+ - [ ] Check if there's a project-specific utility/wrapper that handles the concern
255
+
256
+ 5. **False Positive Elimination**
257
+ - [ ] Is this dead code that's never executed?
258
+ - [ ] Is this test/mock/stub code not in production?
259
+ - [ ] Is this intentionally disabled (feature flag, config)?
260
+ - [ ] Is there a comment explaining why this appears unsafe but is actually safe?
261
+
262
+ 6. **Pattern Prevalence Check (before reporting)**
263
+ - [ ] Run Grep to find all occurrences of the pattern
264
+ - [ ] If found >5x:
265
+ - Randomly sample 3 instances
266
+ - Verify they exhibit the same suspected bug
267
+ - If they work correctly, investigate: what's different about THIS instance?
268
+ - [ ] If no difference found and other instances work: DO NOT REPORT
269
+ - [ ] If all instances have the bug: Report with pattern count in "Impact"
270
+
271
+ **Example Pattern Prevalence Check:**
272
+ ```
273
+ 1. Grep: `rg 'dangerouslySetInnerHTML' src/` → found 12 occurrences
274
+ 2. Sampled 3: src/Blog.tsx:45, src/About.tsx:12, src/FAQ.tsx:30
275
+ 3. All 3 sanitize input via `DOMPurify.sanitize()` before rendering
276
+ 4. THIS instance (src/Comment.tsx:88) passes raw user input without sanitization
277
+ 5. Decision: REPORT — this instance lacks the sanitization all others have
278
+ ```
279
+
280
+ ### Confidence Levels
281
+
282
+ Only report bugs with HIGH or CONFIRMED confidence:
283
+
284
+ | Level | Criteria | Action |
285
+ |-------|----------|--------|
286
+ | **CONFIRMED** | Verified through code trace, no mitigating factors found | Report as bug |
287
+ | **HIGH** | Strong evidence, checked context, no obvious mitigation | Report as bug |
288
+ | **MEDIUM** | Suspicious but couldn't verify all factors | Ask user to confirm before reporting |
289
+ | **LOW** | Possible issue but likely handled elsewhere | Do NOT report |
290
+
291
+ **Example confirmation prompt for MEDIUM Confidence:**
292
+ "I found a potential race condition in `src/handler.ts:45` where async state updates may overwrite each other. However, I couldn't verify if there's a locking mechanism elsewhere. Should I report this as a bug?"
293
+
294
+ ### Evidence Requirements
295
+
296
+ Each reported bug MUST include:
297
+ - **Code Evidence:** The actual problematic code snippet
298
+ - **Trace:** How data reaches this point (caller chain or data flow)
299
+ - **Verification Done:** Which checks from the checklist were completed
300
+ - **Why Not a False Positive:** Explicit statement of why this isn't handled elsewhere
301
+
302
+ ## Analysis Rules
303
+
304
+ - **Do not execute code** - Reason from source only
305
+ - **Do not assume frameworks "handle it"** - Verify explicitly by checking docs/code
306
+ - **Do not assume code is buggy** - Verify it's actually reachable and unguarded
307
+ - **Trace data flow completely** - From input source to bug location
308
+ - **Cross-reference ALL Draft context** - Check architecture, tech-stack, product, tests
309
+ - **Check for existing mitigations** - Middleware, wrappers, utilities, global handlers
310
+ - **Search for patterns** - If used elsewhere without issues, investigate why
311
+
312
+ ## Optional: Runtime Verification (if test suite exists)
313
+
314
+ For suspected bugs that can be tested, write a minimal failing test to confirm:
315
+
316
+ 1. **Write minimal test** — Target the specific bug, not the entire feature
317
+ 2. **Run test** — Execute and observe failure
318
+ 3. **Confirm bug** — If test fails as predicted, confidence level increases to CONFIRMED
319
+ 4. **Only report if**: Test fails OR CONFIRMED confidence from code trace
320
+
321
+ **Example:**
322
+ ```javascript
323
+ // Suspected bug: off-by-one in pagination
324
+ test('should handle last page boundary', () => {
325
+ const items = Array(100).fill('item');
326
+ const result = paginate(items, { page: 10, perPage: 10 });
327
+ expect(result.items.length).toBe(10); // Currently returns 9
328
+ });
329
+ ```
330
+
331
+ If test fails, upgrade confidence to CONFIRMED and include test in bug report.
332
+
333
+ ## Regression Test Generation
334
+
335
+ For each verified bug, generate a regression test in the project's native test framework that would expose the bug as a failing test. **Before writing any new test**, discover the project's language and test framework, then check whether existing tests already cover the bug scenario (COVERED / PARTIAL / WRONG_ASSERTION / NO_COVERAGE / N/A).
336
+
337
+ If no test framework is detected, mark all bugs `Regression Test Status: N/A` and continue — the bug report is the primary deliverable.
338
+
339
+ **Detailed procedure** — see `references/regression-tests.md` for:
340
+ - Language and test-framework detection signals (C/C++, Go, Python, JS/TS, Rust, Java)
341
+ - Existing-test discovery patterns and coverage classification
342
+ - Test case requirements and language-specific templates
343
+ - Build/syntax validation commands per toolchain
344
+
345
+
346
+ ## Fix Suggestion Generation
347
+
348
+ For each bug with CONFIRMED or HIGH confidence, generate a minimal suggested fix alongside the bug report. Fix suggestions are advisory — they are never auto-applied.
349
+
350
+ ### Fix Generation Rules
351
+
352
+ 1. **Minimal change principle:** The fix must be the smallest code change that addresses the root cause. Do not refactor surrounding code, add features, or improve style.
353
+ 2. **Before/after format:** Include the exact current code (BEFORE) and the suggested fix (AFTER) as code snippets with file path and line numbers.
354
+ 3. **Root cause targeting:** The fix must address the root cause identified in the bug's data flow trace, not a symptom. If the root cause is in a different location than the symptom, fix at the root.
355
+ 4. **Mark as SUGGESTED:** Every fix must be clearly marked as `SUGGESTED (REVIEW REQUIRED)` — never imply auto-application.
356
+ 5. **One fix per bug:** Each bug gets exactly one suggested fix. If multiple fix strategies exist, choose the most conservative one and note alternatives.
357
+ 6. **Preserve behavior:** The fix must not change behavior beyond correcting the identified bug. No side-effect improvements.
358
+ 7. **Skip when inappropriate:** Mark fix as `N/A` for bugs where the fix requires architectural changes, significant refactoring, or domain knowledge beyond what the code provides.
359
+
360
+ Reference: Meta SapFix — automated fix suggestion with human-in-the-loop validation.
361
+
362
+ ## Output Format
363
+
364
+ For each verified bug:
365
+
366
+ ```markdown
367
+ ### [SEVERITY] Category: Brief Title
368
+
369
+ **Location:** `path/to/file.ts:123`
370
+ **Confidence:** [CONFIRMED | HIGH | MEDIUM]
371
+
372
+ **Code Evidence:**
373
+ ```[language]
374
+ // The actual problematic code
375
+ ```
376
+
377
+ **Data Flow Trace:**
378
+ [How data reaches this point: caller → caller → this function]
379
+
380
+ **Issue:** [Precise technical description of what is wrong]
381
+
382
+ **Impact:** [User-visible effect or system failure mode]
383
+
384
+ **Verification Done:**
385
+ - [x] Traced code path from [entry point]
386
+ - [x] Checked architecture.md — not intentional
387
+ - [x] Verified framework doesn't handle this
388
+ - [x] No upstream guards found in [files checked]
389
+
390
+ **Why Not a False Positive:**
391
+ [Explicit statement: "No sanitization exists because X", "Framework Y doesn't escape Z in this context", etc.]
392
+
393
+ **Fix:** [Minimal code change or mitigation]
394
+
395
+ **Suggested Fix (REVIEW REQUIRED):**
396
+ ```[language]
397
+ // BEFORE (current buggy code):
398
+ [exact code snippet from the codebase]
399
+
400
+ // AFTER (suggested fix):
401
+ [minimal change that addresses root cause]
402
+ ```
403
+ _This fix is SUGGESTED only — human review required before applying. Reference: Meta SapFix methodology._
404
+
405
+ **Regression Test:**
406
+ **Status:** [COVERED | PARTIAL | WRONG_ASSERTION | NO_COVERAGE | N/A]
407
+ **Existing Test:** [`path/to/test_file:line` — test name | None found]
408
+ [Action: existing test reference, proposed modification, or new test case]
409
+ ```[language]
410
+ // New or modified test case (omit if COVERED or N/A)
411
+ ```
412
+ ```
413
+
414
+ **Example — COVERED (no new test needed):**
415
+ ```markdown
416
+ **Regression Test:**
417
+ **Status:** COVERED — existing test already catches this bug
418
+ **Existing Test:** `tests/validator_test.cpp:89` — `TEST(Validator, RejectsScriptTags)`
419
+ No new test needed. Existing test fails when XSS sanitization is removed.
420
+ ```
421
+
422
+ **Example — PARTIAL (C++ / GTest):**
423
+ ```markdown
424
+ **Regression Test:**
425
+ **Status:** PARTIAL — tests exist for processInput() but miss unsanitized HTML path
426
+ **Existing Test File:** `tests/input_test.cpp`
427
+ **Modification:** Add to existing file:
428
+ ```cpp
429
+ TEST(InputSanitization, RejectsMaliciousScript) {
430
+ std::string malicious = "<script>alert('xss')</script>";
431
+ std::string result = processInput(malicious);
432
+ EXPECT_EQ(result.find("<script>"), std::string::npos)
433
+ << "Input should be sanitized to remove script tags";
434
+ }
435
+ ```
436
+ ```
437
+
438
+ **Example — NO_COVERAGE (Python / pytest):**
439
+ ```markdown
440
+ **Regression Test:**
441
+ **Status:** NO_COVERAGE — no tests found for process_input()
442
+ **Target File:** `tests/test_input_processor.py` (new file)
443
+ ```python
444
+ import pytest
445
+ from input.processor import process_input
446
+
447
+ def test_rejects_malicious_script():
448
+ """Input should be sanitized to remove script tags."""
449
+ malicious = "<script>alert('xss')</script>"
450
+ result = process_input(malicious)
451
+ assert "<script>" not in result, "XSS script tag should be stripped"
452
+ # Expected: FAILS against current code (passes XSS through), PASSES after fix
453
+ ```
454
+ ```
455
+
456
+ **Example — NO_COVERAGE (Go / testing):**
457
+ ```markdown
458
+ **Regression Test:**
459
+ **Status:** NO_COVERAGE — no tests found for ProcessInput()
460
+ **Target File:** `input/processor_test.go` (new file)
461
+ ```go
462
+ package input
463
+
464
+ import (
465
+ "strings"
466
+ "testing"
467
+ )
468
+
469
+ func TestProcessInputRejectsMaliciousScript(t *testing.T) {
470
+ malicious := "<script>alert('xss')</script>"
471
+ result := ProcessInput(malicious)
472
+ if strings.Contains(result, "<script>") {
473
+ t.Error("XSS script tag should be stripped from input")
474
+ }
475
+ }
476
+ // Expected: FAILS against current code (passes XSS through), PASSES after fix
477
+ ```
478
+ ```
479
+
480
+ **Example — N/A (not testable, but still report the bug):**
481
+ ```markdown
482
+ **Regression Test:**
483
+ **Status:** N/A — environment config, no executable code path
484
+ **Reason:** Bug is in `config/production.yaml` which sets incorrect timeout value. Config files are not unit-testable; fix requires changing the YAML value directly.
485
+ ```
486
+
487
+ Severity levels:
488
+ - **Critical** — Blocks release, breaks functionality, security issue
489
+ - **Important** — Degrades quality, creates tech debt
490
+ - **Minor** — Style, optimization, edge cases
491
+
492
+ ## Report Generation
493
+
494
+ Generate report at:
495
+ - **Project-level:** `draft/bughunt-report-<timestamp>.md` (where `<timestamp>` is generated via `date +%Y-%m-%dT%H%M`, e.g., `2026-03-15T1430`)
496
+ - **Track-level:** `draft/tracks/<track-id>/bughunt-report-<timestamp>.md` (if analyzing specific track)
497
+
498
+ After writing the timestamped report, create a symlink pointing to it:
499
+ ```bash
500
+ # Project-level
501
+ ln -sf bughunt-report-<timestamp>.md draft/bughunt-report-latest.md
502
+
503
+ # Track-level
504
+ ln -sf bughunt-report-<timestamp>.md draft/tracks/<track-id>/bughunt-report-latest.md
505
+ ```
506
+
507
+ Previous timestamped reports are preserved. The `-latest.md` symlink always points to the most recent report.
508
+
509
+ **MANDATORY: Include YAML frontmatter with git metadata.** Follow the procedure in `core/shared/git-report-metadata.md` to gather git info and generate the frontmatter. Use `generated_by: "draft:bughunt"`.
510
+
511
+ Report structure:
512
+
513
+ ```markdown
514
+ [YAML frontmatter — see core/shared/git-report-metadata.md]
515
+
516
+ # Bug Hunt Report
517
+
518
+ [Report header table — see core/shared/git-report-metadata.md]
519
+
520
+ **Scope:** [Entire repo | Specific paths | Track: <track-id>]
521
+ **Draft Context:** [Loaded | Not available]
522
+
523
+ ## Summary
524
+
525
+ | Severity | Count | Confirmed | High Confidence |
526
+ |----------|-------|-----------|-----------------|
527
+ | Critical | N | X | Y |
528
+ | Important | N | X | Y |
529
+ | Minor | N | X | Y |
530
+
531
+ ## Critical Issues
532
+
533
+ [Issues...]
534
+
535
+ ## Important Issues
536
+
537
+ [Issues...]
538
+
539
+ ## Minor Issues
540
+
541
+ [Issues...]
542
+
543
+ ## Dimensions With No Findings
544
+
545
+ | Dimension | Status |
546
+ |-----------|--------|
547
+ | Correctness | No bugs found |
548
+ | Reliability | N/A — no runtime application |
549
+ | Performance | N/A — static site, no dynamic content |
550
+ | Concurrency | N/A — no async operations |
551
+
552
+ ## Regression Test Suite
553
+
554
+ **Language:** [detected language]
555
+ **Test Framework:** [detected framework]
556
+ **Validation Command:** [command used]
557
+
558
+ ### Test Discovery Summary
559
+
560
+ | # | Bug Title | Severity | Status | Existing Test | Action |
561
+ |---|-----------|----------|--------|---------------|--------|
562
+ | 1 | [Brief title] | [SEV] | COVERED | `path:line` | None needed |
563
+ | 2 | [Brief title] | [SEV] | PARTIAL | `path:line` | Added case to existing file |
564
+ | 3 | [Brief title] | [SEV] | WRONG_ASSERTION | `path:line` | Fixed assertion |
565
+ | 4 | [Brief title] | [SEV] | NO_COVERAGE | — | Created new test |
566
+ | 5 | [Brief title] | [SEV] | N/A | — | Not testable |
567
+
568
+ ### Validation Status
569
+
570
+ | # | Bug Title | Test File / Target | Validation Status |
571
+ |---|-----------|-------------------|-------------------|
572
+ | 2 | [Brief title] | `tests/test_foo.py` | BUILD_OK (modified) |
573
+ | 3 | [Brief title] | `tests/test_bar.py:67` | BUILD_OK (modified) |
574
+ | 4 | [Brief title] | `tests/test_baz.py` | BUILD_OK (new) |
575
+ | 5 | [Brief title] | — | SKIPPED (N/A) |
576
+
577
+ ```
578
+ Validation Summary: 3 BUILD_OK, 0 BUILD_FAILED, 1 SKIPPED
579
+ Validation Command: python -m py_compile <file>
580
+ ```
581
+
582
+ ### New Tests Written (NO_COVERAGE)
583
+
584
+ New test files created for bugs with no existing test coverage.
585
+
586
+ | Bug # | File Created | Build Target / Runner |
587
+ |-------|-------------|----------------------|
588
+ | 4 | `tests/test_baz.py` | `pytest tests/test_baz.py` |
589
+
590
+ ```[language]
591
+ // Contents of new test file
592
+ ```
593
+
594
+ ### Modifications Applied (PARTIAL / WRONG_ASSERTION)
595
+
596
+ Changes applied to existing test files.
597
+
598
+ | File | Bug # | Change Applied |
599
+ |------|-------|----------------|
600
+ | `tests/test_foo.py` | 2 | Added `test_missing_case()` |
601
+ | `tests/test_bar.py:67` | 3 | Changed `assert result == 0` → `assert result == 1` |
602
+
603
+ ### Already Covered (COVERED)
604
+
605
+ Bugs already caught by existing tests — no action needed.
606
+
607
+ | Bug # | Bug Title | Existing Test |
608
+ |-------|-----------|---------------|
609
+ | 1 | [Brief title] | `tests/test_foo.py:45` — `test_sanitize_input()` |
610
+
611
+ ### Not Testable (N/A)
612
+
613
+ Bugs that cannot have automated regression tests (config issues, documentation, LLM workflows, etc.).
614
+
615
+ | Bug # | Bug Title | Reason |
616
+ |-------|-----------|--------|
617
+ | 6 | [Brief title] | Config file — no executable code |
618
+ ```
619
+
620
+ ## Final Instructions
621
+
622
+ **CRITICAL: All verified bugs appear in the main report body.** The Regression Test Suite section organizes test artifacts, but every bug — regardless of whether a test can be written — MUST be documented in the severity sections (Critical/Important/Minor Issues) above. Bugs with `N/A` regression test status are still valid bugs that need reporting.
623
+
624
+ **CRITICAL: Regression tests are supplementary, not a filter.** If no test framework is detected, or if a bug cannot have a test written (config, docs, LLM workflows), mark it as `N/A` and **still include the bug in the report**. Never skip a verified bug because you cannot write a test for it.
625
+
626
+ - **No unverified bugs** — Every finding must pass the verification protocol
627
+ - **Evidence required** — Include code snippets and trace for every bug
628
+ - **Explicit false positive elimination** — State why each bug isn't handled elsewhere
629
+ - Analyze all applicable dimensions — skip N/A dimensions explicitly with reason (see Dimension Applicability Check)
630
+ - Assume the reader is a senior engineer who will verify your findings
631
+ - If Draft context is available, explicitly note which architectural violations or product requirement bugs were found
632
+ - Be precise about file locations and line numbers
633
+ - Include git branch and commit in report header
634
+ - **Write regression tests when possible** — If a test framework is detected, write test files using the project's native framework (Steps 4-6). If no framework exists, skip Steps 2-6 and mark all bugs as `N/A` for regression tests
635
+ - **Never modify production code** — Only create/modify test files and their build configs
636
+ - **Validate before reporting** — If tests were written, validate syntax/compilation before finalizing; include validation status in the report
637
+ - **Respect project conventions** — Match existing test directory structure, naming patterns, import conventions, and framework idioms
638
+ - **Use native frameworks** — pytest for Python, `go test` for Go, GTest for C++, Jest/Vitest for JS/TS, `cargo test` for Rust, JUnit for Java — never force a foreign test framework
639
+ - **Learn from findings** — After report generation, execute the pattern learning phase from `core/shared/pattern-learning.md` to update `draft/guardrails.md` with newly discovered conventions and anti-patterns
640
+
641
+ ---
642
+
643
+ ## Cross-Skill Dispatch
644
+
645
+ ### Suggestions at Completion
646
+
647
+ After bughunt report generation:
648
+
649
+ **If critical bugs found:**
650
+ ```
651
+ "Critical bugs found. Consider:
652
+ → /draft:debug — Run structured debug session on critical finding #{n}
653
+ → git bisect — Find the exact commit that introduced the bug"
654
+ ```
655
+
656
+ ### Test Writing Guardrail
657
+
658
+ When offering to write regression tests for found bugs:
659
+ ```
660
+ ASK: "Want me to write regression tests for the {n} bugs found? [Y/n]"
661
+ ```
662
+ Never auto-write tests — always ask first.
663
+
664
+ ### Jira Sync
665
+
666
+ If Jira ticket linked, sync via `core/shared/jira-sync.md`:
667
+ - Attach `bughunt-report-latest.md` to ticket
668
+ - Post comment: "[draft] bughunt-complete: Found {n} issues — {critical} critical, {major} major."