@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,53 @@
1
+ ---
2
+ name: integrations
3
+ description: "Canonical integrations parent command. Handles external system exports and syncs. Routes intent to jira-preview or jira-create based on context."
4
+ ---
5
+
6
+ # Integrations Workflows
7
+
8
+ `/draft:integrations` is the **canonical integrations parent command**.
9
+
10
+ It handles connectors and exports to external systems like Jira.
11
+
12
+ Specialist integration workflows remain available as named modes:
13
+
14
+ - `/draft:jira preview` (or `/draft:integrations jira-preview`)
15
+ - `/draft:jira create` (or `/draft:integrations jira-create`)
16
+
17
+ ## Step 1: Parse Intent and Route
18
+
19
+ Examine the user's input and route to the correct integrations workflow.
20
+
21
+ ### Explicit Named Modes
22
+
23
+ If the user explicitly invokes a specialist mode, route directly:
24
+
25
+ - `/draft:integrations jira-preview` → follow `/draft:jira preview`
26
+ - `/draft:integrations jira-create` → follow `/draft:jira create`
27
+
28
+ ### Intent Routing
29
+
30
+ If no explicit mode is specified, infer the intent from the user's prompt:
31
+
32
+ | Intent | Action | Route |
33
+ |--------|--------|-------|
34
+ | "Export to Jira", "Preview Jira issues", "Show me what you'll create in Jira" | Jira Preview | `/draft:jira preview` |
35
+ | "Create Jira issues", "Sync to Jira", "Make tickets" | Jira Create | `/draft:jira create` |
36
+
37
+ ## Step 2: Bare Parent Command Fallback
38
+
39
+ If the user runs a bare `/draft:integrations` without clear intent, present a small integrations menu with a recommended default path:
40
+
41
+ ```text
42
+ Draft Integrations Menu:
43
+ 1. /draft:integrations jira-preview (Generate Jira export file for review)
44
+ 2. /draft:integrations jira-create (Create Jira issues from export)
45
+
46
+ What integration action do you want to perform?
47
+ ```
48
+
49
+ Do not automatically launch a specialist workflow without explicit or clear inferred intent.
50
+
51
+ ## Compatibility Note
52
+
53
+ The legacy specialist commands remain supported during the migration period, but `/draft:integrations` is the canonical parent for integration tasks.
@@ -0,0 +1,577 @@
1
+ ---
2
+ name: jira
3
+ description: Unified Jira entry point. Routes to preview (default), create, or review subcommands.
4
+ ---
5
+
6
+ # Jira
7
+
8
+ Single entry point for all Jira workflows: preview Draft tracks as Jira issues, create them via MCP (default = 1 Story per track; --epic = 1 Epic + 1-3 Stories), and review any Jira ticket (epic, story, bug, sub-task) end-to-end.
9
+
10
+
11
+ ## Subcommand Routing
12
+
13
+ Parse `$ARGUMENTS` and dispatch:
14
+
15
+ | User Intent | Subcommand | Behavior |
16
+ |-------------|------------|----------|
17
+ | `(no args)`, `preview`, `preview <track-id>` | **preview** (default) | Generate `jira-export-<timestamp>.md` — **one Story** containing all phases/tasks |
18
+ | `preview --epic ...` | **preview --epic** | Generate rich export: 1 Epic + 1–3 Stories (max) |
19
+ | `create`, `create <track-id>` | **create** | Create **1 Story** (default) via MCP |
20
+ | `review <JIRA_ID>` | **review** | Full qualification review of any Jira ticket — delegates to [references/review.md](references/review.md) |
21
+
22
+ - `preview` is the default when no subcommand is supplied.
23
+ - `review` requires a Jira ID as the next argument. Validate format `<PROJECT>-<NUMBER>` (e.g., `ENG-446236`). If numeric-only, prompt for project prefix — do NOT assume.
24
+
25
+ ---
26
+
27
+ ## Jira Configuration (Shared)
28
+
29
+ All subcommands read project-level Jira configuration from `draft/workflow.md` under a `## Jira` section:
30
+
31
+ ```markdown
32
+ ## Jira
33
+
34
+ Project Key: <KEY>
35
+ Integration: jira-mcp
36
+ Team: <team-name>
37
+ Component: <component-name>
38
+ Swimlane: <swimlane-name>
39
+ Assignee Display Name: <assignee-name>
40
+ ```
41
+
42
+ - **Project Key** — required for `create`. If missing, prompt and persist.
43
+ - **Integration** — informational; defaults to `jira-mcp` if absent.
44
+ - **Team / Component / Swimlane / Assignee Display Name** — applied as defaults to every issue created by `create`. Empty values are skipped (Jira ignores blank fields).
45
+
46
+ If a value is missing when needed:
47
+ 1. Prompt the user for it.
48
+ 2. Append to (or create) the `## Jira` section in `draft/workflow.md` so subsequent runs reuse it.
49
+
50
+ ---
51
+
52
+ ## Jira Content Hygiene (Mandatory)
53
+
54
+ When writing any text that will go into Jira (descriptions, summaries, bug details):
55
+
56
+ - Be **minimal, concise, and precise**.
57
+ - Do **not** dump full plans, long task lists, verbose context, or Draft-internal reasoning into Jira.
58
+ - Use short summaries + key outcomes only.
59
+ - Structured content (phases, tasks) may be included as compact markdown, but keep it brief.
60
+ - Never pollute Jira with excessive text.
61
+
62
+ This rule applies to both `preview` generation and `create` descriptions.
63
+
64
+ ---
65
+
66
+ # Subcommand: preview
67
+
68
+ Generate a timestamped `jira-export-<timestamp>.md` (with `jira-export-latest.md` symlink) from the active track's plan for review and editing before creating Jira issues.
69
+
70
+ **Flag handling:** Check `$ARGUMENTS` for `--epic` at the very start of this section. If present, set `EPIC_MODE=true` and remove the flag from the working arguments. This flag changes the entire output structure (see Step 2).
71
+
72
+ ## Red Flags — STOP if you're:
73
+
74
+ - Generating a preview without an approved plan.md
75
+ - Assigning story points inconsistent with task count
76
+ - Missing sub-tasks that exist in plan.md
77
+ - Not including quality findings when review/bughunt reports exist
78
+ - Overwriting a reviewed jira-export without warning the user
79
+
80
+ **Plan first, then preview. Accuracy over speed.**
81
+
82
+ ---
83
+
84
+ ## Standard File Metadata
85
+
86
+ The generated `jira-export-<timestamp>.md` MUST include the standard YAML frontmatter for traceability and sync verification.
87
+
88
+ ### Gathering Git Information
89
+
90
+ ```bash
91
+ basename "$(pwd)" # Project name
92
+ git branch --show-current # Local branch
93
+ git rev-parse --abbrev-ref --symbolic-full-name @{upstream} 2>/dev/null || echo "none"
94
+ git rev-parse HEAD # Full SHA
95
+ git rev-parse --short HEAD # Short SHA
96
+ git log -1 --format="%ci" # Commit date
97
+ git log -1 --format="%s" # Commit subject
98
+ git status --porcelain | head -1 # Dirty check
99
+ ```
100
+
101
+ ### Metadata Template
102
+
103
+ ```yaml
104
+ ---
105
+ project: "{PROJECT_NAME}"
106
+ module: "root"
107
+ track_id: "{TRACK_ID}"
108
+ generated_by: "draft:jira:preview"
109
+ generated_at: "{ISO_TIMESTAMP}"
110
+ git:
111
+ branch: "{LOCAL_BRANCH}"
112
+ remote: "{REMOTE/BRANCH or 'none'}"
113
+ commit: "{FULL_SHA}"
114
+ commit_short: "{SHORT_SHA}"
115
+ commit_date: "{COMMIT_DATE}"
116
+ commit_message: "{FIRST_LINE_OF_COMMIT_MESSAGE}"
117
+ dirty: {true|false}
118
+ synced_to_commit: "{FULL_SHA}"
119
+ ---
120
+ ```
121
+
122
+ ---
123
+
124
+ ## Mapping Structure
125
+
126
+
127
+ ### Default behavior (recommended)
128
+
129
+ - Every track becomes **exactly 1 Story**.
130
+ - All phases and their tasks are included **inside the Story description** (as markdown sections).
131
+ - No child Jira issues are created.
132
+
133
+ This keeps Jira clean and keeps the export focused on root issues by default.
134
+
135
+ ### Opt-in rich hierarchy (`--epic`)
136
+
137
+ Use `/draft:jira preview --epic` or `/draft:jira create --epic` when you want an Epic.
138
+
139
+ **Splitting rule (simple):**
140
+ - 5 or fewer phases → **1 Story** under the Epic
141
+ - More than 5 phases → split across **2 or 3 Stories** (maximum)
142
+
143
+ All detailed tasks remain inside the Story descriptions — we never create Jira Tasks or Sub-tasks.
144
+
145
+ ### Summary of mappings
146
+
147
+ | Flag | Root Issue | Child Issues | Where phases/tasks live |
148
+ |------------|------------|-----------------------|---------------------------------------------|
149
+ | (default) | 1 Story | None | Inside the single Story description |
150
+ | `--epic` | 1 Epic | 1–3 Stories (max) | Distributed across the Story descriptions |
151
+
152
+ ## Step 1: Load Context
153
+
154
+ 1. Capture git context (commands above).
155
+ 2. Find the active track from `draft/tracks.md` (look for `[~] In Progress` or first `[ ]`). If a track ID is provided in `$ARGUMENTS`, use that instead.
156
+ 3. Read the track's `plan.md` for phases and tasks.
157
+ 4. Read the track's `metadata.json` for title and type.
158
+ 5. Read the track's `spec.md` for root-issue description.
159
+ 6. Check for quality reports:
160
+ - `draft/tracks/<id>/review-report-latest.md` — review findings (from `/draft:review`)
161
+ - `draft/tracks/<id>/bughunt-report-latest.md` — defect findings
162
+ 7. Read `draft/workflow.md` → `## Jira` section for shared config (see Jira Configuration above).
163
+
164
+ If no track found: tell the user "No track found. Run `/draft:new-track` to create one, or specify track ID."
165
+
166
+ ## Step 2: Determine Export Mode, Count Phases, and Group Content
167
+
168
+ ### 2.1 Detect Mode
169
+ - If `EPIC_MODE=true` (from `--epic` flag), use Epic + Stories mode.
170
+ - Otherwise, use **default single-Story mode**.
171
+
172
+ ### 2.2 Count Phases and Decide Story Count (Epic Mode Only)
173
+ Count the number of `## Phase` sections in `plan.md`.
174
+
175
+ **Splitting guideline (when using --epic):**
176
+ - Phases ≤ 5 → 1 Story under the Epic
177
+ - Phases 6–12 → 2 Stories under the Epic
178
+ - Phases > 12 → 3 Stories under the Epic (hard cap)
179
+
180
+ Store the target number of stories: `TARGET_STORIES`.
181
+
182
+ ### 2.3 Group Phases (for Epic Mode)
183
+ Divide the phases as evenly as possible across `TARGET_STORIES`.
184
+
185
+ Example grouping (store this in memory):
186
+ - Story 1 gets phases 1..K
187
+ - Story 2 gets phases K+1..M
188
+ - Story 3 gets remaining phases
189
+
190
+ In **default mode**, ignore grouping — everything goes under one Story.
191
+
192
+ ### 2.4 Build Data Structures
193
+ For every phase:
194
+ - Capture Phase name, Goal, Verification
195
+ - Collect all its tasks (with status)
196
+
197
+ Calculate total story points using the existing simple table (1-2 tasks = 1pt, 3-4=2pt, 5-6=3pt, 7+=5pt). This total goes on the root issue (or split across stories in epic mode if desired — default is to put total on the first Story).
198
+
199
+ ### 2.5 Root Issue Data
200
+ - Summary = Track title
201
+ - Description base = content from `spec.md` (first 2-3 paragraphs) + later the full structured plan
202
+ - Issue Type = "Story" (default) or "Epic" (--epic)
203
+
204
+ ## Step 3: Extract Quality Findings (if reports exist)
205
+
206
+ If `review-report-latest.md` or `bughunt-report-latest.md` exists in the track directory:
207
+
208
+ ### From `bughunt-report-latest.md`
209
+
210
+ 1. Parse findings by severity (Critical, High, Medium, Low).
211
+ 2. Extract all sections for each bug: Location, Confidence, Code Evidence, Data Flow Trace, Issue, Impact, Verification Done, Why Not a False Positive, Fix, Regression Test.
212
+ 3. Group by severity for the export.
213
+
214
+ ### From `review-report-latest.md`
215
+
216
+ 1. Parse findings from review report stages — Stage 1: Automated Validation (Architecture Conformance, Dead Code, Dependency Cycles, Security Scan, Performance), Stage 2: Spec Compliance, Stage 3: Code Quality (Architecture, Error Handling, Testing, Maintainability).
217
+ 2. Extract for each finding: Severity (Critical ✗ / Warning ⚠), Category, Location, Issue, Risk/Impact, Fix.
218
+ 3. Group by severity for the export.
219
+
220
+ **Critical/High findings** should be highlighted — consider suggesting additional stories or tasks to address them before the track is complete.
221
+
222
+ ## Step 4: Generate the Export File
223
+
224
+ ```bash
225
+ TIMESTAMP=$(date +%Y-%m-%dT%H%M)
226
+ EXPORT_FILE="draft/tracks/<track_id>/jira-export-${TIMESTAMP}.md"
227
+ SYMLINK="draft/tracks/<track_id>/jira-export-latest.md"
228
+ ```
229
+
230
+ Create the file and the `latest` symlink.
231
+
232
+ ### 4.1 Write Frontmatter + Header
233
+ Use the standard YAML frontmatter.
234
+ Add a `mode: default` or `mode: epic` field.
235
+
236
+ Write a clean summary table.
237
+
238
+ ### 4.2 Write Root Issue Section
239
+
240
+ **Jira Content Rule:** Keep the description **minimal and focused**. Use short paragraphs. Do not dump full plans or verbose reasoning. Structured phases/tasks must be compact.
241
+
242
+ **Always start with:**
243
+
244
+ ```markdown
245
+ ## Root Issue
246
+
247
+ **Summary:** [Track Title]
248
+ **Issue Type:** Story # or Epic when --epic
249
+ **Labels:** draft
250
+ **Description:**
251
+ {noformat}
252
+ [First 2-3 paragraphs from spec.md]
253
+
254
+ ## Plan
255
+ ```
256
+
257
+ Then render the plan content **concisely**:
258
+
259
+ - In **default mode**: Render **all** phases as `### Phase X: Name` headings, with Goal, Verification, and a compact task checklist under each.
260
+ - In **--epic mode**: If this is the root Epic section, put a short overview only.
261
+
262
+ Include the Draft signature at the bottom of the description.
263
+
264
+ ### 4.3 Write Story Sections (only in --epic mode)
265
+
266
+ **Jira Content Rule:** Keep every Story description **short and scannable**. Use compact headings and minimal text.
267
+
268
+ If `mode: epic`:
269
+ - Emit 1 to 3 `## Story N: [Short Title]` blocks (using the grouping decided in Step 2).
270
+ - Under each Story, put the phases assigned to it as `### Phase ...` + **compact** task checklists.
271
+ - Each Story gets its share of the total story points (or put the total on the first one — simple is fine).
272
+
273
+ ### 4.4 Write Bug Issues Section (always)
274
+
275
+ Use the existing high-quality bug export format from `bughunt-report-latest.md`.
276
+ These will become real Bug issues linked to the root (Epic or the main Story).
277
+
278
+ ### 4.5 Final Notes in the Export
279
+ Add at the top:
280
+
281
+ > Default = 1 Story. Use `--epic` for 1 Epic + 1-3 Stories.
282
+
283
+ Update the symlink.
284
+
285
+ ## Step 5: Report
286
+
287
+ ```
288
+ Jira Preview Generated
289
+
290
+ Track: [track_id] - [title]
291
+ Mapping: [story-rooted | epic-rooted] (phases: N)
292
+ Export: draft/tracks/<id>/jira-export-<timestamp>.md
293
+ Symlink: draft/tracks/<id>/jira-export-latest.md
294
+
295
+ Summary:
296
+ - 1 root issue ({Story | Epic})
297
+ - N mid-level issues ({Tasks | Stories})
298
+ - M leaf issues (Sub-tasks)
299
+ - P total story points
300
+ - B bugs (from bughunt-report-latest.md)
301
+
302
+ Breakdown:
303
+ - Phase 1: [name] - X pts, Y tasks
304
+ - Phase 2: [name] - X pts, Y tasks
305
+ - ...
306
+
307
+ Bugs (if bughunt-report-latest.md exists):
308
+ - X critical bugs
309
+ - Y high bugs
310
+ - Z medium/low bugs
311
+
312
+ Next steps:
313
+ 1. Review and edit the export via jira-export-latest.md (adjust points, descriptions, leaf issues, bug priorities)
314
+ 2. Run `/draft:jira create` to create issues in Jira
315
+ ```
316
+
317
+ ## Error Handling (preview)
318
+
319
+ **plan.md has no phases:**
320
+ - Tell user: "No phases found in plan.md. Run `/draft:new-track` to generate a proper plan."
321
+
322
+ **spec.md missing:**
323
+ - Use `plan.md` overview for root-issue description.
324
+ - Warn: "spec.md not found, using plan overview for root-issue description."
325
+
326
+ **jira-export-latest.md already exists:**
327
+ - Check if the target file has been manually modified (user-added content not matching generated patterns — edited descriptions, added rows, changed story points from generated values).
328
+ - If modifications detected, prompt: "Existing jira-export appears to have manual edits. Overwrite? [y/N]"
329
+ - If unmodified, proceed with regeneration (new timestamped file + updated symlink).
330
+
331
+ **Phase has no tasks:**
332
+ - Create mid-level issue with 1 story point.
333
+ - Add note: "No leaf issues defined for this phase."
334
+
335
+ ---
336
+
337
+ # Subcommand: create
338
+
339
+ Create Jira issues from `jira-export-latest.md` using MCP-Jira. If no export file exists, auto-generates one first by running the `preview` subcommand.
340
+
341
+ ## Red Flags — STOP if you're:
342
+
343
+ - Creating Jira issues without reviewing `jira-export-latest.md` first (run `/draft:jira preview`)
344
+ - Proceeding when MCP-Jira is not configured
345
+ - Creating duplicate issues (check if jira-export-latest.md already has Jira keys)
346
+ - Not verifying the target Jira project before creation
347
+ - Skipping the export file update after issue creation
348
+
349
+ **Preview before you create. Never create duplicates.**
350
+
351
+ **Default = 1 Story only.** Use `--epic` when you want an Epic + 1–3 Stories. We never create Jira Tasks or Sub-tasks.
352
+
353
+ ---
354
+
355
+ ## Step 1: Load Context
356
+
357
+ 1. Capture git context (commands above).
358
+ 2. Find the active track from `draft/tracks.md`. If a track ID is provided in `$ARGUMENTS`, use that.
359
+ 3. Check for `draft/tracks/<track_id>/jira-export-latest.md`.
360
+
361
+ If no track found: tell user "No track found. Run `/draft:new-track` to create one, or specify track ID."
362
+
363
+ ## Step 2: Ensure Export Exists
364
+
365
+ **If `jira-export-latest.md` exists:** read and parse it (follow the symlink to the timestamped file). Proceed to Step 3.
366
+
367
+ **If missing:** inform user "No jira-export-latest.md found. Generating preview first..." then execute the `preview` subcommand. Proceed to Step 3.
368
+
369
+ ## Step 3: Check MCP-Jira Availability
370
+
371
+ Detect MCP-Jira tools. Known tool name variants: `mcp_jira_create_issue`, `jira_createIssue`, `create_jira_issue`, `jira-create-issue`. Use whichever is available.
372
+
373
+ If unavailable:
374
+
375
+ ```
376
+ MCP-Jira not configured.
377
+
378
+ To create issues:
379
+ 1. Configure MCP-Jira server in your settings
380
+ 2. Run `/draft:jira create` again
381
+
382
+ Or manually import from:
383
+ draft/tracks/<id>/jira-export-latest.md
384
+ ```
385
+
386
+ Stop execution.
387
+
388
+ ## Step 4: Parse Export File (Export Format)
389
+
390
+ Read the `mode` field from frontmatter:
391
+ - `default` → expect 1 root Story
392
+ - `epic` → expect 1 Epic + 1–3 Stories
393
+
394
+ ### Root Issue(s)
395
+ - Parse the `## Root Issue` (and any `## Story N:` sections if mode=epic).
396
+ - For each Story section: Summary, Description (which now contains the phases and task checklists), story points if present.
397
+
398
+ ### Bug Issues
399
+ Parse the `## Bug Issues` section completely (same as before). These are always created as separate Bug issues.
400
+
401
+ **Important:** There are no longer "Mid-Level" or "Leaf Issues" tables that become separate Jira Tasks/Sub-tasks. All work items live inside the Story description(s).
402
+
403
+ ## Step 4b: Resolve Jira Configuration
404
+
405
+ Read `draft/workflow.md` → `## Jira` section. Required fields and behavior:
406
+
407
+ | Field | Required? | Behavior if missing |
408
+ |-------|-----------|---------------------|
409
+ | Project Key | Yes | Prompt user; append to `## Jira` section |
410
+ | Integration | No | Defaults to `jira-mcp` |
411
+ | Team | No | Skip — not applied to issues |
412
+ | Component | No | Skip |
413
+ | Swimlane | No | Skip |
414
+ | Assignee Display Name | No | Skip |
415
+
416
+ When prompting for a missing field, append to `draft/workflow.md`:
417
+
418
+ ```markdown
419
+ ## Jira
420
+
421
+ Project Key: <KEY>
422
+ Integration: jira-mcp
423
+ Team: <team-name>
424
+ Component: <component-name>
425
+ Swimlane: <swimlane-name>
426
+ Assignee Display Name: <assignee-name>
427
+ ```
428
+
429
+ ### Validate Project Key
430
+
431
+ Before creating issues, attempt to fetch project metadata via MCP to verify the project key exists:
432
+
433
+ ```
434
+ MCP call: get_project (or equivalent)
435
+ - project: [project key]
436
+ ```
437
+
438
+ If invalid: "Jira project '[KEY]' not found. Verify the project key and try again." Stop execution.
439
+
440
+ ### Resolve Assignee
441
+
442
+ If `Assignee Display Name` is provided, resolve to an account ID via MCP user search (e.g., `find_users(query=<display_name>)`). Cache the resolved ID for the session. If resolution fails, warn and create issues unassigned rather than failing.
443
+
444
+ ## Step 5: Create Issues via MCP
445
+
446
+ **Pin the symlink target:** At the start of this step, resolve the symlink to its actual timestamped file path (e.g., via `readlink -f jira-export-latest.md`). Use the resolved path for all subsequent writes to prevent data loss if the symlink is updated mid-run.
447
+
448
+ **Incremental persistence:** After creating each issue, immediately update the corresponding entry in the export file with the Jira key. This ensures re-runs can skip already-created items even if the process fails mid-way.
449
+
450
+ **Note:** Some Jira configurations do not allow setting status during creation. If status setting fails, create in default status and log a warning.
451
+
452
+ ### Shared field defaults
453
+
454
+ Apply these to every `create_issue` call (omit any that resolved to empty in Step 4b):
455
+
456
+ ```
457
+ - project: [Project Key]
458
+ - labels: ["draft"]
459
+ - component: [Component if set]
460
+ - assignee: [Resolved account ID if set]
461
+ - custom_field_swimlane: [Swimlane if set] # field ID is Jira-config specific
462
+ - custom_field_team: [Team if set] # field ID is Jira-config specific
463
+ ```
464
+
465
+ > Swimlane and Team are often custom fields. If your Jira project uses different field IDs, configure your MCP server's field mapping. Unknown fields will be rejected — log the rejection and continue without them.
466
+
467
+ ### 5a. Create Root Issue(s)
468
+
469
+ - If mode = default: Create **1 Story**.
470
+ - If mode = epic: Create **1 Epic**, then create the 1–3 Stories (using the sections from the export file) and link them to the Epic.
471
+
472
+ For each Story/Epic:
473
+ **Jira Content Rule (strict):** The description sent to Jira must be concise. Use short summaries and compact structured sections only. Do not include long reasoning or exhaustive lists.
474
+
475
+ ```
476
+ MCP call: create_issue
477
+ - issue_type: Story or Epic
478
+ - summary: ...
479
+ - description: [concise content — phases as compact sections, tasks as short checklists]
480
+ + shared field defaults
481
+ ```
482
+ Capture the keys.
483
+
484
+ ### 5b. Create Bug Issues (from Bug Hunt Report)
485
+
486
+ For every bug parsed in Step 4, create a real **Bug** issue:
487
+
488
+ ```
489
+ MCP call: create_issue
490
+ - issue_type: Bug
491
+ - summary: ...
492
+ - description: [full bughunt evidence]
493
+ - parent / epic_link: [link to the root Story or Epic]
494
+ - priority: [from severity]
495
+ + shared field defaults
496
+ ```
497
+
498
+ **Detailed work lives inside the root issue description(s) by default.** All detailed work lives inside the Story descriptions.
499
+
500
+ ## Step 6: Finalize Tracking
501
+
502
+ Export file has already been updated incrementally during Step 5. Now update `plan.md` with the Jira keys:
503
+
504
+ ```markdown
505
+ ## Phase 1: Setup [PROJ-124]
506
+ ...
507
+ - [x] **Task 1.1:** Extract logging utilities [PROJ-125]
508
+ - [x] **Task 1.2:** Extract security utilities [PROJ-126]
509
+ ```
510
+
511
+ Set export file status to Created (via `jira-export-latest.md`):
512
+
513
+ ```markdown
514
+ **Status:** Created
515
+ **Root Key:** PROJ-123
516
+ ```
517
+
518
+ ## Step 7: Report (new simplified format)
519
+
520
+ ```
521
+ Jira Issues Created
522
+
523
+ Track: [track_id] - [title]
524
+ Project: [PROJ]
525
+ Mode: {default → 1 Story | --epic → 1 Epic + 1-3 Stories}
526
+
527
+ Created:
528
+ - {Story | Epic}: PROJ-123 - [Track title]
529
+ (All phases and tasks are inside the Story description)
530
+
531
+ Bugs (from Bug Hunt) — always created as separate issues:
532
+ - Bug: PROJ-131 - [Critical] Correctness: Off-by-one error in pagination (linked to PROJ-123)
533
+ - Bug: PROJ-132 - [High] ...
534
+
535
+ Total: 1 root issue + B bugs
536
+ Label: "draft" applied to all issues
537
+
538
+ Updated:
539
+ - plan.md (added root Jira key)
540
+ - jira-export-latest.md (marked as created)
541
+ ```
542
+
543
+ ## Error Handling (create)
544
+
545
+ **MCP call fails:**
546
+ ```
547
+ Failed to create [issue type]: [error message]
548
+
549
+ Partial creation:
550
+ - {Story | Epic}: PROJ-123 (created)
551
+ - Mid-level 1: PROJ-124 (created)
552
+ - Leaf 1.1: PROJ-125 (created)
553
+ - Leaf 1.2: FAILED - [error]
554
+ - Mid-level 2: (skipped)
555
+
556
+ Fix the issue and run `/draft:jira create` again.
557
+ Already-created issues will be detected by keys in jira-export-latest.md.
558
+ ```
559
+
560
+ **Export has existing keys:** skip items that already have keys; only create items without keys. Report "Skipped Mid-level 1 (already exists: PROJ-124)". Still create leaves if mid-level exists but leaves don't have keys.
561
+
562
+ **Project not configured:** see Step 4b.
563
+
564
+ **plan.md phases don't match export:** warn "Export has N mid-level issues but plan has M phases. Proceeding with export structure." Create based on export.
565
+
566
+
567
+ ---
568
+
569
+ # Subcommand: review
570
+
571
+ See [review.md](review.md) for the full epic/story/bug/sub-task qualification pipeline. The router delegates to that file when the user invokes `/draft:jira review <JIRA_ID>`.
572
+
573
+ The review subcommand:
574
+ - Accepts any Jira issue ID (epic, story, bug, sub-task) and adapts its depth to the issue type.
575
+ - Runs a 7-phase pipeline: prerequisites → epic/story collection → document/test-plan synthesis → code change collection (Gerrit/GitHub/GitLab) → context synthesis → quality analysis (deep-review + bughunt + coverage) → test gap analysis → report.
576
+ - Produces `draft/jira-review/<JIRA_ID>/qualification-report.md` and (if gaps exist) `remediation-plan.md`.
577
+ - Verdict: QUALIFIED / PARTIALLY QUALIFIED / NOT QUALIFIED.