@drafthq/draft 2.8.3 → 3.1.5

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 (68) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +5 -5
  4. package/bin/README.md +10 -0
  5. package/core/methodology.md +17 -18
  6. package/core/shared/condensation.md +9 -9
  7. package/core/shared/draft-context-loading.md +7 -9
  8. package/core/shared/graph-query.md +38 -31
  9. package/core/shared/graph-usage-report.md +1 -1
  10. package/core/shared/pattern-learning.md +2 -2
  11. package/core/shared/red-flags.md +3 -3
  12. package/core/templates/ai-context.md +2 -1
  13. package/core/templates/ai-profile.md +1 -0
  14. package/core/templates/architecture.md +4 -3
  15. package/core/templates/dependency-graph.md +2 -2
  16. package/core/templates/discovery.md +1 -0
  17. package/core/templates/guardrails.md +1 -0
  18. package/core/templates/hld.md +1 -0
  19. package/core/templates/lld.md +1 -0
  20. package/core/templates/plan.md +1 -0
  21. package/core/templates/product.md +1 -0
  22. package/core/templates/rca.md +1 -0
  23. package/core/templates/root-architecture.md +3 -3
  24. package/core/templates/root-product.md +2 -2
  25. package/core/templates/root-tech-stack.md +2 -2
  26. package/core/templates/service-index.md +3 -3
  27. package/core/templates/spec.md +1 -0
  28. package/core/templates/tech-matrix.md +2 -2
  29. package/core/templates/tech-stack.md +1 -0
  30. package/core/templates/workflow.md +1 -0
  31. package/integrations/agents/AGENTS.md +276 -1037
  32. package/integrations/copilot/.github/copilot-instructions.md +276 -1037
  33. package/package.json +1 -1
  34. package/scripts/lib.sh +2 -1
  35. package/scripts/tools/adr-index.sh +2 -2
  36. package/scripts/tools/check-scope-conflicts.sh +2 -2
  37. package/scripts/tools/check-skill-line-caps.sh +2 -2
  38. package/scripts/tools/cycle-detect.sh +5 -1
  39. package/scripts/tools/diff-templates-vs-tracks.sh +2 -2
  40. package/scripts/tools/fix-whitespace.sh +15 -9
  41. package/scripts/tools/graph-arch.sh +72 -0
  42. package/scripts/tools/graph-impact.sh +1 -0
  43. package/scripts/tools/graph-init.sh +187 -0
  44. package/scripts/tools/graph-snapshot.sh +52 -46
  45. package/scripts/tools/hotspot-rank.sh +2 -0
  46. package/scripts/tools/manage-symlinks.sh +1 -1
  47. package/scripts/tools/parse-reports.sh +1 -1
  48. package/scripts/tools/skill-caps.conf +0 -1
  49. package/scripts/tools/verify-doc-anchors.sh +2 -2
  50. package/scripts/tools/verify-graph-binary.sh +1 -1
  51. package/skills/GRAPH.md +9 -12
  52. package/skills/bughunt/SKILL.md +14 -1
  53. package/skills/debug/SKILL.md +3 -3
  54. package/skills/decompose/SKILL.md +5 -5
  55. package/skills/deep-review/SKILL.md +2 -2
  56. package/skills/deploy-checklist/SKILL.md +2 -2
  57. package/skills/discover/SKILL.md +2 -4
  58. package/skills/draft/SKILL.md +2 -2
  59. package/skills/draft/intent-mapping.md +3 -2
  60. package/skills/graph/SKILL.md +3 -3
  61. package/skills/implement/SKILL.md +1 -1
  62. package/skills/init/SKILL.md +102 -43
  63. package/skills/init/references/architecture-spec.md +17 -16
  64. package/skills/learn/SKILL.md +5 -5
  65. package/skills/quick-review/SKILL.md +3 -3
  66. package/skills/review/SKILL.md +7 -7
  67. package/skills/tech-debt/SKILL.md +2 -2
  68. package/skills/index/SKILL.md +0 -848
