@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.
- package/.claude-plugin/marketplace.json +38 -0
- package/.claude-plugin/plugin.json +26 -0
- package/LICENSE +21 -0
- package/README.md +272 -0
- package/bin/README.md +49 -0
- package/cli/bin/draft.js +13 -0
- package/cli/src/cli.js +113 -0
- package/cli/src/hosts/claude-code.js +46 -0
- package/cli/src/hosts/codex.js +33 -0
- package/cli/src/hosts/cursor.js +50 -0
- package/cli/src/hosts/index.js +24 -0
- package/cli/src/hosts/opencode.js +39 -0
- package/cli/src/installer.js +61 -0
- package/cli/src/lib/fsx.js +34 -0
- package/cli/src/lib/graph.js +23 -0
- package/cli/src/lib/log.js +32 -0
- package/cli/src/lib/paths.js +14 -0
- package/core/agents/architect.md +338 -0
- package/core/agents/debugger.md +193 -0
- package/core/agents/ops.md +104 -0
- package/core/agents/planner.md +158 -0
- package/core/agents/rca.md +314 -0
- package/core/agents/reviewer.md +256 -0
- package/core/agents/writer.md +110 -0
- package/core/guardrails/README.md +4 -0
- package/core/guardrails/code-quality.md +4 -0
- package/core/guardrails/dependency-triage.md +4 -0
- package/core/guardrails/design-norms.md +4 -0
- package/core/guardrails/language-standards.md +4 -0
- package/core/guardrails/review-checks.md +4 -0
- package/core/guardrails/secure-patterns.md +4 -0
- package/core/guardrails/security.md +4 -0
- package/core/guardrails.md +22 -0
- package/core/knowledge-base.md +127 -0
- package/core/methodology.md +1221 -0
- package/core/shared/condensation.md +224 -0
- package/core/shared/context-verify.md +44 -0
- package/core/shared/cross-skill-dispatch.md +127 -0
- package/core/shared/discovery-schema.md +75 -0
- package/core/shared/draft-context-loading.md +282 -0
- package/core/shared/git-report-metadata.md +106 -0
- package/core/shared/graph-query.md +239 -0
- package/core/shared/graph-usage-report.md +22 -0
- package/core/shared/jira-sync.md +170 -0
- package/core/shared/parallel-analysis.md +386 -0
- package/core/shared/parallel-fanout.md +10 -0
- package/core/shared/pattern-learning.md +146 -0
- package/core/shared/red-flags.md +58 -0
- package/core/shared/template-contract.md +22 -0
- package/core/shared/template-hygiene.md +10 -0
- package/core/shared/tool-resolver.md +10 -0
- package/core/shared/vcs-commands.md +97 -0
- package/core/shared/verification-gates.md +47 -0
- package/core/templates/CHANGELOG.md +70 -0
- package/core/templates/ai-context-export.md +8 -0
- package/core/templates/ai-context.md +270 -0
- package/core/templates/ai-profile.md +41 -0
- package/core/templates/architecture.md +203 -0
- package/core/templates/dependency-graph.md +103 -0
- package/core/templates/discovery.md +79 -0
- package/core/templates/guardrails.md +143 -0
- package/core/templates/hld.md +327 -0
- package/core/templates/intake-questions.md +403 -0
- package/core/templates/jira.md +119 -0
- package/core/templates/lld.md +283 -0
- package/core/templates/metadata.json +66 -0
- package/core/templates/plan.md +130 -0
- package/core/templates/product.md +110 -0
- package/core/templates/rca.md +86 -0
- package/core/templates/root-architecture.md +127 -0
- package/core/templates/root-product.md +53 -0
- package/core/templates/root-tech-stack.md +117 -0
- package/core/templates/service-index.md +55 -0
- package/core/templates/session-summary.md +8 -0
- package/core/templates/spec.md +165 -0
- package/core/templates/tech-matrix.md +101 -0
- package/core/templates/tech-stack.md +169 -0
- package/core/templates/track-architecture.md +311 -0
- package/core/templates/workflow.md +187 -0
- package/integrations/agents/AGENTS.md +24384 -0
- package/integrations/copilot/.github/copilot-instructions.md +24384 -0
- package/integrations/gemini/.gemini.md +26 -0
- package/package.json +53 -0
- package/scripts/fetch-memory-engine.sh +116 -0
- package/scripts/lib.sh +256 -0
- package/scripts/tools/_lib.sh +220 -0
- package/scripts/tools/adr-index.sh +117 -0
- package/scripts/tools/check-graph-usage-report.sh +95 -0
- package/scripts/tools/check-scope-conflicts.sh +139 -0
- package/scripts/tools/check-skill-line-caps.sh +115 -0
- package/scripts/tools/check-template-noop.sh +87 -0
- package/scripts/tools/check-track-hygiene.sh +230 -0
- package/scripts/tools/classify-files.sh +231 -0
- package/scripts/tools/cycle-detect.sh +75 -0
- package/scripts/tools/detect-test-framework.sh +135 -0
- package/scripts/tools/diff-templates-vs-tracks.sh +176 -0
- package/scripts/tools/emit-skill-metrics.sh +71 -0
- package/scripts/tools/fix-whitespace.sh +192 -0
- package/scripts/tools/freshness-check.sh +143 -0
- package/scripts/tools/git-metadata.sh +203 -0
- package/scripts/tools/graph-callers.sh +74 -0
- package/scripts/tools/graph-impact.sh +93 -0
- package/scripts/tools/graph-snapshot.sh +102 -0
- package/scripts/tools/hotspot-rank.sh +75 -0
- package/scripts/tools/manage-symlinks.sh +85 -0
- package/scripts/tools/mermaid-from-graph.sh +92 -0
- package/scripts/tools/migrate-track-frontmatter.sh +241 -0
- package/scripts/tools/parse-git-log.sh +135 -0
- package/scripts/tools/parse-reports.sh +114 -0
- package/scripts/tools/render-track.sh +145 -0
- package/scripts/tools/run-coverage.sh +153 -0
- package/scripts/tools/scan-markers.sh +144 -0
- package/scripts/tools/skill-caps.conf +24 -0
- package/scripts/tools/validate-frontmatter.sh +125 -0
- package/scripts/tools/verify-citations.sh +250 -0
- package/scripts/tools/verify-doc-anchors.sh +204 -0
- package/scripts/tools/verify-graph-binary.sh +154 -0
- package/skills/GRAPH.md +332 -0
- package/skills/adr/SKILL.md +374 -0
- package/skills/assist-review/SKILL.md +49 -0
- package/skills/bughunt/SKILL.md +668 -0
- package/skills/bughunt/references/regression-tests.md +399 -0
- package/skills/change/SKILL.md +267 -0
- package/skills/coverage/SKILL.md +336 -0
- package/skills/debug/SKILL.md +201 -0
- package/skills/decompose/SKILL.md +656 -0
- package/skills/deep-review/SKILL.md +326 -0
- package/skills/deploy-checklist/SKILL.md +254 -0
- package/skills/discover/SKILL.md +66 -0
- package/skills/docs/SKILL.md +42 -0
- package/skills/documentation/SKILL.md +197 -0
- package/skills/draft/SKILL.md +177 -0
- package/skills/draft/context-files.md +57 -0
- package/skills/draft/intent-mapping.md +37 -0
- package/skills/draft/quality-guide.md +51 -0
- package/skills/graph/SKILL.md +107 -0
- package/skills/impact/SKILL.md +86 -0
- package/skills/implement/SKILL.md +794 -0
- package/skills/incident-response/SKILL.md +245 -0
- package/skills/index/SKILL.md +848 -0
- package/skills/init/SKILL.md +1784 -0
- package/skills/init/references/architecture-spec.md +1259 -0
- package/skills/integrations/SKILL.md +53 -0
- package/skills/jira/SKILL.md +577 -0
- package/skills/jira/references/review.md +1322 -0
- package/skills/learn/SKILL.md +478 -0
- package/skills/new-track/SKILL.md +841 -0
- package/skills/ops/SKILL.md +57 -0
- package/skills/plan/SKILL.md +60 -0
- package/skills/quick-review/SKILL.md +216 -0
- package/skills/revert/SKILL.md +178 -0
- package/skills/review/SKILL.md +1114 -0
- package/skills/standup/SKILL.md +183 -0
- package/skills/status/SKILL.md +183 -0
- package/skills/tech-debt/SKILL.md +318 -0
- package/skills/testing-strategy/SKILL.md +195 -0
- package/skills/tour/SKILL.md +38 -0
- package/skills/upload/SKILL.md +117 -0
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: learn
|
|
3
|
+
description: Scan codebase to discover coding patterns and update draft/guardrails.md. Learns conventions (skip in future) and anti-patterns (always flag). Supports migration from workflow.md and pattern promotion.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Learn — Pattern Discovery & Guardrails Update
|
|
7
|
+
|
|
8
|
+
Scan the codebase to discover recurring coding patterns and update `draft/guardrails.md` with learned conventions and anti-patterns. This improves future quality command accuracy by reducing false positives and catching known-bad patterns.
|
|
9
|
+
|
|
10
|
+
## MANDATORY GRAPH LOOKUP (read before pattern scanning)
|
|
11
|
+
|
|
12
|
+
When `draft/graph/schema.yaml` exists, this skill **must** follow the graph-first lookup contract in [core/shared/graph-query.md](../../core/shared/graph-query.md) §Mandatory Lookup Contract. Use the graph to:
|
|
13
|
+
|
|
14
|
+
1. Enumerate a module's symbols/files via `scripts/tools/graph-callers.sh`/`graph-impact.sh` and `architecture.json` (preferred over `find`).
|
|
15
|
+
2. Prioritize hotspots from `draft/graph/hotspots.jsonl` — patterns in high-fanIn files are more impactful when learned.
|
|
16
|
+
3. For TS/Python/Go/C/C++, use `*-index.jsonl` to identify class/function definitions rather than re-discovering them via regex.
|
|
17
|
+
|
|
18
|
+
Filesystem `find` for source discovery (Step 2.1) is permitted **as a complement** to the graph for languages not covered by indexes (e.g. Ruby, Java without ctags). Record the rationale in the Graph Usage Report.
|
|
19
|
+
|
|
20
|
+
## Red Flags - STOP if you're:
|
|
21
|
+
|
|
22
|
+
See [shared red flags](../../core/shared/red-flags.md) — applies to all code-touching skills.
|
|
23
|
+
|
|
24
|
+
Skill-specific:
|
|
25
|
+
- Writing to guardrails.md without reading the codebase first
|
|
26
|
+
- Learning a pattern from fewer than 3 occurrences
|
|
27
|
+
- Auto-promoting patterns to Hard Guardrails (requires human approval)
|
|
28
|
+
- Overwriting human-curated Hard Guardrails with learned patterns
|
|
29
|
+
- Learning patterns that contradict `tech-stack.md ## Accepted Patterns`
|
|
30
|
+
- Removing existing learned entries (only update or add)
|
|
31
|
+
|
|
32
|
+
**Evidence over assumptions. Quantity over anecdote.**
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Arguments
|
|
37
|
+
|
|
38
|
+
- No arguments — full codebase pattern scan
|
|
39
|
+
- `promote` — review high-confidence learned patterns and offer promotion to Hard Guardrails or Accepted Patterns
|
|
40
|
+
- `migrate` — migrate `## Guardrails` from `workflow.md` to `guardrails.md` (for existing projects)
|
|
41
|
+
- `<path>` — scan specific directory or file pattern
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Step 0: Verify Draft Context
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
ls draft/ 2>/dev/null
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
If `draft/` does not exist: **STOP** — "No Draft context found. Run `/draft:init` first."
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Step 1: Load Existing Guardrails
|
|
56
|
+
|
|
57
|
+
### 1.1: Check for guardrails.md
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
ls draft/guardrails.md 2>/dev/null
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
If it exists, read it and internalize:
|
|
64
|
+
- Current Hard Guardrails (checked items)
|
|
65
|
+
- Current Learned Conventions (existing entries)
|
|
66
|
+
- Current Learned Anti-Patterns (existing entries)
|
|
67
|
+
|
|
68
|
+
**Then verify core guardrails integrity (backfill if missing):**
|
|
69
|
+
|
|
70
|
+
Check if `draft/guardrails.md` contains the C++/Systems Hard Guardrails from `core/guardrails.md`. Detection: look for the marker heading `### C++/Systems — Object Lifecycle & Memory Safety`.
|
|
71
|
+
|
|
72
|
+
- **If missing AND project contains C++ code:** The file predates `core/guardrails.md`. Backfill by inserting the full C++/Systems Hard Guardrails sections from `core/templates/guardrails.md` (G1.x–G7.x, all pre-checked `[x]`) into the `## Hard Guardrails` section, after any existing general guardrails. Preserve all existing entries. Announce: "Backfilled C++/Systems Hard Guardrails (G1.x–G7.x) from core/guardrails.md into draft/guardrails.md."
|
|
73
|
+
- **If missing AND project has no C++ code:** Skip — these guardrails only apply to C++ projects.
|
|
74
|
+
- **If present:** No action — core guardrails already integrated.
|
|
75
|
+
|
|
76
|
+
### 1.2: Check for Legacy Guardrails (migration path)
|
|
77
|
+
|
|
78
|
+
If `draft/guardrails.md` does NOT exist:
|
|
79
|
+
|
|
80
|
+
1. Check `draft/workflow.md` for `## Guardrails` section
|
|
81
|
+
2. If found, announce: "Found guardrails in workflow.md. Creating guardrails.md and migrating."
|
|
82
|
+
3. Create `draft/guardrails.md` using template from `core/templates/guardrails.md`
|
|
83
|
+
4. Copy checked guardrail items from `workflow.md ## Guardrails` into the Hard Guardrails section
|
|
84
|
+
5. Add a comment in `workflow.md` where `## Guardrails` was:
|
|
85
|
+
```markdown
|
|
86
|
+
## Guardrails
|
|
87
|
+
|
|
88
|
+
> **Migrated** — Guardrails have moved to `draft/guardrails.md`. See that file for hard guardrails, learned conventions, and learned anti-patterns.
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
If `migrate` argument was given, stop here after migration. Otherwise, continue to pattern scanning.
|
|
92
|
+
|
|
93
|
+
### 1.3: Load Supporting Context
|
|
94
|
+
|
|
95
|
+
Read and follow `core/shared/draft-context-loading.md` for full Draft context. Key files:
|
|
96
|
+
- `draft/.ai-context.md` — Module boundaries, invariants, concurrency model
|
|
97
|
+
- `draft/tech-stack.md` — Frameworks, accepted patterns (do not learn patterns that duplicate these)
|
|
98
|
+
- `draft/product.md` — Product requirements
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Step 2: Codebase Pattern Scan
|
|
103
|
+
|
|
104
|
+
### 2.1: Discover Source Files
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# Find all source files (exclude vendored, generated, build artifacts)
|
|
108
|
+
find . -type f \( -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.jsx" \
|
|
109
|
+
-o -name "*.py" -o -name "*.go" -o -name "*.rs" -o -name "*.java" \
|
|
110
|
+
-o -name "*.cpp" -o -name "*.cc" -o -name "*.h" -o -name "*.hpp" \
|
|
111
|
+
-o -name "*.rb" -o -name "*.php" -o -name "*.swift" -o -name "*.kt" \) \
|
|
112
|
+
-not -path "*/node_modules/*" -not -path "*/vendor/*" -not -path "*/.git/*" \
|
|
113
|
+
-not -path "*/dist/*" -not -path "*/build/*" -not -path "*/__pycache__/*" \
|
|
114
|
+
-not -path "*/draft/*" \
|
|
115
|
+
| head -500
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
If scope argument provided, filter to that path.
|
|
119
|
+
|
|
120
|
+
### 2.2: Analyze Pattern Dimensions
|
|
121
|
+
|
|
122
|
+
Scan the codebase across these dimensions, looking for **recurring patterns** (3+ occurrences):
|
|
123
|
+
|
|
124
|
+
#### Error Handling Conventions
|
|
125
|
+
- How errors are caught, logged, and propagated
|
|
126
|
+
- Custom error classes or error codes
|
|
127
|
+
- Try/catch patterns, error boundaries
|
|
128
|
+
- Retry and fallback strategies
|
|
129
|
+
|
|
130
|
+
#### Naming Conventions
|
|
131
|
+
- Variable, function, class naming styles beyond language defaults
|
|
132
|
+
- File naming patterns (kebab-case, PascalCase, etc.)
|
|
133
|
+
- Module/directory organization conventions
|
|
134
|
+
|
|
135
|
+
#### Architecture Patterns
|
|
136
|
+
- Import/dependency patterns (barrel exports, lazy loading)
|
|
137
|
+
- State management approaches
|
|
138
|
+
- API call patterns (centralized client, interceptors)
|
|
139
|
+
- Component composition patterns
|
|
140
|
+
|
|
141
|
+
#### Concurrency Patterns
|
|
142
|
+
- Async/await usage conventions
|
|
143
|
+
- Locking and synchronization approaches
|
|
144
|
+
- Queue and worker patterns
|
|
145
|
+
- Cancellation and timeout handling
|
|
146
|
+
|
|
147
|
+
#### Data Flow Patterns
|
|
148
|
+
- Validation placement (boundary vs deep)
|
|
149
|
+
- Serialization/deserialization conventions
|
|
150
|
+
- Caching strategies
|
|
151
|
+
- Data transformation pipelines
|
|
152
|
+
|
|
153
|
+
#### Testing Conventions
|
|
154
|
+
- Test file placement and naming
|
|
155
|
+
- Test structure (arrange/act/assert, given/when/then)
|
|
156
|
+
- Mock/stub conventions
|
|
157
|
+
- Fixture and factory patterns
|
|
158
|
+
|
|
159
|
+
#### Configuration Patterns
|
|
160
|
+
- Environment variable access patterns
|
|
161
|
+
- Feature flag patterns
|
|
162
|
+
- Config file conventions
|
|
163
|
+
|
|
164
|
+
### 2.3: Temporal Pattern Analysis
|
|
165
|
+
|
|
166
|
+
Detect patterns that are being phased out by the team:
|
|
167
|
+
|
|
168
|
+
1. **Identify declining patterns** — For each candidate pattern, use `git blame` to check the age of files containing it:
|
|
169
|
+
- **Old files** (last modified >1 year ago): high occurrence of the pattern
|
|
170
|
+
- **New files** (last modified <6 months ago): low or zero occurrence of the pattern
|
|
171
|
+
- If occurrence ratio old:new is >3:1, flag as a declining pattern
|
|
172
|
+
2. **Mark declining patterns** — When writing to guardrails.md, add `declining: true` to the entry metadata:
|
|
173
|
+
```markdown
|
|
174
|
+
- **Declining:** yes — found in 8 old files (avg age 18mo), 1 new file (avg age 2mo). Being replaced by [newer pattern].
|
|
175
|
+
```
|
|
176
|
+
3. **Do NOT propagate declining patterns** — Quality commands should not flag absence of a declining pattern as inconsistency
|
|
177
|
+
4. **Example:** Old error handling style `try/catch with manual logging` found in files last modified >1 year ago, newer files use structured error middleware — the old style is declining, not a convention to enforce
|
|
178
|
+
|
|
179
|
+
**Reference:** Google large-scale changes (Rosie) — systematic detection of patterns being migrated away from.
|
|
180
|
+
|
|
181
|
+
### 2.4: Cross-Service Pattern Comparison (Monorepo)
|
|
182
|
+
|
|
183
|
+
When in a monorepo (detected by `draft/service-index.md` existing OR multiple `draft/` directories OR presence of `packages/`, `services/`, `apps/` directories):
|
|
184
|
+
|
|
185
|
+
1. **Scan across services** — Run pattern analysis in each service/package independently
|
|
186
|
+
2. **Compare patterns for the same concern** — For each pattern dimension (error handling, naming, etc.):
|
|
187
|
+
- Does Service A use a different approach than Service B for the same concern?
|
|
188
|
+
- Example: Service A uses `Result<T, E>` for error handling, Service B uses exceptions
|
|
189
|
+
3. **Flag inconsistencies** — Report cross-service divergences:
|
|
190
|
+
```
|
|
191
|
+
Cross-service inconsistency: Error Handling
|
|
192
|
+
services/auth/ → uses custom Result type (5 files)
|
|
193
|
+
services/billing/ → uses thrown exceptions (8 files)
|
|
194
|
+
Suggestion: standardize on one approach
|
|
195
|
+
```
|
|
196
|
+
4. **Respect intentional differences** — Do NOT flag inconsistencies when:
|
|
197
|
+
- Services use different languages or frameworks
|
|
198
|
+
- The pattern difference is documented in `tech-stack.md` or `.ai-context.md`
|
|
199
|
+
- The services have fundamentally different runtime requirements
|
|
200
|
+
|
|
201
|
+
**Reference:** Google monorepo practices — consistent patterns across services reduce cognitive overhead and enable large-scale tooling.
|
|
202
|
+
|
|
203
|
+
### 2.5: Cross-Reference Existing Knowledge
|
|
204
|
+
|
|
205
|
+
For each candidate pattern:
|
|
206
|
+
|
|
207
|
+
1. **Check `tech-stack.md ## Accepted Patterns`** — if already documented there, skip (no duplication)
|
|
208
|
+
2. **Check existing `guardrails.md` entries** — if already learned, update evidence count and date
|
|
209
|
+
3. **Check `.ai-context.md`** — if described as architecture, skip (it's documented)
|
|
210
|
+
4. **Verify consistency** — sample 3+ instances and confirm they follow the same approach
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
### 2.6: Git History Signal Mining
|
|
215
|
+
|
|
216
|
+
Mine git commit history for pattern signals that code scanning misses. Run only if the project is a git repository.
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
git log --oneline --no-merges -500
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Scan the output for recurring message patterns (3+ occurrences of the same type):
|
|
223
|
+
|
|
224
|
+
| Commit pattern | Signal |
|
|
225
|
+
|---------------|--------|
|
|
226
|
+
| `fix: don't X` / `fix: never X` | Team keeps violating X → anti-pattern candidate |
|
|
227
|
+
| `refactor: replace X with Y` | X is declining, Y is the replacement → mark X as `declining: true` |
|
|
228
|
+
| `chore: enforce X` / `chore: add X check` | X is being formalized → convention candidate |
|
|
229
|
+
| `revert: ` followed by same topic 3+ times | That topic is consistently problematic → anti-pattern candidate |
|
|
230
|
+
|
|
231
|
+
**Rules:**
|
|
232
|
+
- Do NOT add git-only signals as standalone entries. Use them only to adjust confidence of patterns already found in Step 2.2.
|
|
233
|
+
- If a pattern appears in both commit history AND code (3+ occurrences): increase confidence by one level.
|
|
234
|
+
- If a pattern appears only in commit history but not in current code: note as `historically_recurring: true` — do not add as active anti-pattern.
|
|
235
|
+
|
|
236
|
+
**Recency weighting** — for each candidate pattern from Step 2.2, check when the files containing it were last modified:
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
git log --follow --oneline -1 -- {file_containing_pattern}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
- Modified within 90 days AND pattern persists → add `recently_active: true` to the entry
|
|
243
|
+
- Not modified in 12+ months → add `stale: true` — lower enforcement priority
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
### 2.7: Graph-Aware Severity Enrichment
|
|
248
|
+
|
|
249
|
+
If `draft/graph/hotspots.jsonl` exists, derive objective severity for all anti-pattern candidates based on the fanIn of files where the pattern was found.
|
|
250
|
+
|
|
251
|
+
For each anti-pattern candidate from Step 2.2:
|
|
252
|
+
1. Check if any evidence files appear in `draft/graph/hotspots.jsonl`
|
|
253
|
+
2. Take the highest fanIn value across all evidence files:
|
|
254
|
+
- fanIn ≥ 10 → `graph_severity: critical` (breakage propagates to many callers)
|
|
255
|
+
- fanIn 5–9 → `graph_severity: high`
|
|
256
|
+
- fanIn 1–4 → `graph_severity: medium`
|
|
257
|
+
- fanIn 0 or file not in hotspots.jsonl → `graph_severity: low`
|
|
258
|
+
3. If no graph data exists → `graph_severity: unresolved`
|
|
259
|
+
|
|
260
|
+
Collect all evidence files with fanIn ≥ 5 for the `high_fanin_files` field.
|
|
261
|
+
|
|
262
|
+
When `graph_severity` differs from the subjectively assigned `severity`, use `graph_severity` as the enforcement priority in quality commands — it is objective and reproducible.
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## Step 3: Apply Confidence Threshold
|
|
267
|
+
|
|
268
|
+
Follow the threshold from `core/shared/pattern-learning.md`:
|
|
269
|
+
|
|
270
|
+
| Evidence | Confidence | Action |
|
|
271
|
+
|----------|------------|--------|
|
|
272
|
+
| Found 1-2x | — | Skip (insufficient data) |
|
|
273
|
+
| Found 3-5x, all consistent | `medium` | Learn as convention or anti-pattern |
|
|
274
|
+
| Found >5x, all consistent, cross-verified | `high` | Learn + flag as promotion candidate |
|
|
275
|
+
| Found >5x but inconsistent | — | Do NOT learn (investigate inconsistency) |
|
|
276
|
+
|
|
277
|
+
**Consistency-claim ground-truth gate (Ground-Truth Discipline G1, G4):** "Consistent" and "cross-verified" require you to have **Read** at least 3 of the instances in this session (5 if claiming `high`). A grep match count is not consistency proof — variant call sites can use the same identifier with different semantics. List the file:line of each Read instance in the learned-pattern record under §Evidence. A `medium` or `high` entry whose Evidence list shows only grep counts is a Red Flag and must be downgraded or discarded.
|
|
278
|
+
|
|
279
|
+
### Distinguishing Conventions from Anti-Patterns
|
|
280
|
+
|
|
281
|
+
- **Convention:** Pattern is consistently applied AND does not cause bugs, security issues, or violations of documented invariants
|
|
282
|
+
- **Anti-Pattern:** Pattern is consistently applied BUT causes or risks bugs, security issues, performance problems, or invariant violations
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## Step 3.5: Pattern Conflict Detection
|
|
287
|
+
|
|
288
|
+
Before saving any new pattern, check for conflicts with existing entries:
|
|
289
|
+
|
|
290
|
+
1. **Check against existing conventions** — Does the new pattern contradict a learned convention?
|
|
291
|
+
2. **Check against existing anti-patterns** — Does the new pattern contradict a learned anti-pattern?
|
|
292
|
+
3. **Check against Hard Guardrails** — Does the new pattern violate a hard guardrail?
|
|
293
|
+
|
|
294
|
+
**If conflict found:**
|
|
295
|
+
- Do NOT silently save the new pattern
|
|
296
|
+
- Alert the user with both patterns side by side:
|
|
297
|
+
```
|
|
298
|
+
CONFLICT DETECTED:
|
|
299
|
+
|
|
300
|
+
Existing convention: "Use async/await for all async operations"
|
|
301
|
+
Evidence: 12 files, high confidence, learned 2025-01-15
|
|
302
|
+
|
|
303
|
+
New candidate: "Avoid async in database module — use callback style"
|
|
304
|
+
Evidence: 4 files in src/db/, medium confidence
|
|
305
|
+
|
|
306
|
+
These may both be valid (module-scoped exception) or one may be outdated.
|
|
307
|
+
Options:
|
|
308
|
+
[1] Keep both (new pattern is a scoped exception)
|
|
309
|
+
[2] Replace existing with new (pattern has evolved)
|
|
310
|
+
[3] Discard new (existing is correct)
|
|
311
|
+
```
|
|
312
|
+
- Wait for user input before proceeding
|
|
313
|
+
|
|
314
|
+
**Reference:** Google Code Health — conflicting patterns create confusion and should be resolved explicitly.
|
|
315
|
+
|
|
316
|
+
---
|
|
317
|
+
|
|
318
|
+
## Step 3.7: External Benchmark Comparison
|
|
319
|
+
|
|
320
|
+
After discovering patterns, optionally compare project conventions against community standards for the detected language:
|
|
321
|
+
|
|
322
|
+
| Language | Benchmarks |
|
|
323
|
+
|----------|-----------|
|
|
324
|
+
| **Go** | Effective Go, Go Code Review Comments |
|
|
325
|
+
| **Python** | PEP 8, PEP 20, Google Python Style Guide |
|
|
326
|
+
| **Java** | Effective Java, Google Java Style Guide |
|
|
327
|
+
| **TypeScript** | typescript-eslint recommended rules |
|
|
328
|
+
| **Rust** | Rust API Guidelines, Clippy lints |
|
|
329
|
+
| **C/C++** | Google C++ Style Guide, C++ Core Guidelines |
|
|
330
|
+
|
|
331
|
+
For each project convention that **deviates** from its language's community standard:
|
|
332
|
+
1. Note the deviation in the summary report (not as an anti-pattern — deviations may be intentional)
|
|
333
|
+
2. If the deviation is undocumented, suggest adding it to `tech-stack.md ## Accepted Patterns` with a rationale
|
|
334
|
+
3. Example: project uses `snake_case` for TypeScript functions (deviates from `camelCase` convention) — flag for documentation, not correction
|
|
335
|
+
|
|
336
|
+
**Reference:** Google Abseil Tips of the Week, language-specific style guides — deviations from community standards increase onboarding friction and should be documented even when intentional.
|
|
337
|
+
|
|
338
|
+
---
|
|
339
|
+
|
|
340
|
+
## Step 4: Update guardrails.md
|
|
341
|
+
|
|
342
|
+
Follow the write procedure in `core/shared/pattern-learning.md`:
|
|
343
|
+
|
|
344
|
+
1. Read current `draft/guardrails.md`
|
|
345
|
+
2. For each new pattern: check for duplicates, then append
|
|
346
|
+
3. For existing patterns: update evidence count, confidence, `last_verified`
|
|
347
|
+
4. Update `draft/metadata.json` with current git state (use `git-metadata.sh --project-metadata --generated-by "draft:learn"` or update `git.commit`, `git.commit_message`, and `synced_to_commit` manually) — `guardrails.md` frontmatter carries only stable fields per WS-8
|
|
348
|
+
|
|
349
|
+
**Cap enforcement:** Maintain a maximum of 50 learned entries per section. If at capacity, replace the oldest `medium` confidence entry that has not been re-verified in 90+ days (per `core/shared/pattern-learning.md`).
|
|
350
|
+
|
|
351
|
+
### Entry Format — Convention
|
|
352
|
+
|
|
353
|
+
```markdown
|
|
354
|
+
### [Pattern Name]
|
|
355
|
+
- **Category:** error-handling | naming | architecture | concurrency | state-management | data-flow | testing | configuration
|
|
356
|
+
- **Confidence:** high | medium
|
|
357
|
+
- **Evidence:** Found in N files — `path/file1.ext:line`, `path/file2.ext:line`, `path/file3.ext:line`
|
|
358
|
+
- **Discovered at:** YYYY-MM-DD (when Draft first observed this pattern)
|
|
359
|
+
- **Established at:** YYYY-MM-DD (when the pattern entered the codebase, via git blame)
|
|
360
|
+
- **Last verified:** YYYY-MM-DD
|
|
361
|
+
- **Last active:** YYYY-MM-DD (when source files containing this pattern were last modified)
|
|
362
|
+
- **Discovered by:** draft:learn on YYYY-MM-DD
|
|
363
|
+
- **Description:** [What the pattern is and why it's intentional]
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
### Entry Format — Anti-Pattern
|
|
367
|
+
|
|
368
|
+
```markdown
|
|
369
|
+
### [Anti-Pattern Name]
|
|
370
|
+
- **Category:** security | reliability | performance | correctness | concurrency
|
|
371
|
+
- **Severity:** critical | high | medium
|
|
372
|
+
- **graph_severity:** critical | high | medium | low | unresolved (fanIn-derived from Step 2.7; "unresolved" if no graph data)
|
|
373
|
+
- **high_fanin_files:** `path/file.go` (fanIn:12), `path/other.go` (fanIn:7) (omit line if none meet fanIn ≥ 5)
|
|
374
|
+
- **Evidence:** Found in N files — `path/file1.ext:line`, `path/file2.ext:line`
|
|
375
|
+
- **Discovered at:** YYYY-MM-DD (when Draft first observed this pattern)
|
|
376
|
+
- **Established at:** YYYY-MM-DD (when the pattern entered the codebase, via git blame)
|
|
377
|
+
- **Last verified:** YYYY-MM-DD
|
|
378
|
+
- **Last active:** YYYY-MM-DD (when source files containing this pattern were last modified)
|
|
379
|
+
- **recently_active:** true | false (true if any evidence file modified within 90 days)
|
|
380
|
+
- **stale:** true | false (true if all evidence files unmodified for 12+ months)
|
|
381
|
+
- **Discovered by:** draft:learn on YYYY-MM-DD
|
|
382
|
+
- **Description:** [What the pattern is and why it's problematic]
|
|
383
|
+
- **Suggested fix:** [Brief description of the correct approach]
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
---
|
|
387
|
+
|
|
388
|
+
## Step 5: Promotion Workflow (when `promote` argument given)
|
|
389
|
+
|
|
390
|
+
Review all learned patterns with `confidence: high` and present promotion candidates:
|
|
391
|
+
|
|
392
|
+
```
|
|
393
|
+
Pattern promotion candidates:
|
|
394
|
+
|
|
395
|
+
1. [Convention] "Centralized API client pattern" (high confidence, 12 files)
|
|
396
|
+
→ Promote to: tech-stack.md ## Accepted Patterns? [y/n]
|
|
397
|
+
|
|
398
|
+
2. [Convention] "Error boundary at route level" (high confidence, 8 files)
|
|
399
|
+
→ Promote to: Hard Guardrail (enforce always)? [y/n]
|
|
400
|
+
|
|
401
|
+
3. [Anti-Pattern] "Unguarded .env access" (high confidence, 6 files)
|
|
402
|
+
→ Promote to: Hard Guardrail (enforce always)? [y/n]
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
For each promoted pattern:
|
|
406
|
+
- **Convention → Accepted Pattern**: Append to `draft/tech-stack.md ## Accepted Patterns` and remove from guardrails.md Learned Conventions
|
|
407
|
+
- **Convention → Hard Guardrail**: Move from Learned Conventions to Hard Guardrails section (as checked `[x]` item)
|
|
408
|
+
- **Anti-Pattern → Hard Guardrail**: Move from Learned Anti-Patterns to Hard Guardrails section (as checked `[x]` item)
|
|
409
|
+
|
|
410
|
+
---
|
|
411
|
+
|
|
412
|
+
## Step 6: Generate Summary Report
|
|
413
|
+
|
|
414
|
+
Display results to the user:
|
|
415
|
+
|
|
416
|
+
```
|
|
417
|
+
/draft:learn complete
|
|
418
|
+
|
|
419
|
+
Scanned: N source files across M directories
|
|
420
|
+
Duration: ~Xs
|
|
421
|
+
|
|
422
|
+
Results:
|
|
423
|
+
New conventions learned: N [list names]
|
|
424
|
+
New anti-patterns learned: N [list names]
|
|
425
|
+
Existing patterns updated: N [list names]
|
|
426
|
+
Skipped (insufficient data): N
|
|
427
|
+
Skipped (already documented): N
|
|
428
|
+
|
|
429
|
+
Promotion candidates (high confidence):
|
|
430
|
+
N patterns ready for promotion — run /draft:learn promote to review
|
|
431
|
+
|
|
432
|
+
Updated: draft/guardrails.md
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
---
|
|
436
|
+
|
|
437
|
+
## How Quality Commands Use guardrails.md
|
|
438
|
+
|
|
439
|
+
After `/draft:learn` populates guardrails.md, all quality commands automatically:
|
|
440
|
+
|
|
441
|
+
| Section | Quality Command Behavior |
|
|
442
|
+
|---------|------------------------|
|
|
443
|
+
| **Hard Guardrails** (checked) | Flag violations as issues |
|
|
444
|
+
| **Learned Conventions** | Skip these patterns during analysis (not bugs) |
|
|
445
|
+
| **Learned Anti-Patterns** | Always flag these patterns as bugs |
|
|
446
|
+
| **Unchecked Hard Guardrails** | Ignore (not enforced) |
|
|
447
|
+
|
|
448
|
+
This creates a **continuous improvement loop**:
|
|
449
|
+
1. Quality command runs → discovers patterns → updates guardrails.md
|
|
450
|
+
2. Next quality command run → reads updated guardrails.md → fewer false positives, catches known-bad patterns
|
|
451
|
+
3. `/draft:learn promote` → graduates stable patterns to permanent status
|
|
452
|
+
|
|
453
|
+
---
|
|
454
|
+
|
|
455
|
+
## Anti-Patterns
|
|
456
|
+
|
|
457
|
+
| Don't | Instead |
|
|
458
|
+
|-------|---------|
|
|
459
|
+
| Learn from <3 occurrences | Require minimum 3 consistent instances |
|
|
460
|
+
| Auto-promote to Hard Guardrails | Always require human approval for promotion |
|
|
461
|
+
| Overwrite human-curated entries | Learned patterns complement, never replace |
|
|
462
|
+
| Learn framework defaults as conventions | Only learn project-specific patterns |
|
|
463
|
+
| Remove entries on re-scan | Update evidence/dates, never delete |
|
|
464
|
+
| Learn from test/mock code | Focus on production source code |
|
|
465
|
+
|
|
466
|
+
## Mandatory Self-Check (before completion summary)
|
|
467
|
+
|
|
468
|
+
Before printing the completion summary, internally verify and report:
|
|
469
|
+
|
|
470
|
+
1. **Graph files queried** — JSONL files loaded plus any live graph query-tool invocations.
|
|
471
|
+
2. **Layer 1 files deliberately skipped** — list any context sections skipped.
|
|
472
|
+
3. **Filesystem find/grep fallback justification** — for every `find`/`grep` run for source discovery, state which languages or extensions were not covered by the graph indexes (e.g. Ruby without ctags).
|
|
473
|
+
|
|
474
|
+
If `draft/graph/schema.yaml` does not exist, set `Graph files queried: NONE` and use justification `graph data unavailable`.
|
|
475
|
+
|
|
476
|
+
## Graph Usage Report (append to completion summary)
|
|
477
|
+
|
|
478
|
+
Emit the canonical footer from [core/shared/graph-usage-report.md](../../core/shared/graph-usage-report.md) §Canonical footer. The lint hook `scripts/tools/check-graph-usage-report.sh` validates the section on save.
|