@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,282 @@
|
|
|
1
|
+
# Draft Context Loading
|
|
2
|
+
|
|
3
|
+
Standard procedure for loading Draft project context. All Draft commands that read project context follow this procedure before analysis or execution.
|
|
4
|
+
|
|
5
|
+
Referenced by: All skills that load Draft project context — including `/draft:bughunt`, `/draft:review`, `/draft:deep-review`, `/draft:quick-review`, `/draft:learn`, `/draft:tech-debt`, `/draft:deploy-checklist`, `/draft:incident-response`, `/draft:documentation`, `/draft:adr`, `/draft:testing-strategy`, `/draft:standup`, `/draft:debug`
|
|
6
|
+
|
|
7
|
+
## Context Loading Layers
|
|
8
|
+
|
|
9
|
+
Draft uses a layered context system inspired by memory tiering — compact, always-available context at the top, with progressively deeper context loaded on demand.
|
|
10
|
+
|
|
11
|
+
### Layer 0: Project Profile (Always Loaded)
|
|
12
|
+
|
|
13
|
+
If `draft/.ai-profile.md` exists, **always** read it first. This ultra-compact file (20-50 lines) provides the minimum context every command needs: language, framework, database, auth, API style, critical invariants, safety rules, active tracks, and recent changes.
|
|
14
|
+
|
|
15
|
+
- **Always loaded** regardless of task complexity
|
|
16
|
+
- **Purpose**: Enables simple tasks (quick edits, config changes, small fixes) without loading full context
|
|
17
|
+
- **Fallback**: If `.ai-profile.md` does not exist, proceed to Layer 1
|
|
18
|
+
|
|
19
|
+
### Layer 0.5: Plugin Guardrails (Selective Loading)
|
|
20
|
+
|
|
21
|
+
Layer 0.5 files live in the Draft plugin (`core/guardrails/`) and provide numbered, versioned baseline rules. **Project-level `draft/guardrails.md` always takes precedence** — if a project rule conflicts with a plugin rule, the project rule wins. See `core/guardrails/README.md` for vocabulary and full precedence order. (Portable improvement merged per manifest §2.1.)
|
|
22
|
+
|
|
23
|
+
| File | Rules | Scope |
|
|
24
|
+
|------|-------|-------|
|
|
25
|
+
| `core/guardrails/README.md` | (index) | Vocabulary, ID prefixes, precedence rules |
|
|
26
|
+
| `core/guardrails/code-quality.md` | CQ-001…CQ-012 | Code authoring, naming, error messages, structure |
|
|
27
|
+
| `core/guardrails/design-norms.md` | DN-001…DN-010 | HLD/LLD depth split, diagrams, traceability, secrets |
|
|
28
|
+
| `core/guardrails/review-checks.md` | RC-001…RC-015 | Cross-cutting review baseline (security, tests, observability) |
|
|
29
|
+
| `core/guardrails/security.md` | SEC-01…SEC-10 | Hard security red lines + reasoning chain |
|
|
30
|
+
| `core/guardrails/secure-patterns.md` | (cross-cites SEC) | Per-language enforcement of SEC rules |
|
|
31
|
+
| `core/guardrails/dependency-triage.md` | RC-014 | Third-party dependency vulnerability handling |
|
|
32
|
+
| `core/guardrails/language-standards.md` | Per-stack sections | Language-specific style, safety, test standards |
|
|
33
|
+
| `core/guardrails.md` *(existing)* | G1…G8 | C++ systems guardrails — always enforced for C++ code (conditioned on language signals for public language-agnostic use) |
|
|
34
|
+
|
|
35
|
+
#### Selective Loading Matrix (binding)
|
|
36
|
+
|
|
37
|
+
This matrix is the **single source of truth** for which Layer 0.5 files load per command. Skills MUST honor it — over-loading is a Red Flag (see red-flags.md) and costs tokens per invocation.
|
|
38
|
+
|
|
39
|
+
| Command type | Commands | Guardrails loaded |
|
|
40
|
+
|---|---|---|
|
|
41
|
+
| **Read-only** | `/draft:status`, `/draft:standup`, `/draft:tour`, `/draft:index`, `/draft:coverage` | **none** |
|
|
42
|
+
| **Spec / Plan** | `/draft:new-track`, `/draft:decompose`, `/draft:adr`, `/draft:testing-strategy`, `/draft:documentation` | `design-norms.md` only (architecture-shaped rules) |
|
|
43
|
+
| **Code-touching (generation)** | `/draft:implement`, `/draft:debug`, `/draft:change`, `/draft:revert` | `code-quality.md` + `security.md` + `secure-patterns.md` + `language-standards.md` (detected stack) |
|
|
44
|
+
| **Review** | `/draft:review`, `/draft:quick-review`, `/draft:deep-review`, `/draft:assist-review`, `/draft:bughunt`, `/draft:tech-debt` | `review-checks.md` + `security.md` + `language-standards.md` (detected stack); deep-review also loads `code-quality.md` + `design-norms.md` |
|
|
45
|
+
| **Deploy** | `/draft:deploy-checklist`, `/draft:incident-response` | `security.md` + `dependency-triage.md` |
|
|
46
|
+
| **Pattern / Meta** | `/draft:learn`, `/draft:init` | `code-quality.md` + `security.md` (baseline only — pattern discovery uses project-level guardrails as primary signal) |
|
|
47
|
+
|
|
48
|
+
**Sensitive-task escalation:** Even when the matrix says "none" or a narrow set, code-touching tasks whose title/spec mentions authentication, authorization, login, token, session, password, SQL, database query, subprocess, exec, crypto, encryption, hash, file upload, or external API input MUST additionally load `security.md` + `secure-patterns.md` and treat `[SEC-*]` violations as Critical.
|
|
49
|
+
|
|
50
|
+
**Citation requirement:** When a rule is enforced or violated, cite the ID inline — `[SEC-03]`, `[CQ-007]`, `[RC-012]`, `[DN-004]`.
|
|
51
|
+
|
|
52
|
+
**Fallback**: If `core/guardrails/` files are not present (older plugin installation), skip gracefully — no degradation.
|
|
53
|
+
|
|
54
|
+
### Layer 1: Base Context Files
|
|
55
|
+
|
|
56
|
+
If `draft/` directory exists, read and internalize these files in order:
|
|
57
|
+
|
|
58
|
+
| Priority | File | Purpose | Fallback |
|
|
59
|
+
|----------|------|---------|----------|
|
|
60
|
+
| 1 | `draft/.ai-context.md` | Module boundaries, dependencies, critical invariants, concurrency model, error handling, data flows | `draft/architecture.md` (legacy projects) |
|
|
61
|
+
| 2 | `draft/tech-stack.md` | Frameworks, libraries, constraints, **Accepted Patterns** | — |
|
|
62
|
+
| 3 | `draft/product.md` | Product vision, user flows, requirements, **Guidelines** | — |
|
|
63
|
+
| 4 | `draft/workflow.md` | Team conventions, testing preferences | — |
|
|
64
|
+
| 5 | `draft/guardrails.md` | Hard guardrails, **Learned Conventions**, **Learned Anti-Patterns** | `draft/workflow.md` `## Guardrails` (legacy) |
|
|
65
|
+
|
|
66
|
+
### Layer 1.5: Graph Context (When Available)
|
|
67
|
+
|
|
68
|
+
If `draft/graph/schema.yaml` exists, the project has automated graph analysis data. This provides precise, deterministic structural context that complements the AI-generated `.ai-context.md`.
|
|
69
|
+
|
|
70
|
+
**Always-load files** (compact, read alongside Layer 1):
|
|
71
|
+
|
|
72
|
+
| File | Purpose | Content |
|
|
73
|
+
|------|---------|---------|
|
|
74
|
+
| `draft/graph/schema.yaml` | Snapshot metadata (engine, project, node/edge counts) | YAML, ~15 lines |
|
|
75
|
+
| `draft/graph/architecture.json` | Node labels, edge types, languages, packages (fan-in/out), entry points, routes, hotspots | JSON |
|
|
76
|
+
| `draft/graph/hotspots.jsonl` | Fan-in-ranked symbols, one object per line: `{id, name, fanIn}` | JSONL |
|
|
77
|
+
|
|
78
|
+
Note: `.ai-context.md` embeds a condensed graph summary (`GRAPH:MODULES`, `GRAPH:HOTSPOTS`, `GRAPH:CYCLES`) for first-pass structural ground truth. `architecture.json` is authoritative for deep structure.
|
|
79
|
+
|
|
80
|
+
Note: The canonical embedded mermaid diagrams are in architecture.md injection slots (`<!-- GRAPH:module-deps:START/END -->`, `<!-- GRAPH:proto-map:START/END -->`), refreshed by `draft:index`. For current data, regenerate via `scripts/tools/mermaid-from-graph.sh`.
|
|
81
|
+
|
|
82
|
+
**Live structural queries** (run on demand — no per-language index files; the engine's model is unified):
|
|
83
|
+
|
|
84
|
+
| Tool | Use When... |
|
|
85
|
+
|------|-------------|
|
|
86
|
+
| `scripts/tools/graph-callers.sh --symbol <name>` | Enumerating callers of a function |
|
|
87
|
+
| `scripts/tools/graph-impact.sh --file <path>` / `--symbol <name>` | Sizing blast radius before a change |
|
|
88
|
+
| `scripts/tools/cycle-detect.sh` | Checking for call cycles |
|
|
89
|
+
| `scripts/tools/hotspot-rank.sh` | Fan-in ranking (live) |
|
|
90
|
+
|
|
91
|
+
See `core/shared/graph-query.md` for the full query contract.
|
|
92
|
+
|
|
93
|
+
**Fallback**: If `draft/graph/` does not exist, skip — no degradation.
|
|
94
|
+
|
|
95
|
+
### Layer 2: Fact Registry (When Available)
|
|
96
|
+
|
|
97
|
+
If `draft/.state/facts.json` exists, it provides granular fact-level context:
|
|
98
|
+
|
|
99
|
+
- **For refresh operations**: Load facts sourced from changed files to enable contradiction detection
|
|
100
|
+
- **For quality commands**: Load facts by category relevant to the current analysis dimension
|
|
101
|
+
- **For implementation**: Load facts related to files being modified (match via `source_files`)
|
|
102
|
+
|
|
103
|
+
Facts are NOT loaded in full for every command — use relevance filtering (see below).
|
|
104
|
+
|
|
105
|
+
Additional state files used by refresh operations (not loaded during normal context loading):
|
|
106
|
+
- `draft/.state/freshness.json` — SHA-256 hashes for file-level staleness detection
|
|
107
|
+
- `draft/.state/signals.json` — signal classification for structural drift detection
|
|
108
|
+
|
|
109
|
+
## Relevance-Scored Context Loading
|
|
110
|
+
|
|
111
|
+
Not all context is equally relevant to every task. When a specific track or task is active, apply relevance scoring to prioritize which context sections are most useful.
|
|
112
|
+
|
|
113
|
+
### When to Apply
|
|
114
|
+
|
|
115
|
+
Apply relevance scoring when ALL of these conditions are true:
|
|
116
|
+
1. A specific track or task is active (has `spec.md` and/or `plan.md`)
|
|
117
|
+
2. `draft/.ai-context.md` exists and is above tier-1 minimum (100 lines)
|
|
118
|
+
3. The command benefits from focused context (`/draft:implement`, `/draft:bughunt`, `/draft:review`)
|
|
119
|
+
|
|
120
|
+
Do NOT apply relevance scoring for commands that need full context (`/draft:init`, `/draft:deep-review`, `/draft:decompose`).
|
|
121
|
+
|
|
122
|
+
### Scoring Procedure
|
|
123
|
+
|
|
124
|
+
1. **Extract key concepts** from the active task:
|
|
125
|
+
- Read `spec.md` acceptance criteria and extract domain terms
|
|
126
|
+
- Read `plan.md` current task description and extract file paths, module names, technology terms
|
|
127
|
+
- Identify the primary concern: data flow, UI, API, security, performance, configuration, etc.
|
|
128
|
+
|
|
129
|
+
2. **Score `.ai-context.md` sections** against the task concepts:
|
|
130
|
+
|
|
131
|
+
| Section | Load When Task Involves... |
|
|
132
|
+
|---------|--------------------------|
|
|
133
|
+
| `## META` | Always (baseline) |
|
|
134
|
+
| `## GRAPH:COMPONENTS` | Module boundary changes, new components |
|
|
135
|
+
| `## GRAPH:MODULES` | Module boundary changes, new components, cross-module work |
|
|
136
|
+
| `## GRAPH:HOTSPOTS` | Performance work, refactoring, changes to high-complexity files |
|
|
137
|
+
| `## GRAPH:CYCLES` | Dependency restructuring, module boundary decisions |
|
|
138
|
+
| `## GRAPH:DEPENDENCIES` | Integration work, new external dependencies |
|
|
139
|
+
| `## GRAPH:DATAFLOW` | Data pipeline changes, new flows |
|
|
140
|
+
| `## INVARIANTS` | Always (safety critical) |
|
|
141
|
+
| `## INTERFACES` | API changes, new implementations |
|
|
142
|
+
| `## CATALOG:*` | Implementation work matching the category |
|
|
143
|
+
| `## THREADS` | Concurrency-related tasks |
|
|
144
|
+
| `## CONFIG` | Configuration changes |
|
|
145
|
+
| `## ERRORS` | Error handling tasks |
|
|
146
|
+
| `## CONCURRENCY` | Any async/parallel work |
|
|
147
|
+
| `## EXTEND:*` | Adding new implementations of existing patterns |
|
|
148
|
+
| `## TEST` | Always (need test commands) |
|
|
149
|
+
| `## FILES` | Always (need file locations) |
|
|
150
|
+
| `## VOCAB` | Domain-specific tasks |
|
|
151
|
+
|
|
152
|
+
3. **Score graph files** (if `draft/graph/` exists) against the task concepts:
|
|
153
|
+
|
|
154
|
+
| Graph source | Use When Task Involves... |
|
|
155
|
+
|------------|--------------------------|
|
|
156
|
+
| `architecture.json` | Module boundary changes, cross-module work, architecture analysis, API/route surface |
|
|
157
|
+
| `hotspots.jsonl` | Performance work, refactoring, changes to high-fanIn symbols |
|
|
158
|
+
| `scripts/tools/graph-callers.sh --symbol <name>` | Enumerating callers before a change |
|
|
159
|
+
| `scripts/tools/graph-impact.sh --file <path>` / `--symbol <name>` | Tracing call paths, root cause analysis, function-level impact |
|
|
160
|
+
| `scripts/tools/cycle-detect.sh` | Checking for call cycles |
|
|
161
|
+
|
|
162
|
+
4. **Always include**: `META`, `INVARIANTS`, `TEST`, `FILES` (minimum context floor)
|
|
163
|
+
5. **Include if relevant**: All other sections scored against task concepts
|
|
164
|
+
6. **Result**: A focused subset of `.ai-context.md` that maximizes signal-to-noise for the current task
|
|
165
|
+
|
|
166
|
+
### Fact Registry Relevance
|
|
167
|
+
|
|
168
|
+
When `draft/.state/facts.json` exists, also load relevant facts:
|
|
169
|
+
|
|
170
|
+
1. **By file overlap**: Facts whose `source_files` overlap with files the current task will modify
|
|
171
|
+
2. **By category**: Facts in categories matching the task's primary concern
|
|
172
|
+
3. **By recency**: Prefer facts with recent `last_active_at` timestamps (active code areas)
|
|
173
|
+
4. **Limit**: Load at most 20 relevant facts per task to stay within token budget
|
|
174
|
+
|
|
175
|
+
## Special Sections to Honor
|
|
176
|
+
|
|
177
|
+
### Accepted Patterns (`tech-stack.md` → `## Accepted Patterns`)
|
|
178
|
+
|
|
179
|
+
Patterns listed here are **intentional design decisions**. Do NOT flag these as bugs, issues, or violations. They represent deliberate trade-offs documented by the team.
|
|
180
|
+
|
|
181
|
+
### Guardrails (`draft/guardrails.md`)
|
|
182
|
+
|
|
183
|
+
Project-level `draft/guardrails.md` has three sections with different enforcement behavior:
|
|
184
|
+
|
|
185
|
+
| Section | Behavior |
|
|
186
|
+
|---------|----------|
|
|
187
|
+
| **Hard Guardrails** (checked `[x]`) | Always flag violations as issues |
|
|
188
|
+
| **Learned Conventions** | Skip these patterns during analysis — they are verified intentional patterns |
|
|
189
|
+
| **Learned Anti-Patterns** | Always flag these patterns — they are verified problematic patterns |
|
|
190
|
+
| **Hard Guardrails** (unchecked `[ ]`) | Ignore (not enforced) |
|
|
191
|
+
|
|
192
|
+
**Legacy fallback:** If `draft/guardrails.md` does not exist, check `draft/workflow.md` for a `## Guardrails` section and enforce checked items there. Suggest running `/draft:learn migrate` to move to the new format.
|
|
193
|
+
|
|
194
|
+
### Critical Invariants (`.ai-context.md` → `## Critical Invariants`)
|
|
195
|
+
|
|
196
|
+
Invariants covering data safety, security, concurrency, ordering, and idempotency. Check for violations across all relevant code paths.
|
|
197
|
+
|
|
198
|
+
## Track Context (when scoped to a track)
|
|
199
|
+
|
|
200
|
+
If analyzing a specific track, also load:
|
|
201
|
+
|
|
202
|
+
| File | Purpose |
|
|
203
|
+
|------|---------|
|
|
204
|
+
| `draft/tracks/<id>/spec.md` | Requirements, acceptance criteria, edge cases |
|
|
205
|
+
| `draft/tracks/<id>/plan.md` | Implementation tasks, phases, dependencies |
|
|
206
|
+
|
|
207
|
+
Use track context to:
|
|
208
|
+
- Verify implemented features match spec requirements
|
|
209
|
+
- Check edge cases listed in spec are handled
|
|
210
|
+
- Focus analysis on files modified/created by the track
|
|
211
|
+
|
|
212
|
+
## Toolchain & MCP Auto-Connect
|
|
213
|
+
|
|
214
|
+
After loading Layer 1 context, check `draft/workflow.md` → `## Toolchain` section. Draft uses standard `git` for VCS — see `core/shared/vcs-commands.md` for the command conventions.
|
|
215
|
+
|
|
216
|
+
### MCP Auto-Connect (optional)
|
|
217
|
+
|
|
218
|
+
If MCP integrations are checked in `draft/workflow.md`, verify availability at context-load time:
|
|
219
|
+
|
|
220
|
+
| Server | Verification Call | On Success | On Failure |
|
|
221
|
+
|--------|-------------------|------------|------------|
|
|
222
|
+
| Jira MCP | `get_issue(key="TEST-1", prune_mode="minimal")` — expect error, confirms server responds | Record: `jira_mcp=available` | Record: `jira_mcp=unavailable`, degrade gracefully |
|
|
223
|
+
| Confluence MCP | Check for Confluence tools in environment (e.g., `search_confluence`, `get_page`) | Record: `confluence_mcp=available` | Record: `confluence_mcp=unavailable`, degrade gracefully |
|
|
224
|
+
| GitHub MCP | Check for GitHub tools in environment (e.g., `gh_pr_create`, `gh_issue_get`) | Record: `github_mcp=available` | Record: `github_mcp=unavailable`, fall back to `gh` CLI |
|
|
225
|
+
|
|
226
|
+
MCP availability status is passed to downstream skills. Skills that can leverage MCPs will automatically use them when available, falling back to local-only analysis when unavailable.
|
|
227
|
+
|
|
228
|
+
### Confluence Integration Points
|
|
229
|
+
|
|
230
|
+
When Confluence MCP is available, skills can leverage it for documentation lookup:
|
|
231
|
+
|
|
232
|
+
| Skill | Confluence Use |
|
|
233
|
+
|-------|---------------|
|
|
234
|
+
| `/draft:init` | Search for existing design documents, architecture docs related to the project |
|
|
235
|
+
| `/draft:new-track` | Search for relevant RFCs, design docs, or prior art before starting a track |
|
|
236
|
+
|
|
237
|
+
## Degradation Behavior
|
|
238
|
+
|
|
239
|
+
| Scenario | Behavior |
|
|
240
|
+
|----------|----------|
|
|
241
|
+
| No `draft/` directory | Proceed with code-only analysis (no context enrichment) |
|
|
242
|
+
| `.ai-profile.md` missing | Skip Layer 0; proceed directly to Layer 1 context loading |
|
|
243
|
+
| `.ai-context.md` missing | Fall back to `draft/architecture.md` if it exists |
|
|
244
|
+
| `tech-stack.md` missing | Skip framework-specific checks |
|
|
245
|
+
| `product.md` missing | Skip product requirement verification |
|
|
246
|
+
| `workflow.md` missing | Skip workflow preferences |
|
|
247
|
+
| `guardrails.md` missing | Fall back to `workflow.md ## Guardrails`; if neither exists, skip guardrail enforcement |
|
|
248
|
+
| `draft/graph/` missing | Skip Layer 1.5; no structural graph data available |
|
|
249
|
+
| `facts.json` missing | Skip Layer 2; no fact-level context available |
|
|
250
|
+
| Track files missing | Warn and proceed with project-level scope |
|
|
251
|
+
|
|
252
|
+
## Context-Enriched Analysis
|
|
253
|
+
|
|
254
|
+
Once loaded, Draft context enables analysis that pure code reading cannot:
|
|
255
|
+
|
|
256
|
+
- **Architecture violations** — Coupling or boundary violations against intended module structure
|
|
257
|
+
- **Framework-specific checks** — Anti-patterns for the specific frameworks in tech-stack.md
|
|
258
|
+
- **Product requirement bugs** — Behavior that contradicts product.md user flows
|
|
259
|
+
- **Invariant violations** — Data safety, security, concurrency, ordering, idempotency violations
|
|
260
|
+
- **Concurrency analysis** — Race conditions and deadlocks informed by the documented concurrency model
|
|
261
|
+
- **Error handling gaps** — Missing failure modes against documented failure recovery matrix
|
|
262
|
+
- **State machine violations** — Invalid transitions, missing guards, states with no exit
|
|
263
|
+
- **Consistency boundary bugs** — Stale reads, lost events at eventual-consistency seams
|
|
264
|
+
- **Guardrail violations** — Checked hard guardrails and learned anti-patterns from guardrails.md
|
|
265
|
+
- **False positive suppression** — Learned conventions and accepted patterns are skipped during analysis
|
|
266
|
+
- **Precise dependency analysis** — Module boundaries, weighted edges, and cycle detection from graph data (Layer 1.5)
|
|
267
|
+
- **Impact assessment** — Blast radius of file changes using graph callers/impact queries
|
|
268
|
+
- **Hotspot awareness** — High-complexity, high-fanIn files flagged before modification
|
|
269
|
+
|
|
270
|
+
## Future MCP Extensions
|
|
271
|
+
|
|
272
|
+
The following MCP integrations are planned but not yet available. Skills referencing these should use graceful fallback (manual input or skip).
|
|
273
|
+
|
|
274
|
+
| MCP Server | Purpose | Used By | Status |
|
|
275
|
+
|---|---|---|---|
|
|
276
|
+
| Monitoring MCP | Metrics dashboards, alert history, SLO status | `incident-response`, `deploy-checklist` | Planned |
|
|
277
|
+
| CI/CD MCP | Build status, pipeline triggers, deployment history | `deploy-checklist` | Planned |
|
|
278
|
+
| Chat MCP | Slack/Teams notifications, war room creation | `incident-response` | Planned |
|
|
279
|
+
| Incident Management MCP | PagerDuty/OpsGenie integration, on-call schedules | `incident-response` | Planned |
|
|
280
|
+
| APM MCP | Distributed traces, error tracking, performance profiles | `debug`, `incident-response` | Planned |
|
|
281
|
+
|
|
282
|
+
When these MCPs become available, update the corresponding skills to auto-connect using the standard MCP auto-connect pattern defined above.
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Git Report Metadata
|
|
2
|
+
|
|
3
|
+
Shared procedure for gathering git metadata and generating YAML frontmatter in Draft reports.
|
|
4
|
+
|
|
5
|
+
Referenced by: All skills that generate Draft reports — including `/draft:bughunt`, `/draft:deep-review`, `/draft:review`, `/draft:quick-review`, `/draft:tech-debt`, `/draft:deploy-checklist`, `/draft:incident-response`, `/draft:debug`, `/draft:standup`, `/draft:testing-strategy`
|
|
6
|
+
|
|
7
|
+
> **Two-tier metadata pattern:**
|
|
8
|
+
> - **Project-level artifacts** (`draft/architecture.md`, `.ai-context.md`, `.ai-profile.md`, `product.md`, `workflow.md`, etc.): git state lives in `draft/metadata.json` only. Per-file frontmatter carries only `project`, `module`, `generated_by`, `generated_at`. Skills read `synced_to_commit` from `draft/metadata.json`.
|
|
9
|
+
> - **Session/report artifacts** (`draft/bughunt-report-*.md`, `draft/review-*.md`, etc.): embed full git frontmatter using the template below — these are point-in-time snapshots, not refreshable docs.
|
|
10
|
+
> - **Track artifacts** (`tracks/<id>/spec.md`, `hld.md`, etc.): git state lives in `tracks/<id>/metadata.json`. Per-file frontmatter carries only stable fields.
|
|
11
|
+
>
|
|
12
|
+
> This doc covers session/report artifacts. For project-level artifacts see `core/templates/draft-metadata.json`.
|
|
13
|
+
|
|
14
|
+
## Preferred: Deterministic Script
|
|
15
|
+
|
|
16
|
+
Use `git-metadata.sh` from the plugin install, resolved via the canonical tool resolver (see [tool-resolver.md](tool-resolver.md)):
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
DRAFT_TOOLS="${DRAFT_PLUGIN_ROOT:-$HOME/.claude/plugins/draft}/scripts/tools"
|
|
20
|
+
[ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$HOME/.cursor/plugins/local/draft/scripts/tools"
|
|
21
|
+
[ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$PWD/scripts/tools"
|
|
22
|
+
bash "$DRAFT_TOOLS/git-metadata.sh" --yaml \
|
|
23
|
+
--project "$PROJECT" --module "$MODULE" \
|
|
24
|
+
--track-id "$TRACK_ID" --generated-by "draft:bughunt"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The script emits the full YAML frontmatter block shown below, including `commits_ahead_base` / `commits_behind_base` vs. `--base main`. Use `--json` for a machine-readable object with the same fields. Exits nonzero outside a git work tree.
|
|
28
|
+
|
|
29
|
+
The manual commands below remain the specification and a fallback for environments where the script is not present.
|
|
30
|
+
|
|
31
|
+
## Git Metadata Commands
|
|
32
|
+
|
|
33
|
+
Gather git info before writing the report:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
git branch --show-current # LOCAL_BRANCH
|
|
37
|
+
git rev-parse --abbrev-ref @{upstream} 2>/dev/null || echo "none" # REMOTE/BRANCH
|
|
38
|
+
git rev-parse HEAD # FULL_SHA
|
|
39
|
+
git rev-parse --short HEAD # SHORT_SHA
|
|
40
|
+
git log -1 --format=%ci HEAD # COMMIT_DATE
|
|
41
|
+
git log -1 --format=%s HEAD # COMMIT_MESSAGE
|
|
42
|
+
[ -n "$(git status --porcelain)" ] && echo "true" || echo "false" # dirty check
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## YAML Frontmatter Template
|
|
46
|
+
|
|
47
|
+
Every Draft report MUST include this frontmatter block at the top of the file. Replace placeholders with values from the commands above.
|
|
48
|
+
|
|
49
|
+
```yaml
|
|
50
|
+
---
|
|
51
|
+
project: "{PROJECT_NAME}"
|
|
52
|
+
module: "{MODULE_NAME or 'root'}"
|
|
53
|
+
track_id: "{TRACK_ID or null}"
|
|
54
|
+
generated_by: "{COMMAND_NAME}"
|
|
55
|
+
generated_at: "{ISO_TIMESTAMP}"
|
|
56
|
+
git:
|
|
57
|
+
branch: "{LOCAL_BRANCH}"
|
|
58
|
+
remote: "{REMOTE/BRANCH}"
|
|
59
|
+
commit: "{FULL_SHA}"
|
|
60
|
+
commit_short: "{SHORT_SHA}"
|
|
61
|
+
commit_date: "{COMMIT_DATE}"
|
|
62
|
+
commit_message: "{COMMIT_MESSAGE}"
|
|
63
|
+
dirty: {true|false}
|
|
64
|
+
synced_to_commit: "{FULL_SHA}"
|
|
65
|
+
---
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Field Notes
|
|
69
|
+
|
|
70
|
+
- `project` — Derive from the repository name or `draft/product.md` title
|
|
71
|
+
- `module` — Use `"root"` for project-level reports; use the module name/path for module-level reports
|
|
72
|
+
- `track_id` — Set to the track ID if scoped to a track; `null` otherwise
|
|
73
|
+
- `generated_by` — The Draft command that produced this report (e.g., `"draft:bughunt"`, `"draft:deep-review"`, `"draft:review"`)
|
|
74
|
+
- `synced_to_commit` — Use the full SHA of HEAD at report time; or read from `draft/metadata.json:synced_to_commit` if available
|
|
75
|
+
|
|
76
|
+
## Report Header Table
|
|
77
|
+
|
|
78
|
+
Include this summary table immediately after the frontmatter for human readability:
|
|
79
|
+
|
|
80
|
+
```markdown
|
|
81
|
+
| Field | Value |
|
|
82
|
+
|-------|-------|
|
|
83
|
+
| **Branch** | `{LOCAL_BRANCH}` → `{REMOTE/BRANCH}` |
|
|
84
|
+
| **Commit** | `{SHORT_SHA}` — {COMMIT_MESSAGE} |
|
|
85
|
+
| **Generated** | {ISO_TIMESTAMP} |
|
|
86
|
+
| **Synced To** | `{FULL_SHA}` |
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Timestamped File Naming
|
|
90
|
+
|
|
91
|
+
Reports use timestamped filenames with a `-latest.md` symlink:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
# Generate timestamp
|
|
95
|
+
TIMESTAMP=$(date +%Y-%m-%dT%H%M)
|
|
96
|
+
|
|
97
|
+
# Write report to timestamped file
|
|
98
|
+
# Example: draft/bughunt-report-2026-03-15T1430.md
|
|
99
|
+
|
|
100
|
+
# Refresh the "-latest.md" symlink deterministically (resolver as above):
|
|
101
|
+
[ -x "$DRAFT_TOOLS/manage-symlinks.sh" ] && bash "$DRAFT_TOOLS/manage-symlinks.sh" draft/ bughunt
|
|
102
|
+
# (Fallback when the script is unavailable:)
|
|
103
|
+
# ln -sf <report-filename> <report-dir>/<report-type>-latest.md
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Previous timestamped reports are preserved. The `-latest.md` symlink always points to the most recent report.
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
# Graph Query Subroutine
|
|
2
|
+
|
|
3
|
+
Shared procedure for querying the knowledge graph from any skill. The graph provides precise, deterministic structural data about the codebase — module boundaries, dependency edges, hotspots, proto API surface, and symbol indexes.
|
|
4
|
+
|
|
5
|
+
This is the **single source of truth** for graph lookup procedure. Consumer skills MUST reference this file rather than inlining their own lookup logic.
|
|
6
|
+
|
|
7
|
+
Referenced by: `/draft:init`, `/draft:implement`, `/draft:bughunt`, `/draft:review`, `/draft:deep-review`, `/draft:quick-review`, `/draft:debug`, `/draft:decompose`, `/draft:new-track`, `/draft:tech-debt`, `/draft:deploy-checklist`, `/draft:learn`, `/draft:index`
|
|
8
|
+
|
|
9
|
+
## Mandatory Lookup Contract
|
|
10
|
+
|
|
11
|
+
Any code-touching skill that needs to discover files, modules, symbols, callers, or blast-radius **MUST** follow this lookup order whenever `draft/graph/schema.yaml` exists:
|
|
12
|
+
|
|
13
|
+
1. **Graph first** — the committed snapshot (`architecture.json`, `hotspots.jsonl`) and the live query tools (`scripts/tools/graph-callers.sh`, `graph-impact.sh`, `cycle-detect.sh`, `hotspot-rank.sh`).
|
|
14
|
+
2. **Generated context second** — `draft/.ai-context.md`, relevant `draft/architecture.md` slices, track-level `hld.md`/`lld.md`.
|
|
15
|
+
3. **Source file reads third** — narrow via tiers 1–2, then **Read** the candidate files. Reading is **not optional**: see §Ground-Truth Discipline below.
|
|
16
|
+
4. **Filesystem `grep`/`find`/`rg` last** — only after an explicit graph miss.
|
|
17
|
+
|
|
18
|
+
**If a lower tier is used before a higher tier, that is a Red Flag** ([red-flags.md](red-flags.md)). The skill must report it in its Graph Usage Report footer (see below) with justification.
|
|
19
|
+
|
|
20
|
+
**Required fallback sentence format** (verbatim) before any filesystem search after a graph miss:
|
|
21
|
+
|
|
22
|
+
> `Graph returned no match for <X>; falling back to grep.`
|
|
23
|
+
|
|
24
|
+
If `draft/graph/schema.yaml` is **absent**, the graph contract is satisfied — proceed directly to tier 2/3/4 as needed and record `Graph files queried: NONE — graph data unavailable` in the report footer.
|
|
25
|
+
|
|
26
|
+
## Ground-Truth Discipline (mandatory)
|
|
27
|
+
|
|
28
|
+
The graph is the **index**, not the **territory**. Graph hits identify candidates; **Read** validates them. Skills that ship claims about code behavior, scope coverage, hotspot status, or risk **without opening the cited files** routinely produce confidently-wrong output (e.g. citations marked `TBD` for files that were "found via graph but never opened"; scope statements that exclude the actual code path the problem statement names).
|
|
29
|
+
|
|
30
|
+
The following rules apply to every code-touching skill output. They are non-negotiable for `criticality: standard | high | mission-critical` work; `criticality: low` (quick) tracks may skip rule **G3** only.
|
|
31
|
+
|
|
32
|
+
**G1. Read before you cite.** Any `file:line`, `func()`, or `symbol` reference written into a deliverable (spec / hld / lld / plan / review / audit / debug report) must come from a file the skill has actually opened in this run. The graph tells you *which* file; Read confirms the line is what you claim it is.
|
|
33
|
+
|
|
34
|
+
**G2. Read before you scope.** A track / phase / audit / review may not declare a code path **in-scope** or **out-of-scope** without at least one Read on a representative file in that path. The graph's module list is a candidate set — it does not establish that the candidate contains the cost the problem names.
|
|
35
|
+
|
|
36
|
+
**G3. No `TBD` citations on `Modified` or `Existing` modules.** When a deliverable's Component / Class / Symbol table marks a module `Status: Modified` or `Status: Existing`, every Citation cell must resolve to a real `path:line` from a file read in this run. `TBD` is reserved for `Status: New` modules whose source files have not been authored yet, and even then the planned file path must be filled (`Citation: path/to/new_file.h (planned)`).
|
|
37
|
+
|
|
38
|
+
**G4. No claim about code behavior from graph metadata alone.** Statements of the form "*X writes to disk*", "*Y blocks on Z*", "*this is the hotspot*", "*this is the only path*" must be backed by a Read. Graph fan-in / fan-out / complexity scores are necessary signal, not sufficient evidence. If you have only graph data, write *"graph signal suggests X; not yet validated against source"* rather than asserting X.
|
|
39
|
+
|
|
40
|
+
**G5. Scope-vs-problem coverage check before promote.** Before promoting `spec-draft.md` → `spec.md`, before generating `hld.md` / `lld.md`, and before declaring a review / audit complete: enumerate the cost / behavior / risk terms in the problem statement, and confirm that the in-scope file set (per G2) covers each. If any term is not covered, surface the gap before commit — do not silently ship a scope that excludes the named cost.
|
|
41
|
+
|
|
42
|
+
### Self-check (run before emitting the Graph Usage Report)
|
|
43
|
+
|
|
44
|
+
Append the answers to your scratch notes; the skill output need not include them unless asked.
|
|
45
|
+
|
|
46
|
+
1. Did I open every file whose `path:line` appears in this output? (yes / list misses)
|
|
47
|
+
2. Are any `Modified` / `Existing` modules carrying `Citation: TBD`? (no / list)
|
|
48
|
+
3. Did I declare anything in-scope or out-of-scope? If yes, did I Read at least one file in that path? (yes / list)
|
|
49
|
+
4. Did I make a claim about what code does (writes / blocks / loops / fails) based only on graph metadata? (no / list)
|
|
50
|
+
5. Does the in-scope set cover every cost term in the problem statement? (yes / list gaps)
|
|
51
|
+
|
|
52
|
+
A single "no" / "list" answer is a halt — fix and re-check before output.
|
|
53
|
+
|
|
54
|
+
## Concept-to-Files Recipe
|
|
55
|
+
|
|
56
|
+
Use this recipe whenever the user names a concept, feature, or domain term ("in-memory shuffle", "auth flow", "ingest pipeline") and you need to locate the implementing files. **Run it before any filesystem search.**
|
|
57
|
+
|
|
58
|
+
1. **Concept → modules** — `grep` the concept token against `draft/graph/architecture.json` (`.packages[].name`) and `draft/.ai-context.md` (module headings). Record the candidate module list.
|
|
59
|
+
2. **Concept → symbols/callers** — for a named function, run `scripts/tools/graph-callers.sh --repo . --symbol <name>` to find call sites, and `scripts/tools/graph-impact.sh --repo . --symbol <name>` for transitive dependents. These are the authoritative structural answers.
|
|
60
|
+
3. **Modules → risk ranking** — cross-reference `draft/graph/hotspots.jsonl` (or `scripts/tools/hotspot-rank.sh`). High-fanIn symbols are the most likely entry points for impact.
|
|
61
|
+
4. **Concept → public API** — for API-shaped concepts, consult `architecture.json` `.routes` (detected HTTP/gRPC/GraphQL routes) for matching service surface.
|
|
62
|
+
5. **Graph miss → grep fallback** — only if steps 1–4 return nothing relevant, emit the fallback sentence and use `grep`/`find`. Narrow the search by file extension and exclude `node_modules`, `vendor`, `dist`, `build`, `.git`.
|
|
63
|
+
|
|
64
|
+
## Graph Usage Report (Mandatory Footer)
|
|
65
|
+
|
|
66
|
+
Every code-touching skill output MUST end with this footer block. The lint check `scripts/tools/check-graph-usage-report.sh` rejects outputs missing the section.
|
|
67
|
+
|
|
68
|
+
```md
|
|
69
|
+
## Graph Usage Report
|
|
70
|
+
|
|
71
|
+
- Graph files queried: <comma-separated list, e.g. `architecture.json, hotspots.jsonl` and/or query tools like `graph-callers.sh` — or `NONE` with justification below>
|
|
72
|
+
- Modules identified via graph: <comma-separated module names, or `none`>
|
|
73
|
+
- Files identified via graph: <integer count>
|
|
74
|
+
- Filesystem grep fallbacks: <list of `<pattern>` searches with one-line justification each, or `none`>
|
|
75
|
+
- Justification (only when `Graph files queried: NONE`): <required — `graph data unavailable` | `non-code task` | `<explicit reason>`>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**Gate:** `Graph files queried: NONE` without a populated justification line is a hard failure.
|
|
79
|
+
|
|
80
|
+
## Telemetry Fields (graph adherence)
|
|
81
|
+
|
|
82
|
+
Skills that emit telemetry via [emit-skill-metrics.sh](../../scripts/tools/emit-skill-metrics.sh) MUST include these fields in the JSON payload so contract adherence and token-floor trends can be monitored:
|
|
83
|
+
|
|
84
|
+
| Field | Type | Description |
|
|
85
|
+
|---|---|---|
|
|
86
|
+
| `graph_queries` | int | Number of graph artifacts loaded plus live graph query-tool invocations during the run |
|
|
87
|
+
| `fallback_grep_count` | int | Number of `grep`/`find` fallbacks invoked after an explicit graph miss |
|
|
88
|
+
|
|
89
|
+
These fields are appended to `~/.draft/metrics.jsonl` along with the existing skill fields (`skill`, `track_id`, etc.) — no new state file is needed. Run `tail -100 ~/.draft/metrics.jsonl | jq -s 'group_by(.skill) | map({skill: .[0].skill, runs: length, avg_graph_queries: ([.[].graph_queries] | add / length), avg_grep_fallbacks: ([.[].fallback_grep_count] | add / length)})'` to monitor adherence per skill.
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
## Tooling Wrappers
|
|
94
|
+
|
|
95
|
+
For common query modes, prefer the deterministic wrappers that ship with the plugin. Resolve their location via the canonical tool resolver (see [tool-resolver.md](tool-resolver.md)) before invoking:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
DRAFT_TOOLS="${DRAFT_PLUGIN_ROOT:-$HOME/.claude/plugins/draft}/scripts/tools"
|
|
99
|
+
[ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$HOME/.cursor/plugins/local/draft/scripts/tools"
|
|
100
|
+
[ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$PWD/scripts/tools"
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
| Wrapper | Graph mode | Behavior on missing graph |
|
|
104
|
+
|---|---|---|
|
|
105
|
+
| `bash "$DRAFT_TOOLS/hotspot-rank.sh" [--top N] [--module NAME]` | `--mode hotspots` | Emits `{hotspots:[],source:"unavailable"}` and exits 2 |
|
|
106
|
+
| `bash "$DRAFT_TOOLS/cycle-detect.sh"` | `--mode cycles` | Emits `{cycles:[],source:"unavailable"}` and exits 2 |
|
|
107
|
+
| `bash "$DRAFT_TOOLS/mermaid-from-graph.sh" [--diagram module-deps\|proto-map]` | `--mode mermaid` | Emits an empty mermaid block and exits 2 |
|
|
108
|
+
|
|
109
|
+
Use the raw `graph` CLI directly for the lower-level modes documented below.
|
|
110
|
+
|
|
111
|
+
## Pre-Check
|
|
112
|
+
|
|
113
|
+
Verify graph data exists before any graph operation:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
ls draft/graph/schema.yaml 2>/dev/null
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
If absent, **skip all graph operations silently**. Graph enriches analysis — it never gates it. All skills must work identically without graph data.
|
|
120
|
+
|
|
121
|
+
## Engine + snapshot model
|
|
122
|
+
|
|
123
|
+
The graph is produced by the **codebase-memory-mcp** engine (a single binary; see [bin/README.md](../../bin/README.md)). There are two ways skills consume it:
|
|
124
|
+
|
|
125
|
+
1. **Live queries** (preferred when the engine is resolvable) — the shell tools under `scripts/tools/` drive the engine on demand (it auto-indexes into its own cache). No committed files required.
|
|
126
|
+
2. **Committed snapshot** (`draft/graph/`) — a small, derived, PR-reviewable snapshot written by `scripts/tools/graph-snapshot.sh`. It exists for reviewability and for the Copilot/Gemini integrations, which cannot run the engine but can read committed files. Git remains the source of truth.
|
|
127
|
+
|
|
128
|
+
When `draft/graph/` exists, the snapshot contains:
|
|
129
|
+
|
|
130
|
+
| File | Load | Content |
|
|
131
|
+
|------|------|---------|
|
|
132
|
+
| `schema.yaml` | Always | Engine + project metadata, node/edge counts, artifact list. Its presence **gates** graph use (see Pre-Check). |
|
|
133
|
+
| `architecture.json` | Always | `get_architecture(all)` output: node labels, edge types, languages, packages (with fan-in/out), entry points, routes, hotspots. |
|
|
134
|
+
| `hotspots.jsonl` | Always | Fan-in-ranked symbols, one JSON object per line: `{id, name, fanIn}`. |
|
|
135
|
+
| `module-deps.mermaid` | Diagram injection | File co-change coupling diagram (`FILE_CHANGES_WITH`). |
|
|
136
|
+
| `proto-map.mermaid` | Diagram injection | Detected service-route diagram (`Route` nodes). |
|
|
137
|
+
|
|
138
|
+
The engine uses a **unified, language-agnostic** node model — `Function`, `Method`, `Class`, `Module`, `File`, `Folder`, `Route`, `Section`, `Variable` (language is inferred from file extension) — and edges `CALLS`, `DEFINES`, `CONTAINS_FILE`, `IMPORTS`, `HTTP_CALLS`, `FILE_CHANGES_WITH`, `SEMANTICALLY_RELATED`, `SIMILAR_TO`. There are **no** per-language index files and no `ctags-sym` fallback; that detail is served by live queries against the unified model.
|
|
139
|
+
|
|
140
|
+
**Always-load files** are compact and should be read during context loading for any task that touches code structure.
|
|
141
|
+
|
|
142
|
+
## Query Tools
|
|
143
|
+
|
|
144
|
+
Live queries go through the shell tools under `scripts/tools/`, which drive the engine and shape results into stable JSON. Each tool resolves the engine (see Finding the Engine), indexes the repo on demand, and emits `source: "memory-graph"` on success or `source: "unavailable"` (non-zero exit) when the engine cannot be resolved. Set `DRAFT_MEMORY_DISABLE=1` to force the engine off; all tools then degrade gracefully.
|
|
145
|
+
|
|
146
|
+
### Callers — who calls this function?
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
scripts/tools/graph-callers.sh --repo . --symbol <name>
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Output: `{symbol, callers[{name, file}], source}`. Use when enumerating call sites before claiming "no other usages" or judging breaking-change severity.
|
|
153
|
+
|
|
154
|
+
### Impact — blast radius of a file or symbol
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
scripts/tools/graph-impact.sh --repo . --file <path> # changed-file impact (working-tree diff)
|
|
158
|
+
scripts/tools/graph-impact.sh --repo . --symbol <name> # transitive callers of a function
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Output: `{target, kind, impacted[{name, file, hop}], source}`. Use when sizing risk before modifying a file or symbol, especially high-fan-in hotspots.
|
|
162
|
+
|
|
163
|
+
### Hotspots — fan-in ranking
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
scripts/tools/hotspot-rank.sh --repo . [--top N]
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Output: `{hotspots[{id, name, fanIn}], source}` (server-computed by the engine).
|
|
170
|
+
|
|
171
|
+
### Cycles — call-cycle detection
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
scripts/tools/cycle-detect.sh --repo .
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Output: `{cycles[[a,b],[a,b,c]], source}` — fixed-length 2- and 3-node `CALLS` cycles (mutual recursion / tight coupling).
|
|
178
|
+
|
|
179
|
+
### Modules — dependency overview
|
|
180
|
+
|
|
181
|
+
Read `draft/graph/architecture.json` (`.packages` for module fan-in/out, `.node_labels`/`.edge_types` for shape, `.routes` for service surface), or regenerate it with `scripts/tools/graph-snapshot.sh --repo .`.
|
|
182
|
+
|
|
183
|
+
### Mermaid — diagram text
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
scripts/tools/mermaid-from-graph.sh --repo . --diagram module-deps # co-change coupling
|
|
187
|
+
scripts/tools/mermaid-from-graph.sh --repo . --diagram proto-map # detected routes
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Emits a ready-to-inject ` ```mermaid ``` ` block, or an empty stub (exit 2) when the engine is unavailable. The committed `draft/graph/*.mermaid` snapshots are written by `graph-snapshot.sh`.
|
|
191
|
+
|
|
192
|
+
### Building / refreshing the snapshot
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
scripts/tools/graph-snapshot.sh --repo .
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Writes the committed `draft/graph/` snapshot (`schema.yaml`, `architecture.json`, `hotspots.jsonl`, `*.mermaid`). Run during `/draft:init` and `/draft:index`, or whenever the reviewable graph state should be refreshed.
|
|
199
|
+
|
|
200
|
+
## Finding the Engine (Resolution + Usage Report)
|
|
201
|
+
|
|
202
|
+
The engine is the `codebase-memory-mcp` binary. Resolution order (implemented by `scripts/tools/_lib.sh:find_memory_bin`):
|
|
203
|
+
|
|
204
|
+
1. `DRAFT_MEMORY_BIN` — explicit override (pinned installs, testing).
|
|
205
|
+
2. `codebase-memory-mcp` on `$PATH` — global/dev installs.
|
|
206
|
+
3. `~/.cache/draft/bin/codebase-memory-mcp` — the Draft-managed location (`scripts/fetch-memory-engine.sh` installs it here; `draft install claude-code`/`draft install cursor` run that on install unless `--no-graph`).
|
|
207
|
+
4. `bin/<os>-<arch>/codebase-memory-mcp` under the plugin/repo root — optional vendored fallback (air-gapped only).
|
|
208
|
+
|
|
209
|
+
`DRAFT_MEMORY_DISABLE=1` forces the engine off. There is **no** legacy `graph`/`graph-clang` fallback.
|
|
210
|
+
|
|
211
|
+
The canonical verifier is `scripts/tools/verify-graph-binary.sh` (`--json --verbose --strict`). It resolves and liveness-checks the engine and, in a `draft/` context, writes the usage-report side-effect:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
ENGINE_INFO="$(scripts/tools/verify-graph-binary.sh --repo . --json 2>/dev/null || true)"
|
|
215
|
+
# {"status":"ok","engine_bin":"...","source":"managed|path|bundled:<arch>|override","arch":"..."}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Usage Report Contract
|
|
219
|
+
|
|
220
|
+
After successful detection, `draft/.graph-binary-report.json` contains: `detected_at`, `engine_bin`, `source` (`path` | `managed` | `bundled:<arch>` | `override`), `arch`, `status`. It is a derived artifact (safe to prune), regenerated by each graph-using command that calls the verifier.
|
|
221
|
+
|
|
222
|
+
## Building the Snapshot
|
|
223
|
+
|
|
224
|
+
Run during `draft:init` / `draft:index`, or manually:
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
scripts/tools/graph-snapshot.sh --repo .
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
The engine indexes C/C++, Go, Python, TypeScript/JS, and more (tree-sitter, 159 languages) plus LSP-assisted resolution for the major ones, and detects HTTP/gRPC/GraphQL routes. Indexing is incremental in the engine (content-based, git-aware); the snapshot is re-derived on each run.
|
|
231
|
+
|
|
232
|
+
## Graceful Degradation
|
|
233
|
+
|
|
234
|
+
| Scenario | Behavior |
|
|
235
|
+
|----------|----------|
|
|
236
|
+
| No engine resolvable (or `DRAFT_MEMORY_DISABLE=1`) | Skip graph build in init; all skills proceed without graph data; tools emit `source: unavailable` |
|
|
237
|
+
| Engine present but a query fails | Warn and proceed; skills work without graph data |
|
|
238
|
+
| `draft/graph/` snapshot exists | Load always-load files during context loading; use live query tools as needed |
|
|
239
|
+
| Stale snapshot | Still useful — structural changes are infrequent. Re-run `graph-snapshot.sh` (or init) to refresh. |
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
shared: graph-usage-report
|
|
3
|
+
applies_to: quality + init + graph skills
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Graph Usage Report (Canonical Footer)
|
|
7
|
+
|
|
8
|
+
Every code-touching skill output that performs graph or filesystem discovery MUST end with this footer block. The lint hook `scripts/tools/check-graph-usage-report.sh` validates the section on save.
|
|
9
|
+
|
|
10
|
+
See [graph-query.md](graph-query.md) §Graph Usage Report (Mandatory Footer) for the full lookup contract. Emit this block verbatim:
|
|
11
|
+
|
|
12
|
+
```md
|
|
13
|
+
## Graph Usage Report
|
|
14
|
+
|
|
15
|
+
- Graph files queried: <comma-separated list, e.g. `architecture.json, hotspots.jsonl` and/or query tools like `graph-callers.sh` — or `NONE` with justification below>
|
|
16
|
+
- Modules identified via graph: <comma-separated module names, or `none`>
|
|
17
|
+
- Files identified via graph: <integer count>
|
|
18
|
+
- Filesystem grep fallbacks: <list of `<pattern>` searches with one-line justification each, or `none`>
|
|
19
|
+
- Justification (only when `Graph files queried: NONE`): <required — `graph data unavailable` | `non-code task` | `<explicit reason>`>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Gate:** `Graph files queried: NONE` without a populated justification line is a hard failure.
|