@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,224 @@
1
+ # Condensation Subroutine
2
+
3
+ > Generates `.ai-context.md` from `architecture.md`. Called by multiple skills after modifying architecture.
4
+
5
+ ---
6
+
7
+ This is a self-contained, callable procedure for generating `draft/.ai-context.md` from `draft/architecture.md`.
8
+
9
+ **Critical fidelity requirement**: The condensation must faithfully preserve the core operational models (workflows, lifecycles, state machines) from architecture.md §3 "Primary Control & Data Flows", along with invariants (§2) and extension points (§8). These behavioral models are the highest-value content for downstream coding accuracy.
10
+
11
+ **Mapping (architecture.md → .ai-context.md)** (modern 10-section graph-primary):
12
+ - Primary Control & Data Flows (§3) → `## GRAPH:OPERATIONAL` + GRAPH:DATAFLOW (states, transitions, error/recovery paths in compact form)
13
+ - Module & Dependency Map (§4) + hotspots → `GRAPH:MODULE-HOTSPOTS`, `GRAPH:FAN-IN`, `GRAPH:PROTO-MAP` etc.
14
+ - Critical Invariants (§2) → INVARIANTS
15
+ - Extension Points (§8) → EXTEND + INTERFACES
16
+
17
+ Any skill that mutates `architecture.md` should execute this subroutine afterward to keep the derived context files in sync.
18
+
19
+ **Called by:** `/draft:init`, `/draft:init refresh`, `/draft:implement`, `/draft:decompose`, `/draft:coverage`, `/draft:index`
20
+
21
+ ### Inputs
22
+
23
+ | Input | Path | Description |
24
+ |-------|------|-------------|
25
+ | architecture.md | `draft/architecture.md` | Comprehensive human-readable engineering reference (source of truth) |
26
+ | schema.yaml | `draft/graph/schema.yaml` | Graph metrics for tier computation (optional — skip if absent) |
27
+
28
+ ### Outputs
29
+
30
+ | Output | Path | Description |
31
+ |--------|------|-------------|
32
+ | .ai-context.md | `draft/.ai-context.md` | Token-optimized, machine-readable AI context (tier-scaled budget) |
33
+ | .ai-profile.md | `draft/.ai-profile.md` | Ultra-compact, always-injected project profile (20-50 lines) |
34
+
35
+ **Note:** `.ai-profile.md` generation is a separate step (the Profile Generation Subroutine defined in `skills/init/SKILL.md`). The Condensation Subroutine generates `.ai-context.md` only. Skills that call this subroutine should also trigger profile regeneration if `draft/.ai-profile.md` exists.
36
+
37
+ ### Target Size
38
+
39
+ Compute tier from `draft/graph/schema.yaml` after graph build:
40
+
41
+ M = stats.modules
42
+ F = stats.go_functions + stats.py_functions
43
+ P = stats.proto_rpcs
44
+
45
+ | Tier | Label | Condition | Budget |
46
+ |------|--------|----------------------------------------|---------------|
47
+ | 1 | micro | M≤5 AND F≤50 AND P≤10 | 100–180 lines |
48
+ | 2 | small | M≤15 AND F≤300 AND P≤30 | 180–280 lines |
49
+ | 3 | medium | M≤40 AND F≤1000 AND P≤100 | 280–400 lines |
50
+ | 4 | large | M≤100 AND F≤5000 AND P≤500 | 400–600 lines |
51
+ | 5 | XL | M>100 OR F>5000 OR P>500 | 600–900 lines |
52
+
53
+ If `schema.yaml` does not exist: default to tier 2 (180–280 lines).
54
+
55
+ - Below tier minimum: incomplete condensation — ensure all sections are represented
56
+ - Above tier maximum: insufficient compression — apply prioritization rules below
57
+
58
+ ### Procedure
59
+
60
+ #### Step 1: Read Source
61
+
62
+ Read the full contents of `draft/architecture.md`. Extract the YAML frontmatter metadata block — it will be reused (with updated `generated_by` and `generated_at`) for the output file.
63
+
64
+ #### Step 2: Write YAML Frontmatter
65
+
66
+ Start `draft/.ai-context.md` with a stable frontmatter block. Git state is centralized in `draft/metadata.json` — do NOT copy `git.*` or `synced_to_commit` from `architecture.md` into this file. Set:
67
+ - `project`: from `architecture.md` frontmatter
68
+ - `module`: from `architecture.md` frontmatter (usually `root`)
69
+ - `generated_by`: the calling command (e.g., `draft:init`, `draft:implement`)
70
+ - `generated_at`: current ISO 8601 timestamp
71
+
72
+ #### Step 3: Transform Sections
73
+
74
+ Transform each `architecture.md` section into machine-optimized format using this mapping:
75
+
76
+ | architecture.md Section (10-section graph-primary) | .ai-context.md Section | Transformation |
77
+ |--------------------------------------------------|------------------------|----------------|
78
+ | §1 Executive Summary + Graph Health Dashboard | META + GRAPH:HEALTH | Extract key-value pairs; dashboard metrics as compact rows |
79
+ | §2 Critical Invariants & Safety Rules | INVARIANTS | One line per invariant: `[CATEGORY] name: rule @file:line` |
80
+ | §3 Primary Control & Data Flows | GRAPH:OPERATIONAL + GRAPH:DATAFLOW | Convert Mermaid to `FLOW:{Name}` arrow notation |
81
+ | §4 Module & Dependency Map | GRAPH:COMPONENTS + GRAPH:MODULES | Tree notation `├─` / `└─`; module fan-in/out from graph |
82
+ | §5 Concurrency, Ownership & Isolation | THREADS + CONCURRENCY | Pipe-separated rows + isolation rules |
83
+ | §6 Error Handling & Failure Mode Catalog | ERRORS | Key-value pairs: `scenario: recovery` |
84
+ | §7 State & Data Truth Sources | GRAPH:DATAFLOW + STATE | Truth sources and reconciliation paths |
85
+ | §8 Extension Points & Safe Mutation | INTERFACES + EXTEND | Condensed signatures + cookbook steps |
86
+ | §9 Graph Coverage Gaps | GRAPH:GAPS | Bullet list of known limitations |
87
+ | §10 Relationship to Other Docs | META:DOCS | Pointer map to authoritative files |
88
+
89
+ #### Step 3.5: Generate Graph Summary Sections
90
+
91
+ If `draft/graph/schema.yaml` exists, generate these sections from the snapshot (`draft/graph/architecture.json`, `draft/graph/hotspots.jsonl`) and the live query tools:
92
+
93
+ **GRAPH:MODULES** (tier ≥ 2 only):
94
+ - Read `draft/graph/architecture.json` → `.packages[]` (each has `name`, `node_count`, `fan_in`, `fan_out`)
95
+ - Format: `{name}|{node_count} nodes|fan_in:{fan_in} fan_out:{fan_out}`
96
+ - Order by `node_count` descending
97
+ - Omit this section entirely for tier-1 codebases (≤5 modules) where Component Graph is sufficient
98
+
99
+ **GRAPH:HOTSPOTS** (all tiers):
100
+ - Read `draft/graph/hotspots.jsonl` (already fan-in-ranked), take top 10
101
+ - Format: `{name}|fanIn:{fanIn}` (use `id` for disambiguation when names collide)
102
+ - Always include regardless of tier
103
+
104
+ **GRAPH:CYCLES** (all tiers):
105
+ - Run `scripts/tools/cycle-detect.sh --repo .`; read `.cycles[]` (each is an array of qualified symbol names)
106
+ - Output `None ✓` if empty
107
+ - Otherwise output each cycle on its own line: `"A → B → C → A"`
108
+ - Always include — absence is positive signal that the call graph is acyclic
109
+
110
+ **GRAPH:MODULE-HOTSPOTS** (tier ≥ 3 only):
111
+ - Read `draft/graph/hotspots.jsonl`; group by the package segment of each `id` (the qualified name minus the leaf symbol)
112
+ - For each module: take its top 3 symbols by `fanIn`, format as indented lines under the module name
113
+ - Format: `{module}: {name}|fanIn:{N}` with subsequent symbols indented to align
114
+ - Order modules by their highest-fanIn symbol, descending
115
+ - Omit modules with no hotspot entries; omit entire section for tier 1–2 (covered by global GRAPH:HOTSPOTS)
116
+
117
+ **GRAPH:FAN-IN** (tier ≥ 3 only):
118
+ - Read `architecture.json` → `.packages[]`, use the `fan_in` field per module
119
+ - Format: `{name}|fanIn:{fan_in}|fanOut:{fan_out}`
120
+ - Order by `fan_in` descending; include only modules with `fan_in ≥ 2`; cap at 15 rows
121
+ - Omit entire section for tier 1–2 (trivially small graph)
122
+
123
+ **GRAPH:PROTO-MAP** (only when `architecture.json` `.routes` is non-empty):
124
+ - Read `architecture.json` → `.routes[]` (each has `method`, `path`, `handler`)
125
+ - Format: `{method} {path} → {handler}`
126
+ - One line per route
127
+ - Omit entire section if `.routes` is empty — do not write an empty section
128
+
129
+ #### Step 4: Apply Compression
130
+
131
+ - Remove all prose paragraphs — use structured key-value pairs instead
132
+ - Remove Mermaid syntax — use text-based graph notation (`├─`, `-->`, `-[proto]->`)
133
+ - Remove markdown formatting (no `**bold**`, no `_italic_`, no headers beyond `##`)
134
+ - Abbreviate common words: `fn`=function, `ret`=returns, `cfg`=config, `impl`=implementation, `req`=required, `opt`=optional, `dep`=dependency, `auth`=authentication, `authz`=authorization
135
+ - Use symbols: `@`=at/in file, `->`=calls/leads-to, `|`=column separator, `?`=optional, `!`=required/critical
136
+
137
+ #### Step 5: Prioritize Content
138
+
139
+ If the output exceeds the tier maximum, cut sections in this order (bottom = cut first):
140
+
141
+ | Priority | Section | Rule |
142
+ |----------|---------|------|
143
+ | 1 (never cut) | INVARIANTS | Safety critical — preserve every invariant |
144
+ | 2 (never cut) | EXTEND | Agent productivity critical — preserve all cookbook steps |
145
+ | 3 (keep) | GRAPH:HOTSPOTS | Always include — needed for impact awareness |
146
+ | 3 (keep) | GRAPH:CYCLES | Always include — always 1-2 lines; absence is signal |
147
+ | 3 (keep) | GRAPH:PROTO-MAP | Never cut when protos exist — RPC contracts are critical for AI agents |
148
+ | 3 | GRAPH:* | Keep all component, dependency, and dataflow graphs |
149
+ | 4 (scale) | GRAPH:MODULES | Include tier ≥ 2; omit for tier 1 |
150
+ | 4 (scale) | GRAPH:MODULE-HOTSPOTS | Include tier ≥ 3; cut to top-5 modules if budget tight |
151
+ | 4 (scale) | GRAPH:FAN-IN | Include tier ≥ 3; cut to top-10 rows if budget tight |
152
+ | 4 | INTERFACES | Keep all signatures |
153
+ | 5 | CATALOG | Can abbreviate to top 20 entries per category |
154
+ | 6 | CONFIG | Can abbreviate to `critical:Y` entries only |
155
+ | 7 (cut first) | VOCAB | Can abbreviate to 10 most important terms |
156
+
157
+ #### Step 6: Quality Check
158
+
159
+ Before writing `draft/.ai-context.md`, verify:
160
+
161
+ - [ ] No prose paragraphs remain (all content is structured data)
162
+ - [ ] No Mermaid syntax (all diagrams converted to text graphs)
163
+ - [ ] No references to `architecture.md` (file must be self-contained)
164
+ - [ ] All invariants from architecture.md are preserved
165
+ - [ ] Extension cookbooks are complete (an agent can follow them without other files)
166
+ - [ ] Output is within tier budget bounds (compute from schema.yaml or default tier 2)
167
+ - [ ] GRAPH:HOTSPOTS present (or note "No hotspot data available" if graph absent)
168
+ - [ ] GRAPH:CYCLES present ("None ✓" or cycle list; or note if graph absent)
169
+ - [ ] GRAPH:MODULE-HOTSPOTS present for tier ≥ 3 (or note if no hotspot data)
170
+ - [ ] GRAPH:FAN-IN present for tier ≥ 3
171
+ - [ ] GRAPH:PROTO-MAP present when `stats.proto_rpcs > 0` (omit entirely if no protos)
172
+ - [ ] YAML frontmatter metadata is present at the top
173
+
174
+ #### Step 7: Write Output
175
+
176
+ Write the completed content to `draft/.ai-context.md`.
177
+
178
+ #### Step 8: Normalise Whitespace
179
+
180
+ After writing both output files, strip trailing whitespace and blank lines at EOF to prevent GitHub upload failures. Resolve the script via the canonical tool resolver (see [tool-resolver.md](tool-resolver.md)):
181
+
182
+ ```bash
183
+ DRAFT_TOOLS="${DRAFT_PLUGIN_ROOT:-$HOME/.claude/plugins/draft}/scripts/tools"
184
+ [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$HOME/.cursor/plugins/local/draft/scripts/tools"
185
+ [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$PWD/scripts/tools"
186
+ [ -x "$DRAFT_TOOLS/fix-whitespace.sh" ] && bash "$DRAFT_TOOLS/fix-whitespace.sh" draft/architecture.md draft/.ai-context.md draft/.ai-profile.md 2>/dev/null || true
187
+ ```
188
+
189
+ This is idempotent — run it unconditionally.
190
+
191
+ ### Example Transformation
192
+
193
+ **architecture.md input:**
194
+ ````markdown
195
+ ### 4.1 High-Level Topology
196
+
197
+ The AuthService is a microservice that handles user authentication...
198
+
199
+ ```mermaid
200
+ flowchart TD
201
+ subgraph AuthService
202
+ API[API Layer] --> Logic[Auth Logic]
203
+ Logic --> Store[Token Store]
204
+ end
205
+ Logic --> UserDB[(User Database)]
206
+ ```
207
+ ````
208
+
209
+ **.ai-context.md output:**
210
+ ```
211
+ ## GRAPH:COMPONENTS
212
+ AuthService
213
+ ├─API: handles HTTP requests
214
+ ├─Logic: validates credentials, generates tokens
215
+ └─Store: caches active tokens
216
+
217
+ ## GRAPH:DEPENDENCIES
218
+ AuthService.Logic -[PostgreSQL]-> UserDB
219
+ ```
220
+
221
+ ### Reference for Other Skills
222
+
223
+ Other skills that mutate `draft/architecture.md` should invoke this subroutine with:
224
+ > "After updating `draft/architecture.md`, regenerate `draft/.ai-context.md` using the Condensation Subroutine defined in `core/shared/condensation.md`. If `draft/.ai-profile.md` exists, also regenerate it using the Profile Generation Subroutine defined in `skills/init/SKILL.md`."
@@ -0,0 +1,44 @@
1
+ ---
2
+ shared: context-verify
3
+ applies_to: all skills that load Draft project context
4
+ ---
5
+
6
+ # Verify Draft Context (Shared Subroutine)
7
+
8
+ Single-source `Verify Draft Context` subroutine. Replaces the duplicated 3–4 line blocks that appeared in skills that load project context.
9
+
10
+ Referenced by: every skill that starts with a `Verify Draft Context` step.
11
+
12
+ ## Procedure
13
+
14
+ 1. **Probe the draft directory:**
15
+
16
+ ```bash
17
+ ls draft/ 2>/dev/null
18
+ ```
19
+
20
+ 2. **Branch on result:**
21
+
22
+ | Result | Action |
23
+ |---|---|
24
+ | Directory exists | Proceed to step 3. |
25
+ | Directory missing AND skill requires context (`/draft:learn`, `/draft:deep-review`, `/draft:tech-debt`, `/draft:implement`) | **STOP** — print `No Draft context found. Run /draft:init first.` and exit. |
26
+ | Directory missing AND skill is context-optional (`/draft:debug`, `/draft:quick-review`, `/draft:bughunt`, `/draft:deploy-checklist`, `/draft:documentation`, `/draft:testing-strategy`) | Proceed with reduced-context mode; record `draft_context: absent` in the report header. |
27
+
28
+ 3. **Load context** by following [draft-context-loading.md](draft-context-loading.md). Honor the **selective guardrail matrix** in that file's Layer 0.5 — do not load all guardrails just because they are available.
29
+
30
+ ## Usage in SKILL.md
31
+
32
+ Replace the existing 3–4 line `Verify Draft Context` block with a single reference:
33
+
34
+ ```md
35
+ ### Verify Draft Context
36
+
37
+ See [core/shared/context-verify.md](../../core/shared/context-verify.md). This skill is <required | optional> with respect to `draft/`.
38
+ ```
39
+
40
+ This keeps each skill explicit about whether draft context is required, while centralizing the probe-and-branch logic.
41
+
42
+ ## Why This Exists
43
+
44
+ Duplicating the same `ls draft/ 2>/dev/null` snippet across skills costs tokens per duplicate after frontmatter and surrounding prose. Factoring removes the duplication without changing semantics.
@@ -0,0 +1,127 @@
1
+ # Cross-Skill Dispatch Convention
2
+
3
+ Standard convention for how Draft skills invoke, offer, or suggest other skills. All Tier 1 orchestrators and cross-referencing skills follow this pattern.
4
+
5
+ Convention spec implemented by: All Tier 1 orchestrators (`init`, `new-track`, `implement`, `review`, `upload`), and Tier 2 skills that cross-reference others. Skills implement this dispatch convention independently; see `skills/GRAPH.md` for the full dependency graph.
6
+
7
+ ## Dispatch Tiers
8
+
9
+ ### Tier 1: Auto-Invoke (Silent)
10
+
11
+ Execute without user confirmation. Used for passive context enrichment and established patterns.
12
+
13
+ - Load `testing-strategy.md` if it exists (context enrichment)
14
+ - Feed quality results to `/draft:learn` (established pattern)
15
+ - Sync artifacts to Jira via `core/shared/jira-sync.md` when ticket is linked
16
+ - Load `rca.md` into bug track implementation context
17
+
18
+ **Convention:** No announcement needed. Log in track metadata if applicable.
19
+
20
+ ### Tier 2: Offer (Ask with Default)
21
+
22
+ Present a choice with a recommended default. Used when the skill adds significant value but the user may want to skip.
23
+
24
+ Format:
25
+ ```
26
+ "Run /draft:<skill> to <benefit>? [Y/n]"
27
+ ```
28
+
29
+ Examples:
30
+ - "Run `/draft:debug` to investigate before writing the spec? [Y/n]" — bug tracks in new-track
31
+ - "Run full three-stage review or `/draft:quick-review` for lightweight check? [full]" — phase boundaries in implement
32
+ - "Run `/draft:tech-debt` to scope this refactor? [Y/n]" — refactor tracks in new-track
33
+
34
+ **Convention:** Default answer in brackets. Enter accepts default.
35
+
36
+ ### Tier 3: Suggest (Announce, Don't Block)
37
+
38
+ Announce availability at completion without blocking. Used for optional follow-up actions.
39
+
40
+ Format:
41
+ ```
42
+ "Consider running `/draft:<skill>` to <benefit>."
43
+ ```
44
+
45
+ Examples:
46
+ - "Consider running `/draft:tech-debt` to catalog debt found during review."
47
+ - "Consider running `/draft:documentation api` to document new endpoints."
48
+ - "Consider running `/draft:adr` to record this design decision."
49
+
50
+ **Convention:** Grouped in a "What's Next" or "Suggestions" section at skill completion.
51
+
52
+ ### Tier 4: Detect + Auto-Feed (Smart Context Injection)
53
+
54
+ Automatically detect when output from one skill is useful to another and inject it as context. No user interaction.
55
+
56
+ | Source Skill | Output | Target Skill | How Injected |
57
+ |---|---|---|---|
58
+ | `/draft:debug` | Debug Report | `/draft:new-track` | Fed into spec.md "Reproduction" and "Root Cause Hypothesis" sections |
59
+ | `/draft:incident-response` | Postmortem | `/draft:new-track` | Fed into bug track spec context |
60
+ | `/draft:tech-debt` | Debt Report | `/draft:new-track` | Fed into refactor track spec scope |
61
+ | `/draft:testing-strategy` | Strategy Doc | `/draft:implement` | Loaded into TDD context (coverage targets, test boundaries) |
62
+ | `/draft:debug` + RCA agent | `rca.md` | `/draft:implement` | Loaded as investigation context for bug fix implementation |
63
+
64
+ **Convention:** Check for artifact existence before injection. If not found, skip silently.
65
+
66
+ ## Dispatch Registry
67
+
68
+ Complete registry of all cross-skill dispatch points:
69
+
70
+ | Orchestrator | When | Dispatches | Tier |
71
+ |---|---|---|---|
72
+ | `init` | Brownfield + debt signals detected | `tech-debt` | Suggest |
73
+ | `init` | After generating tech-stack.md | `testing-strategy` | Suggest |
74
+ | `init` | At completion | `documentation readme` | Suggest |
75
+ | `new-track` | Bug track detected | `debug` | Offer |
76
+ | `new-track` | Incident/outage keywords | `incident-response postmortem` | Detect + Suggest |
77
+ | `new-track` | Refactor track | `tech-debt` | Offer |
78
+ | `new-track` | New technology / arch shift | `adr` | Detect + Suggest |
79
+ | `new-track` | Plan generation (feature) | `testing-strategy` task, `deploy-checklist` task, `documentation` task | Auto-embed |
80
+ | `implement` | Blocked task | `debug` | Offer (replaces inline debugger) |
81
+ | `implement` | Before TDD (first task) | `testing-strategy` load | Auto-Invoke |
82
+ | `implement` | Bug track before tests | Ask developer | Offer (test guardrail) |
83
+ | `implement` | Phase boundary | `quick-review` | Offer |
84
+ | `implement` | Track completion | `deploy-checklist`, `documentation`, `tech-debt`, `adr` | Suggest |
85
+ | `review` | After Stage 3 | `coverage` | Auto-Invoke |
86
+ | `review` | At completion (quality findings) | `tech-debt`, `documentation` | Suggest |
87
+ | `upload` | Pre-upload | `deploy-checklist` | Auto-Invoke |
88
+ | `upload` | New APIs detected | `documentation api` | Detect + Suggest |
89
+ | `upload` | Post-upload success | Jira comment | Auto-Invoke |
90
+ | `decompose` | After module decomposition | `testing-strategy`, `documentation api` | Suggest |
91
+ | `decompose` | Dependency cycles detected | `tech-debt` | Detect + Suggest |
92
+ | `decompose` | Module boundary decisions | `adr` | Auto-Invoke |
93
+ | `bughunt` | Critical bugs found | `debug` | Suggest |
94
+ | `deep-review` | Architecture debt found | `tech-debt`, `adr` | Suggest |
95
+
96
+ ## Implementation Pattern
97
+
98
+ Skills implementing dispatch should follow this pattern:
99
+
100
+ ```markdown
101
+ ## Cross-Skill Dispatch
102
+
103
+ At this point, check for dispatch opportunities:
104
+
105
+ ### Auto-Invoke
106
+ - [list auto-invoke actions relevant to this skill]
107
+
108
+ ### Offer
109
+ - [list offer actions relevant to this skill]
110
+
111
+ ### Suggest (at completion)
112
+ - [list suggest actions relevant to this skill]
113
+ ```
114
+
115
+ ## Test Writing Guardrail
116
+
117
+ **In bug/debug/RCA workflows:** Never auto-write unit tests. Always ask the developer first.
118
+
119
+ Applies to: `/draft:debug`, `/draft:implement` (bug tracks), auto-triage pipeline, `/draft:bughunt`
120
+ Does NOT apply to: Feature tracks with TDD enabled, `/draft:coverage`
121
+
122
+ ```
123
+ If track type is "bugfix" OR current context is debug/RCA:
124
+ BEFORE writing any test file:
125
+ ASK: "Want me to write [regression/unit] tests for [description]? [Y/n]"
126
+ If declined: skip test writing, note in plan.md: "Tests: developer-handled"
127
+ ```
@@ -0,0 +1,75 @@
1
+ # Discovery Artifact Schema
2
+
3
+ > Schema for the `discovery.md` artifact produced by discovery flows (as part of
4
+ > new-track). The artifact captures the AI's pre-spec code-spike
5
+ > findings as a first-class output.
6
+
7
+ ## Why this is first-class
8
+
9
+ Pre-2.0, code-spike findings were buried in "Conversation Log" sections of
10
+ `spec.md` or scattered across context-references rows. Reviewers could not
11
+ tell whether the AI had actually read the code or had inferred structure
12
+ from titles. `discovery.md` makes the spike output auditable, machine-
13
+ verifiable (via citation verifiers), and load-bearing for downstream specs.
14
+
15
+ ## Required sections (each carries `<!-- REQUIRED -->`)
16
+
17
+ 1. **Hotspots** — code locations the spec must address.
18
+ 2. **Mode selection** — flags / feature gates / env switches governing the
19
+ current code path.
20
+ 3. **Open Questions** — load-bearing unknowns that must close before spec
21
+ freeze.
22
+ 4. **References** — flat list of files and functions touched in the spike.
23
+
24
+ ## Hotspots table — required columns
25
+
26
+ | Column | Notes |
27
+ |---|---|
28
+ | Step | Short label for the operation observed |
29
+ | Location | `path/to/file.ext:LINE` (verifier-resolvable) |
30
+ | Behavior | What the spec must explain or improve (1 line) |
31
+
32
+ Minimum row count: 3 (configurable via `metadata.json:hygiene_budget.discovery_min_hotspots`).
33
+ If the spike genuinely found nothing, the row count may be 0 but the
34
+ **Open Questions** section must contain a `_NONE_FOUND_ — <one-line
35
+ justification>` line. The validator rejects an empty discovery without
36
+ that justification.
37
+
38
+ ## Mode selection table — required columns
39
+
40
+ | Column | Notes |
41
+ |---|---|
42
+ | Switch | flag, gate, env var, or build option |
43
+ | Location | `path/to/file.ext:LINE` |
44
+ | Notes | what behavior the switch toggles |
45
+
46
+ ## Open Questions
47
+
48
+ Each question begins with `Q<N>:` and is a single line. Each MUST close
49
+ into one of:
50
+
51
+ - a decision merged into `spec.md` (preferred),
52
+ - an explicit deferral with a follow-up track ID, or
53
+ - a `_NONE_FOUND_` annotation explaining why the question is moot.
54
+
55
+ A `discovery.md` whose Open Questions list is left dangling fails the
56
+ hygiene validator.
57
+
58
+ ## References
59
+
60
+ A flat bullet list of files and functions:
61
+
62
+ - `path/to/file.ext` — `Function` / `Class::Method` — one-line role
63
+ - `path/to/other.ext` — `Function2` — …
64
+
65
+ Functions named here are exempt from citation drift unless they also
66
+ appear with line numbers elsewhere.
67
+
68
+ ## Renaming / archiving
69
+
70
+ Discovery is created once per track at spec time. Subsequent
71
+ decompose runs DO NOT regenerate `discovery.md` — its job is to
72
+ capture the moment in time when the spec was written, anchored to
73
+ `metadata.json:synced_to_commit`. Re-running discovery is a deliberate
74
+ re-spike; the previous file should be renamed `discovery-<isodate>.md`
75
+ and the new one inherits the slot.