@@ -1,848 +0,0 @@
1
- ---
2
- name: index
3
- description: Build federated index from all child draft/ directories. Aggregates service-level context into root-level knowledge without deep code analysis. Use at monorepo root after services have been initialized with /draft:init.
4
- ---
5
-
6
- # Draft Index
7
-
8
- You are building a federated knowledge index for a monorepo with multiple services.
9
-
10
- ## Red Flags - STOP if you're:
11
-
12
- - Running at a non-root directory in a monorepo
13
- - Indexing services that haven't been initialized with `/draft:init`
14
- - Overwriting root-level context without confirming with the user
15
- - Aggregating without verifying each service's draft/ directory exists
16
- - Skipping dependency mapping between services
17
-
18
- **Aggregate from initialized services only. Verify before overwriting.**
19
-
20
- ---
21
-
22
- ## Standard File Metadata
23
-
24
- **ALL generated files MUST include the standard YAML frontmatter.** This enables refresh tracking, sync verification, and traceability.
25
-
26
- ### Project Metadata File (single source of truth)
27
-
28
- Before writing any file, update `draft/metadata.json` with current git state. This is the single source of truth for `synced_to_commit` and all `git.*` fields for every project-level artifact. Do NOT embed git fields in per-file frontmatter.
29
-
30
- Use the `--project-metadata` flag (preferred):
31
-
32
- ```bash
33
- DRAFT_TOOLS="${DRAFT_PLUGIN_ROOT:-$HOME/.claude/plugins/draft}/scripts/tools"
34
- [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$HOME/.cursor/plugins/local/draft/scripts/tools"
35
- [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$PWD/scripts/tools"
36
- bash "$DRAFT_TOOLS/git-metadata.sh" --project-metadata \
37
- --project "$PROJECT" --generated-by "draft:index"
38
- ```
39
-
40
- ### Per-File Metadata Template
41
-
42
- Insert this **stable** YAML frontmatter at the top of every generated file (`service-index.md`, `dependency-graph.md`, `tech-matrix.md`, `draft-index-bughunt-summary.md`):
43
-
44
- ```yaml
45
- ---
46
- project: "{PROJECT_NAME}"
47
- module: "root"
48
- generated_by: "draft:index"
49
- generated_at: "{ISO_TIMESTAMP}"
50
- ---
51
- ```
52
-
53
- > **Note**: `generated_by` uses `draft:command` format (not `/draft:command`) for cross-platform compatibility.
54
-
55
- ---
56
-
57
- ## Pre-Check
58
-
59
- ```bash
60
- ls draft/ 2>/dev/null
61
- ```
62
-
63
- **If `draft/` does NOT exist at root:**
64
- - Announce: "Root draft/ directory not found. Run `/draft:init` at monorepo root first to create base context, then run `/draft:index` to aggregate service knowledge."
65
- - Stop here.
66
-
67
- **If `draft/` exists:** Continue to lockfile check.
68
-
69
- ## Lockfile Check
70
-
71
- Before proceeding, check for a stale lock:
72
-
73
- ```bash
74
- ls draft/.index-lock 2>/dev/null
75
- ```
76
-
77
- - **If `draft/.index-lock` exists and is less than 10 minutes old:** Warn: "Previous indexing may be incomplete. Remove `draft/.index-lock` to proceed." Stop here.
78
- - **If `draft/.index-lock` exists and is older than 10 minutes:** Remove it and continue.
79
- - **If no lock exists:** Continue.
80
-
81
- Create `draft/.index-lock` with the current timestamp before starting:
82
-
83
- ```bash
84
- date -u +"%Y-%m-%dT%H:%M:%SZ" > draft/.index-lock
85
- ```
86
-
87
- **On completion (Step 9) or fatal error, remove the lock:**
88
-
89
- ```bash
90
- rm -f draft/.index-lock
91
- ```
92
-
93
- ## Step 1: Parse Arguments
94
-
95
- Check for optional arguments:
96
- - `--init-missing`: Also initialize services that don't have `draft/` directories
97
- - `bughunt [dir1 dir2 ...]`: Run bug hunt across subdirectories with `draft/` folders
98
- - If no directories specified: auto-discover all subdirectories with `draft/`
99
- - If directories specified: run bughunt only in those subdirectories (skip if no `draft/`)
100
- - Generate summary report at: `draft/bughunt-summary.md`
101
-
102
- **If `bughunt` argument detected:** Skip to Step 1A (Bughunt Mode) instead of continuing to Step 2.
103
-
104
- ## Step 1A: Bughunt Mode
105
-
106
- This mode runs `/draft:bughunt` across multiple subdirectories and aggregates results.
107
-
108
- ### 1A.1: Determine Target Directories
109
-
110
- **If directories explicitly specified** (e.g., `bughunt dir1 dir2 dir3`):
111
- - Use provided directory list as targets
112
- - Verify each directory exists
113
- - Check each directory for `draft/` subdirectory
114
- - Warn and skip any directory without `draft/`
115
-
116
- **If no directories specified** (e.g., just `bughunt`):
117
- - Auto-discover all immediate child directories (depth=1)
118
- - Filter for directories containing `draft/` subdirectory
119
- - Exclude patterns: `node_modules/`, `vendor/`, `.git/`, `draft/`, `.*`
120
-
121
- ```bash
122
- # Example auto-discovery
123
- for dir in */; do
124
- if [ -d "$dir/draft" ]; then
125
- echo "$dir"
126
- fi
127
- done
128
- ```
129
-
130
- **Output:**
131
- ```
132
- Target directories for bughunt:
133
- - services/auth/
134
- - services/billing/
135
- - services/notifications/
136
- ```
137
-
138
- ### 1A.2: Execute Bughunt Per Directory
139
-
140
- For each target directory:
141
-
142
- 1. **Set working directory** to `<target-dir>` for the bughunt scope. The AI agent should invoke `/draft:bughunt` with the target directory as the scope path, rather than using `cd`:
143
- ```
144
- /draft:bughunt
145
- → (scope prompt) → "Specific paths"
146
- → (paths prompt) → <target-dir>
147
- ```
148
-
149
- 2. **Announce:**
150
- ```
151
- Running bughunt in <target-dir>...
152
- ```
153
-
154
- 3. **Let `/draft:bughunt` run its full workflow:**
155
- - Report will be generated at `<target-dir>/draft/bughunt-report-<timestamp>.md`
156
- - Capture exit status (success/failure)
157
-
158
- 4. **Record results:**
159
- - Directory path
160
- - Total bugs found (by severity)
161
- - Report location
162
- - Any errors encountered
163
-
164
- **Note:** Run bughunts sequentially, not in parallel, to avoid context conflicts.
165
-
166
- ### 1A.3: Parse Individual Reports
167
-
168
- After all bughunts complete, read each generated report:
169
-
170
- ```bash
171
- # For each target directory
172
- cat <dir>/draft/bughunt-report-latest.md
173
- ```
174
-
175
- Extract from each report:
176
- - Branch and commit (from header)
177
- - Summary table (bug counts by severity)
178
- - Critical/High issue count
179
- - Total issues count
180
-
181
- ### 1A.4: Generate Aggregate Summary Report
182
-
183
- Create `draft/bughunt-summary.md`:
184
-
185
- ```markdown
186
- # Draft Index: Bughunt Summary
187
-
188
- **Date:** YYYY-MM-DD HH:MM
189
- **Mode:** [Auto-discovery | Explicit directories]
190
- **Directories Scanned:** N
191
-
192
- ## Overview
193
-
194
- | Directory | Critical | High | Medium | Low | Total | Report |
195
- |-----------|----------|------|--------|-----|-------|--------|
196
- | services/auth/ | 0 | 2 | 5 | 3 | 10 | [→](services/auth/draft/bughunt-report.md) |
197
- | services/billing/ | 1 | 1 | 2 | 1 | 5 | [→](services/billing/draft/bughunt-report.md) |
198
- | services/notifications/ | 0 | 0 | 1 | 2 | 3 | [→](services/notifications/draft/bughunt-report.md) |
199
-
200
- **Grand Total:** X Critical, Y High, Z Medium, W Low
201
-
202
- ## Directories With Critical Issues
203
-
204
- | Directory | Count | Details |
205
- |-----------|-------|---------|
206
- | services/billing/ | 1 | [→](services/billing/draft/bughunt-report.md#critical-issues) |
207
-
208
- ## Directories With No Issues
209
-
210
- - services/api-gateway/
211
- - services/user-service/
212
-
213
- ## Skipped Directories
214
-
215
- | Directory | Reason |
216
- |-----------|--------|
217
- | services/legacy-tools/ | No draft/ directory found |
218
- | services/experiments/ | No draft/ directory found |
219
-
220
- ## Next Steps
221
-
222
- 1. **Prioritize Critical Issues:** Review directories with Critical bugs first
223
- 2. **Review Individual Reports:** Click links above to see detailed findings
224
- 3. **Track Fixes:** Use `/draft:new-track` to create implementation tracks for fixes
225
- 4. **Re-run After Fixes:** Run `/draft:index bughunt` again to verify
226
-
227
- ---
228
-
229
- *Generated by `/draft:index bughunt` command*
230
- ```
231
-
232
- ### 1A.5: Completion Report
233
-
234
- ```
235
- ---
236
- DRAFT INDEX BUGHUNT COMPLETE
237
- ---
238
- Scanned: N directories
239
- Completed: X successful
240
- Skipped: Y (no draft/)
241
- Failed: Z errors
242
-
243
- Grand Total Bugs:
244
- Critical: W
245
- High: X
246
- Medium: Y
247
- Low: Z
248
-
249
- Summary Report: draft/bughunt-summary.md
250
-
251
- Directories requiring immediate attention:
252
- - services/billing/ (1 CRITICAL)
253
- - services/auth/ (2 HIGH)
254
-
255
- ---
256
- ```
257
-
258
- **STOP HERE** if bughunt mode. Do not continue to Step 2 (normal indexing flow).
259
-
260
- ## Step 2: Discover Services (Depth=1 Only)
261
-
262
- Scan immediate child directories for service markers. Do NOT recurse beyond depth=1.
263
-
264
- **Service detection markers (any of these):**
265
- - `package.json` (Node.js)
266
- - `go.mod` (Go)
267
- - `Cargo.toml` (Rust)
268
- - `pom.xml` or `build.gradle` (Java)
269
- - `pyproject.toml` or `requirements.txt` (Python)
270
- - `Dockerfile` (containerized service)
271
- - `src/` directory with code files
272
-
273
- **Exclude patterns:**
274
- - `node_modules/`
275
- - `vendor/`
276
- - `.git/`
277
- - `draft/` (the root draft directory itself)
278
- - Any directory starting with `.`
279
-
280
- ```bash
281
- # Example discovery (adapt to actual structure)
282
- ls -d */ | head -50
283
- ```
284
-
285
- **Output:** List of detected service directories.
286
-
287
- ## Step 3: Categorize Services
288
-
289
- For each detected service directory, check for `draft/` subdirectory:
290
-
291
- ```bash
292
- # For each service
293
- ls <service>/draft/ 2>/dev/null
294
- ```
295
-
296
- Categorize into:
297
- - **Initialized:** Has `draft/` with context files
298
- - **Uninitialized:** No `draft/` directory
299
-
300
- Report:
301
- ```
302
- Scanning immediate child directories...
303
-
304
- Detected X service directories:
305
- ✓ Y initialized (draft/ found)
306
- ○ Z uninitialized
307
-
308
- Initialized services:
309
- - services/auth/
310
- - services/billing/
311
- - ...
312
-
313
- Uninitialized services:
314
- - services/legacy-reports/
315
- - services/admin-tools/
316
- - ...
317
- ```
318
-
319
- ## Step 4: Handle Uninitialized Services
320
-
321
- **If `init-missing` argument is present:**
322
- 1. For each uninitialized service, prompt:
323
- ```
324
- Initialize <service-name>/? [y/n/all/skip-rest]
325
- ```
326
- 2. If user selects:
327
- - `y`: Run `/draft:init` in that directory
328
- - `n`: Skip this service
329
- - `all`: Initialize all remaining without prompting
330
- - `skip-rest`: Skip all remaining uninitialized services
331
-
332
- **If `init-missing` argument is NOT present:**
333
- - Just report uninitialized services and continue
334
- - Suggest: "Run `/draft:index --init-missing` to initialize these services"
335
-
336
- ## Step 5: Aggregate Context from Initialized Services
337
-
338
- For each initialized service, read and extract:
339
-
340
- ### 5.1 From `<service>/draft/product.md`:
341
- - Service name
342
- - First paragraph of Vision (summary)
343
- - Target users (list)
344
- - Core features (list)
345
-
346
- ### 5.2 From `<service>/draft/.ai-context.md` (or legacy `<service>/draft/architecture.md`):
347
- - Key Takeaway paragraph (from `## System Overview`)
348
- - External dependencies (from `## External Dependencies`)
349
- - Exposed APIs or entry points (from `## Entry Points`)
350
- - Dependencies on other services (look for references to sibling service names)
351
- - Critical invariants summary (from `## Critical Invariants`, if available)
352
-
353
- ### 5.3 From `<service>/draft/tech-stack.md`:
354
- - Primary language/framework
355
- - Database
356
- - Key dependencies
357
-
358
- ### 5.4 Create/Update `<service>/draft/manifest.json`:
359
- ```json
360
- {
361
- "name": "<service-name>",
362
- "type": "service",
363
- "summary": "<first line of product vision>",
364
- "primaryTech": "<main language/framework>",
365
- "dependencies": ["<other-service-names>", "<external-deps>"],
366
- "dependents": [],
367
- "team": "<if found in docs>",
368
- "initialized": "<date>",
369
- "lastIndexed": "<current-date>"
370
- }
371
- ```
372
-
373
- ## Step 6: Detect Inter-Service Dependencies
374
-
375
- Analyze extracted data to build dependency graph:
376
-
377
- 1. Look for service name references in each service's architecture.md
378
- 2. Look for API client imports or service URLs in tech-stack.md
379
- 3. Look for mentions in product.md that reference other services
380
- 4. **Graph-enriched detection** (if individual services have `draft/graph/` directories):
381
- - Read each service's `draft/graph/architecture.json` `.routes` to map which service defines vs consumes which endpoints
382
- - Cross-reference proto consumers with proto producers to build precise inter-service dependency edges
383
- - Read `draft/graph/architecture.json` (`.packages`) per service for internal module structure
384
- - This provides deterministic, code-level dependency data that supplements the heuristic name-matching above
385
-
386
- Build a dependency map:
387
- ```
388
- auth-service: [] # no dependencies on other services
389
- billing-service: [auth-service]
390
- api-gateway: [auth-service, billing-service]
391
- ```
392
-
393
- ### Step 6.1b: Cycle Detection
394
-
395
- **Cycle detection:** Walk the dependency graph depth-first from each service. If a cycle is detected (service A depends on B depends on ... depends on A), emit a `> WARNING: Circular dependency detected: A → B → ... → A` line in `dependency-graph.md`, mark the back-edge with `circular: true` in `manifest.json`'s dependency entry, and continue processing. Do not fail on cycles — report and proceed.
396
-
397
- ### Step 6.2: Resolve Dependents (Reverse Lookup)
398
-
399
- For each service S, iterate all other services' `dependencies` arrays. If S appears in another service's dependencies, add that service to S's `dependents` array. Write the updated `manifest.json` for each service.
400
-
401
- ## Step 7: Generate Root Aggregated Files
402
-
403
- ### 7.1 Generate `draft/service-index.md`
404
-
405
- Use the following inline template:
406
-
407
- ```markdown
408
- # Service Index
409
-
410
- > Auto-generated by `/draft:index` on <date>. Do not edit directly.
411
- > Re-run `/draft:index` to update.
412
-
413
- ## Overview
414
-
415
- | Metric | Count |
416
- |--------|-------|
417
- | Total Services Detected | X |
418
- | Initialized | Y |
419
- | Uninitialized | Z |
420
-
421
- ## Service Registry
422
-
423
- | Service | Status | Tech Stack | Dependencies | Team | Details |
424
- |---------|--------|------------|--------------|------|---------|
425
- | auth | ✓ | Go, Postgres | - | @auth-team | [→](../services/auth/draft/.ai-context.md) |
426
- | billing | ✓ | Node, Stripe | auth | @billing | [→](../services/billing/draft/.ai-context.md) |
427
- | legacy-reports | ○ | - | - | - | Not initialized |
428
-
429
- ## Uninitialized Services
430
-
431
- The following services have not been initialized with `/draft:init`:
432
- - `services/legacy-reports/`
433
- - `services/admin-tools/`
434
-
435
- Run `/draft:index --init-missing` or initialize individually with:
436
- ```bash
437
- cd services/legacy-reports && /draft:init
438
- ```
439
- ```
440
-
441
- ### 7.2 Generate `draft/dependency-graph.md`
442
-
443
- ```markdown
444
- # Service Dependency Graph
445
-
446
- > Auto-generated by `/draft:index` on <date>. Do not edit directly.
447
-
448
- ## System Topology
449
-
450
- ```mermaid
451
- graph LR
452
- subgraph "Core Services"
453
- auth[auth-service]
454
- billing[billing-service]
455
- users[user-service]
456
- end
457
-
458
- subgraph "Edge"
459
- gateway[api-gateway]
460
- end
461
-
462
- subgraph "Background"
463
- notifications[notification-service]
464
- reports[report-service]
465
- end
466
-
467
- gateway --> auth
468
- gateway --> billing
469
- gateway --> users
470
- billing --> auth
471
- notifications --> users
472
- reports --> billing
473
- ```
474
-
475
- ## Dependency Matrix
476
-
477
- | Service | Depends On | Depended By |
478
- |---------|-----------|-------------|
479
- | auth-service | - | billing, gateway, users |
480
- | billing-service | auth | gateway, reports |
481
- | user-service | auth | gateway, notifications |
482
- | api-gateway | auth, billing, users | - |
483
-
484
- ## Dependency Order (Topological)
485
-
486
- 1. **auth-service** (foundational - no internal dependencies)
487
- 2. **user-service** (depends on: auth)
488
- 3. **billing-service** (depends on: auth)
489
- 4. **notification-service** (depends on: users)
490
- 5. **report-service** (depends on: billing)
491
- 6. **api-gateway** (depends on: auth, billing, users)
492
-
493
- > This ordering helps when planning cross-service changes or understanding impact.
494
- ```
495
-
496
- ### 7.3 Generate `draft/tech-matrix.md`
497
-
498
- ```markdown
499
- # Technology Matrix
500
-
501
- > Auto-generated by `/draft:index` on <date>. Do not edit directly.
502
-
503
- ## Common Stack (Org Standards)
504
-
505
- Technologies used by majority of services:
506
-
507
- | Technology | Usage | Services |
508
- |------------|-------|----------|
509
- | PostgreSQL | Database | auth, billing, users (85%) |
510
- | Redis | Caching | auth, gateway, notifications (60%) |
511
- | Docker | Containerization | all (100%) |
512
- | GitHub Actions | CI/CD | all (100%) |
513
-
514
- ## Technology Distribution
515
-
516
- ### Languages
517
-
518
- | Language | Services | Percentage |
519
- |----------|----------|------------|
520
- | Go | auth, users, gateway | 45% |
521
- | TypeScript | billing, notifications, reports | 45% |
522
- | Python | ml-service, analytics | 10% |
523
-
524
- ### Databases
525
-
526
- | Database | Services |
527
- |----------|----------|
528
- | PostgreSQL | auth, billing, users, reports |
529
- | MongoDB | notifications, analytics |
530
- | Redis | auth, gateway (cache only) |
531
-
532
- ## Variance Report
533
-
534
- Services deviating from org standards:
535
-
536
- | Service | Deviation | Reason |
537
- |---------|-----------|--------|
538
- | ml-service | Python instead of Go/TS | ML ecosystem |
539
- | analytics | MongoDB instead of Postgres | Time-series workload |
540
- ```
541
-
542
- ### Placeholder Detection
543
-
544
- A file is considered a placeholder if it contains the marker `<!-- AUTO-GENERATED -->` or is smaller than 100 bytes. Placeholders may be overwritten without confirmation. Non-placeholder files require user confirmation before overwriting.
545
-
546
- ### 7.4 Synthesize `draft/product.md` (if not exists or is placeholder)
547
-
548
- Read all service product.md files and synthesize:
549
-
550
- ```markdown
551
- # Product: [Org/Product Name]
552
-
553
- > Synthesized from X service contexts by `/draft:index` on <date>.
554
- > Edit this file to refine the overall product vision.
555
-
556
- ## Vision
557
-
558
- [Synthesized from common themes across service visions - one paragraph describing what the overall product/platform does]
559
-
560
- ## Target Users
561
-
562
- <!-- Aggregated from all services, deduplicated -->
563
- - **End Users**: [common user types across services]
564
- - **Developers**: [if developer-facing APIs exist]
565
- - **Operators**: [if ops/admin services exist]
566
-
567
- ## Service Capabilities
568
-
569
- | Capability | Provided By | Description |
570
- |------------|-------------|-------------|
571
- | Authentication | auth-service | User identity, JWT, OAuth |
572
- | Payments | billing-service | Stripe integration, invoicing |
573
- | API Access | api-gateway | Rate limiting, routing |
574
-
575
- ## Cross-Cutting Concerns
576
-
577
- <!-- Extracted from common patterns across services -->
578
- - **Authentication**: All services validate via auth-service
579
- - **Observability**: [common logging/tracing approach]
580
- - **Data Privacy**: [common compliance patterns]
581
- ```
582
-
583
- ### 7.5 Synthesize `draft/architecture.md` (if not exists or is placeholder)
584
-
585
- ```markdown
586
- # Architecture: [Org/Product Name]
587
-
588
- > Synthesized from X service contexts by `/draft:index` on <date>.
589
- > This is a system-of-systems view. For service internals, see individual service contexts.
590
-
591
- ## System Overview
592
-
593
- **Key Takeaway:** [One paragraph synthesizing overall system purpose from service summaries]
594
-
595
- ### System Topology
596
-
597
- ```mermaid
598
- graph TD
599
- subgraph "External"
600
- Users[Users/Clients]
601
- ThirdParty[Third-Party Services]
602
- end
603
-
604
- subgraph "Edge Layer"
605
- Gateway[API Gateway]
606
- CDN[CDN/Static]
607
- end
608
-
609
- subgraph "Core Services"
610
- Auth[Auth Service]
611
- Billing[Billing Service]
612
- Users2[User Service]
613
- end
614
-
615
- subgraph "Background"
616
- Notifications[Notifications]
617
- Reports[Reports]
618
- end
619
-
620
- subgraph "Data Layer"
621
- Postgres[(PostgreSQL)]
622
- Redis[(Redis)]
623
- Queue[Message Queue]
624
- end
625
-
626
- Users --> Gateway
627
- Gateway --> Auth
628
- Gateway --> Billing
629
- Gateway --> Users2
630
- Billing --> ThirdParty
631
- Auth --> Postgres
632
- Billing --> Postgres
633
- Notifications --> Queue
634
- Reports --> Queue
635
- ```
636
-
637
- ## Service Directory
638
-
639
- | Service | Responsibility | Tech | Status | Details |
640
- |---------|---------------|------|--------|---------|
641
- | auth-service | Identity & access management | Go, Postgres | ✓ Active | [→ context](../services/auth/draft/.ai-context.md) |
642
- | billing-service | Payments & invoicing | Node, Stripe | ✓ Active | [→ context](../services/billing/draft/.ai-context.md) |
643
-
644
- ## Shared Infrastructure
645
-
646
- <!-- Extracted from common external dependencies -->
647
-
648
- | Component | Purpose | Used By |
649
- |-----------|---------|---------|
650
- | PostgreSQL | Primary datastore | auth, billing, users |
651
- | Redis | Caching, sessions | auth, gateway |
652
- | RabbitMQ | Async messaging | notifications, reports |
653
- | Stripe | Payment processing | billing |
654
-
655
- ## Cross-Service Patterns
656
-
657
- <!-- Extracted from common conventions -->
658
-
659
- | Pattern | Description | Services |
660
- |---------|-------------|----------|
661
- | JWT Auth | All services validate JWT via auth-service | all |
662
- | Event-Driven | Async events via message queue | notifications, reports |
663
-
664
- ## Notes
665
-
666
- - For detailed service architecture, navigate to individual service contexts
667
- - This file is regenerable via `/draft:index`
668
- - Manual edits to non-synthesized sections will be preserved on re-index
669
- ```
670
-
671
- ### 7.6 Synthesize `draft/tech-stack.md` (if not exists or is placeholder)
672
-
673
- ```markdown
674
- # Tech Stack: [Org/Product Name]
675
-
676
- > Synthesized from X service contexts by `/draft:index` on <date>.
677
- > This defines org-wide standards. Service-specific additions are in their local tech-stack.md.
678
-
679
- ## Org Standards
680
-
681
- ### Languages
682
- - **Primary**: [most common language] — [X% of services]
683
- - **Secondary**: [second most common] — [Y% of services]
684
-
685
- ### Frameworks
686
- - **API**: [common API framework]
687
- - **Testing**: [common test framework]
688
-
689
- ### Infrastructure
690
- - **Database**: PostgreSQL (standard), MongoDB (approved for specific use cases)
691
- - **Caching**: Redis
692
- - **Messaging**: RabbitMQ / SQS
693
- - **Container**: Docker
694
- - **Orchestration**: Kubernetes
695
-
696
- ### CI/CD
697
- - **Platform**: GitHub Actions
698
- - **Registry**: [container registry]
699
-
700
- ## Approved Variances
701
-
702
- | Service | Variance | Justification |
703
- |---------|----------|---------------|
704
- | ml-service | Python | ML ecosystem requirements |
705
- | analytics | MongoDB | Time-series workload |
706
-
707
- ## Shared Libraries
708
-
709
- | Library | Purpose | Version | Used By |
710
- |---------|---------|---------|---------|
711
- | @org/auth-client | Auth service client | 2.x | billing, gateway, notifications |
712
- | @org/logging | Structured logging | 1.x | all services |
713
- ```
714
-
715
- ### 7.7 Synthesize `draft/.ai-context.md` (if not exists or is placeholder)
716
-
717
- After generating `draft/architecture.md`, derive a condensed `draft/.ai-context.md` using the Condensation Subroutine (as defined in `core/shared/condensation.md`). This provides a token-optimized, self-contained AI context file at the root level aggregating all service knowledge.
718
-
719
- - Read the synthesized `draft/architecture.md`
720
- - Condense into 200-400 lines covering: system overview, service catalog, inter-service dependencies, shared infrastructure, cross-cutting patterns, critical invariants, and entry points
721
- - If `draft/.ai-context.md` already exists and is not a placeholder, prompt before overwriting
722
-
723
- ## Step 8: Create Root Config
724
-
725
- Create `draft/config.yaml` if not exists:
726
-
727
- ```yaml
728
- # Draft Index Configuration
729
-
730
- # Service detection patterns (immediate children only)
731
- service_patterns:
732
- - "package.json"
733
- - "go.mod"
734
- - "Cargo.toml"
735
- - "pom.xml"
736
- - "build.gradle"
737
- - "pyproject.toml"
738
- - "requirements.txt"
739
- - "Dockerfile"
740
-
741
- # Directories to exclude from scanning
742
- exclude_patterns:
743
- - "node_modules"
744
- - "vendor"
745
- - ".git"
746
- - "draft"
747
- - ".*" # Hidden directories
748
-
749
- # Re-index on these events (for CI integration)
750
- reindex_triggers:
751
- - "service added"
752
- - "service removed"
753
- - "weekly"
754
- ```
755
-
756
- ## Step 8.5: Refresh Graph Injection Slots
757
-
758
- For each initialized service with both `draft/architecture.md` AND `draft/graph/schema.yaml`:
759
-
760
- **A. Read current `architecture.md` into memory.**
761
-
762
- **B. Regenerate slot content from graph JSONL:**
763
- - `GRAPH:module-deps` → run `scripts/tools/mermaid-from-graph.sh --repo . --diagram module-deps`
764
- Parse JSON response, extract `.mermaid` string + `filtered` flag + stats
765
- - `GRAPH:proto-map` → run `scripts/tools/mermaid-from-graph.sh --repo . --diagram proto-map`
766
- Parse JSON response, extract `.mermaid` string + stats
767
- - `GRAPH:hotspots` → read `draft/graph/hotspots.jsonl`, build top-10 markdown table:
768
- `| File | Lines | fanIn | Score |` with one row per hotspot, ordered by score descending
769
-
770
- **C. For each slot, find `<!-- GRAPH:{id}:START -->` ... `<!-- GRAPH:{id}:END -->` markers.**
771
- Replace entire block (inclusive of markers) with regenerated content.
772
- If a marker pair is absent (legacy file): insert slot at the designated position and log:
773
- `"Injected GRAPH:{id} slot into architecture.md (slot was absent — legacy file upgraded)"`
774
-
775
- **D. Write updated `architecture.md` back to disk.**
776
- Update frontmatter: `generated_by = "draft:index"`, `generated_at = now`. Also update `draft/metadata.json` via `git-metadata.sh --project-metadata --generated-by "draft:index"` to re-anchor `synced_to_commit`.
777
-
778
- **E. Re-run Condensation Subroutine** (condensation.md) to propagate updated hotspot data into `.ai-context.md` GRAPH:HOTSPOTS and recompute tier budget. If `.ai-profile.md` exists, regenerate via Profile Generation Subroutine.
779
-
780
- **F. Report per service:**
781
- ```
782
- ✓ <service>: refreshed 3 graph slots (module-deps, proto-map, hotspots)
783
- ✓ <service>: regenerated .ai-context.md (tier N, {lines} lines)
784
- ```
785
-
786
- ## Step 9: Completion Report
787
-
788
- Remove the lockfile:
789
-
790
- ```bash
791
- rm -f draft/.index-lock
792
- ```
793
-
794
- ```
795
- ---
796
- DRAFT INDEX COMPLETE
797
- ---
798
- Scanned: X service directories (depth=1)
799
- Indexed: Y services with draft/ context
800
- Skipped: Z uninitialized services
801
-
802
- Generated/Updated:
803
- ✓ draft/service-index.md (service registry)
804
- ✓ draft/dependency-graph.md (inter-service topology)
805
- ✓ draft/tech-matrix.md (technology distribution)
806
- ✓ draft/product.md (synthesized product vision)
807
- ✓ draft/architecture.md (system-of-systems view)
808
- ✓ draft/tech-stack.md (org standards)
809
- ✓ draft/config.yaml (index configuration)
810
-
811
- Service manifests updated: Y services
812
-
813
- Next steps:
814
- 1. Review synthesized files in draft/
815
- 2. Edit draft/product.md to refine overall vision
816
- 3. Edit draft/architecture.md to add cross-cutting context
817
- 4. Run /draft:index periodically to refresh
818
-
819
- For uninitialized services, run:
820
- /draft:index init-missing
821
- ---
822
- ```
823
-
824
- ## Operational Notes
825
-
826
- ### What This Command Does NOT Do
827
-
828
- - **No deep code analysis** — Reads only existing `draft/*.md` files
829
- - **No source code scanning** — That's `/draft:init`'s job per service
830
- - **No recursive scanning** — Depth=1 only, immediate children
831
- - **No duplication** — Root files link to service files, not copy content
832
-
833
- ### When to Re-Run
834
-
835
- - After running `/draft:init` on a new service
836
- - After significant changes to service architectures
837
- - Weekly/monthly as part of documentation hygiene
838
- - Before major cross-service planning
839
-
840
- ### Preserving Manual Edits
841
-
842
- When regenerating, the skill:
843
- 1. Reads existing root files
844
- 2. Identifies manually-added sections (not marked as auto-generated)
845
- 3. Preserves those sections while updating auto-generated parts
846
- 4. Sections between `<!-- MANUAL START -->` and `<!-- MANUAL END -->` are never overwritten
847
-
848
- **Graph injection slots** (`<!-- GRAPH:...:START -->` / `<!-- GRAPH:...:END -->`) are ALWAYS overwritten during refresh — they are auto-managed. Never place manual content between these markers. Use `<!-- MANUAL START -->` / `<!-- MANUAL END -->` for content you want preserved near a slot.