@drafthq/draft 2.8.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +9 -3
  4. package/bin/README.md +13 -0
  5. package/cli/src/installer.js +11 -2
  6. package/core/methodology.md +17 -18
  7. package/core/shared/condensation.md +1 -1
  8. package/core/shared/draft-context-loading.md +4 -2
  9. package/core/shared/graph-query.md +4 -3
  10. package/core/templates/ai-context.md +1 -0
  11. package/core/templates/ai-profile.md +1 -0
  12. package/core/templates/architecture.md +1 -0
  13. package/core/templates/dependency-graph.md +2 -2
  14. package/core/templates/discovery.md +1 -0
  15. package/core/templates/guardrails.md +1 -0
  16. package/core/templates/hld.md +1 -0
  17. package/core/templates/lld.md +1 -0
  18. package/core/templates/plan.md +1 -0
  19. package/core/templates/product.md +1 -0
  20. package/core/templates/rca.md +1 -0
  21. package/core/templates/root-architecture.md +3 -3
  22. package/core/templates/root-product.md +2 -2
  23. package/core/templates/root-tech-stack.md +2 -2
  24. package/core/templates/service-index.md +3 -3
  25. package/core/templates/spec.md +1 -0
  26. package/core/templates/tech-matrix.md +2 -2
  27. package/core/templates/tech-stack.md +1 -0
  28. package/core/templates/workflow.md +1 -0
  29. package/integrations/agents/AGENTS.md +134 -918
  30. package/integrations/copilot/.github/copilot-instructions.md +134 -918
  31. package/integrations/copilot/.github/copilot-instructions.md.7iDz8X +91 -0
  32. package/integrations/copilot/.github/copilot-instructions.md.DoBdtd +91 -0
  33. package/integrations/copilot/.github/copilot-instructions.md.McGoBW +122 -0
  34. package/integrations/copilot/.github/copilot-instructions.md.VsPyLB +91 -0
  35. package/integrations/copilot/.github/copilot-instructions.md.XAVr7D +91 -0
  36. package/integrations/copilot/.github/copilot-instructions.md.YoFVFa +91 -0
  37. package/integrations/copilot/.github/copilot-instructions.md.a9DeW0 +91 -0
  38. package/integrations/copilot/.github/copilot-instructions.md.oxQs3B +91 -0
  39. package/integrations/copilot/.github/copilot-instructions.md.ww33Ly +91 -0
  40. package/package.json +1 -1
  41. package/scripts/lib.sh +4 -1
  42. package/scripts/tools/graph-init.sh +187 -0
  43. package/scripts/tools/graph-snapshot.sh +6 -1
  44. package/scripts/tools/okf-bundle.sh +141 -0
  45. package/scripts/tools/okf-check.sh +137 -0
  46. package/scripts/tools/okf-emit.sh +161 -0
  47. package/scripts/tools/skill-caps.conf +0 -1
  48. package/skills/GRAPH.md +7 -10
  49. package/skills/bughunt/SKILL.md +13 -0
  50. package/skills/discover/SKILL.md +2 -4
  51. package/skills/draft/SKILL.md +2 -2
  52. package/skills/draft/intent-mapping.md +3 -2
  53. package/skills/graph/SKILL.md +3 -3
  54. package/skills/init/SKILL.md +58 -19
  55. package/skills/init/references/architecture-spec.md +5 -5
  56. package/skills/index/SKILL.md +0 -848
@@ -31,7 +31,7 @@ When `draft/` exists in the project, always consider:
31
31
  | Command | Purpose |
32
32
  |---------|---------|
33
33
  | `draft` | Show overview and available commands |
34
- | `draft init` | Initialize project (run once) |
34
+ | `draft init [refresh] [--graph-only] [--module-only]` | Initialize project context + code-graph memory; scope-aware (root or sub-module) |
35
35
  | `draft new-track <description>` | Create feature/bug track |
36
36
  | `draft implement` | Execute tasks from plan |
37
37
  | `draft review [--track <id>]` | Three-stage code review |
@@ -57,7 +57,6 @@ When `draft/` exists in the project, always consider:
57
57
  | `draft status` | Show progress overview |
58
58
  | `draft revert` | Git-aware rollback |
59
59
  | `draft change <description>` | Handle mid-track requirement changes |
60
- | `draft index [--init-missing]` | Aggregate monorepo service contexts |
61
60
  | `draft tour` | Interactive onboarding tour |
62
61
  | `draft impact` | Telemetry and analytics insights |
63
62
  | `draft assist-review` | Assist human reviewers with architectural risk audit |
@@ -124,7 +123,7 @@ Recognize and use these throughout plan.md:
124
123
 
125
124
  ## Init Command
126
125
 
127
- When user says "init draft" or "draft init [refresh]":
126
+ When user says "init draft", "build the code graph", or "draft init [refresh] [--graph-only] [--module-only]":
128
127
 
129
128
  Initialize a Draft project for Context-Driven Development.
130
129
 
@@ -314,18 +313,24 @@ synced_to_commit: "a1b2c3d4e5f6789012345678901234567890abcd"
314
313
 
315
314
  Check for arguments:
316
315
  - `refresh`: Update existing context without full re-init
317
- - `index`: Route to `draft index`
316
+ - `--graph-only`: Build/refresh only the code-graph knowledge memory (no markdown) — see the fast path below
317
+ - `--module-only`: When run in a sub-module, do not touch the root graph (the module→root link is marked `pending`)
318
318
  - `discover`: Route to `draft discover`
319
319
 
320
+ > `draft init` is the **single entry point** for building context — there is no separate `index` command. Init is scope-aware (root vs sub-module); see **Scope Detection** below.
321
+
320
322
  ### Route Explicit Modes Before Initialization
321
323
 
322
324
  If the user explicitly invoked a specialist mode, route directly:
323
325
 
324
- - `draft init index` → follow `draft index`
325
326
  - `draft init discover` → follow `draft discover`
326
327
 
327
328
  Explicit mode always wins. Do not perform standard initialization if an explicit mode is requested.
328
329
 
330
+ ### `--graph-only` Fast Path
331
+
332
+ If `--graph-only` is present, run **Step 1.4** (scope-aware, root-first graph build via `graph-init.sh`) and **STOP** — generate no `architecture.md` or other markdown. This is the fast path to (re)build the whole-repo code-graph knowledge memory; in a sub-module it also ensures the root spine exists and writes the module→root link. This path is allowed even when `draft/` already exists (it refreshes the graph in place — no `draft.tmp/` staging, no overwrite prompt).
333
+
329
334
  ### Standard Init Check
330
335
 
331
336
  ```bash
@@ -357,16 +362,16 @@ mv draft.tmp/ draft/
357
362
 
358
363
  > **Forced re-init:** If `draft/` exists and the user explicitly requests a fresh init (not refresh), confirm with user before removing the existing `draft/` directory.
359
364
 
360
- ### Monorepo Detection
365
+ ### Scope Detection (root vs sub-module)
366
+
367
+ `draft init` is the single entry point and is **scope-aware** — it works the same whether run at the repository root or inside a sub-module. The root-first graph behavior is handled mechanically by `graph-init.sh` in Step 1.4; you do not detect the monorepo shape by hand.
361
368
 
362
- Check for monorepo indicators:
363
- - Multiple `package.json` / `go.mod` / `Cargo.toml` in child directories
364
- - `lerna.json`, `pnpm-workspace.yaml`, `nx.json`, or `turbo.json` at root
365
- - `packages/`, `apps/`, `services/` directories with independent manifests
369
+ Resolve **ROOT** = nearest ancestor (above the current dir) containing `draft/` → else the git toplevel → else the current dir. Then:
366
370
 
367
- If monorepo detected:
368
- - Announce: "Detected monorepo structure. Consider using `draft init index` at root level to aggregate service context, or run `draft init` within individual service directories."
369
- - Ask user to confirm: initialize here (single service) or abort (use draft init index instead)
371
+ - **Root init** (current dir IS root): the graph step builds the whole-repo spine. The generated markdown is a **sparse, high-level system map** that links *down* to each module's context — a large root must not carry deep per-module prose. (See "Root vs Module Markdown" below.)
372
+ - **Module init** (current dir is BELOW root): the graph step ensures the root spine exists first (building it if missing), builds the module snapshot, and writes `draft/graph/root-link.json` (module→root). The generated markdown is the **detailed** module reference produced by the standard deep analysis in this skill.
373
+
374
+ Use `--module-only` to skip touching the root (the link is marked `pending` and resolves when root init later runs). With no git and no ancestor `draft/`, init treats the current dir as root (module-local, no traversal).
370
375
 
371
376
  ### Migration Detection
372
377
 
@@ -599,20 +604,25 @@ If **Greenfield**: skip to Step 2 (Product Definition).
599
604
 
600
605
  **CRITICAL ORDERING**: Phase 0 (this step) MUST complete before writing any section of architecture.md. The graph provides: (a) exhaustive module list, (b) hotspot-ranked module priority, (c) authoritative proto API surface, (d) mermaid diagrams ready for slot injection, (e) codebase tier for .ai-context.md budget.
601
606
 
602
- ### 1. Build the graph snapshot
607
+ ### 1. Build the graph (scope-aware, root-first)
603
608
 
604
- The knowledge-graph engine is `codebase-memory-mcp`, resolved by `scripts/tools/_lib.sh:find_memory_bin` (`DRAFT_MEMORY_BIN` > PATH > `~/.cache/draft/bin` > vendored `bin/<arch>/`). `draft install` fetches it (skip with `--no-graph`); install manually with `scripts/fetch-memory-engine.sh`. Set `DRAFT_MEMORY_DISABLE=1` to opt out.
609
+ The knowledge-graph engine `codebase-memory-mcp` is Draft's **default** capability tier — deterministic call/dependency traversal beats grep/glob. It is normally already installed by `draft install`; `graph-init.sh` fetches it as a fallback when missing (blocking — download/index time is accepted, never gated on cost). Resolution: `scripts/tools/_lib.sh:find_memory_bin` (`DRAFT_MEMORY_BIN` > PATH > `~/.cache/draft/bin` > vendored `bin/<arch>/`). Set `DRAFT_MEMORY_DISABLE=1` to opt out.
605
610
 
606
- One command resolves the engine, indexes the repo, and writes the committed snapshot under `draft/graph/`:
611
+ One command resolves ROOT, ensures the engine, builds the whole-repo spine, and in a sub-module — builds the module snapshot and writes the `root-link.json` pointer:
607
612
 
608
613
  ```bash
609
- if scripts/tools/graph-snapshot.sh --repo .; then
610
- echo "Graph snapshot written to draft/graph/ (schema.yaml, architecture.json, hotspots.jsonl, *.mermaid)."
614
+ # Add --module-only to skip touching the root (link marked "pending").
615
+ if scripts/tools/graph-init.sh --scope .; then
616
+ echo "Graph memory ready under draft/graph/ (the root spine is the structural source of truth)."
611
617
  else
612
- echo "Graph engine unavailable — skipping automated graph analysis. Downstream skills degrade gracefully."
618
+ echo "Graph engine unavailable — proceeding with degraded manual discovery. Downstream skills degrade gracefully."
613
619
  fi
614
620
  ```
615
621
 
622
+ - **Root init** writes `<root>/draft/graph/` — the committed, git-tracked whole-repo memory.
623
+ - **Module init** also writes `draft/graph/root-link.json` (module→root); follow `root_graph` for cross-module understanding. The root spine is rebuilt first so the link is live.
624
+ - Only `draft/graph/` is committed. The engine's `~/.cache` index is a disposable accelerator — never commit it; it rebuilds deterministically from source.
625
+
616
626
  Optionally record which engine was selected (usage-report contract):
617
627
 
618
628
  ```bash
@@ -621,7 +631,7 @@ scripts/tools/verify-graph-binary.sh --repo . --json 2>/dev/null || true
621
631
 
622
632
  See `core/shared/graph-query.md` and `bin/README.md` for the query contract and engine resolution.
623
633
 
624
- If the snapshot succeeds, `draft/graph/` is populated and later steps consume the always-load artifacts + injection slots.
634
+ If the build succeeds, `draft/graph/` is populated and later steps consume the always-load artifacts + injection slots.
625
635
 
626
636
  ### 2. If graph build succeeds, load the always-load artifacts
627
637
 
@@ -1129,11 +1139,19 @@ The document is:
1129
1139
 
1130
1140
  **Full details, per-section guidance, provenance rules, and examples** live in:
1131
1141
  - `core/templates/architecture.md` (the source of truth for the 10 sections + Generation Contract)
1132
- - `docs/research/proposed-graph-backed-architecture-template.md` (design rationale and fidelity rules)
1133
1142
  - `references/architecture-spec.md` (deprecated legacy notes — **10-section template wins on any conflict**)
1134
1143
 
1135
1144
  There is no legacy 28-section structure and no volume targets. The template itself is the contract.
1136
1145
 
1146
+ ### Root vs Module Markdown (scope asymmetry)
1147
+
1148
+ The depth of generated markdown depends on the scope resolved in **Scope Detection**:
1149
+
1150
+ - **Module init** (current dir below root): generate the **full, detailed** 10-section `architecture.md` for the module subtree — the standard deep analysis described in this skill. This is where engineering depth lives.
1151
+ - **Root init** (current dir IS root, monorepo): generate a **sparse, high-level system map**, not deep per-module prose. The root `architecture.md` covers: system overview + Graph Health Dashboard (from the whole-repo spine), the module catalog with one-line responsibilities and links *down* to each module's `draft/.ai-context.md`, cross-module dependency topology (from `draft/graph/`), shared infrastructure, and system-wide invariants. Defer module internals to the module docs — a large root must not duplicate them. If a module has not been initialized, link it as "not yet initialized — run `draft init` there."
1152
+
1153
+ The graph is symmetric (root spine + per-module snapshots, linked); only the **prose** is asymmetric. Both consume `draft/graph/`.
1154
+
1137
1155
  **After completing analysis AND passing verification**, write to `draft/architecture.md`. This is the PRIMARY output. Then run the Condensation Subroutine.
1138
1156
 
1139
1157
  ## .ai-context.md Specification
@@ -1709,6 +1727,7 @@ Create `draft/tracks.md` with metadata header:
1709
1727
 
1710
1728
  ```markdown
1711
1729
  ---
1730
+ type: TrackIndex
1712
1731
  project: "{PROJECT_NAME}"
1713
1732
  module: "root"
1714
1733
  generated_by: "draft:init"
@@ -1754,6 +1773,23 @@ For **brownfield** projects, run `draft learn` (no arguments — full codebase s
1754
1773
 
1755
1774
  ## Completion
1756
1775
 
1776
+ **Finalize OKF bundle:** After all `draft/` files are written, run the bundle tool
1777
+ to (re)generate the Open Knowledge Format root index so the whole `draft/` tree is
1778
+ a portable, vendor-neutral OKF bundle. This is the default — no flag required.
1779
+
1780
+ ```bash
1781
+ scripts/tools/okf-bundle.sh --dir draft # writes the bundle-root draft/index.md
1782
+ scripts/tools/okf-check.sh --dir draft # OKF v0.1 conformance (advisory, non-fatal)
1783
+ ```
1784
+
1785
+ `okf-bundle.sh` links every concept file present (`.ai-profile.md`, `.ai-context.md`,
1786
+ `architecture.md`, `product.md`, `tech-stack.md`, `workflow.md`, `guardrails.md`), the
1787
+ tracks, and the graph sub-bundle (`graph/okf/`). Concept `type:` frontmatter comes from
1788
+ the templates; `okf-check.sh` validates §9 conformance (frontmatter + `type` on every
1789
+ concept; reserved `index.md`/`log.md` structure). It is advisory — report the result,
1790
+ do not fail init. Note: operational reports later written into `draft/` (e.g.
1791
+ `deep-review-report.md`) are not OKF concepts and will be flagged.
1792
+
1757
1793
  **Finalize run memory:** Update `draft/.state/run-memory.json`:
1758
1794
  - `status`: `"completed"`
1759
1795
  - `completed_at`: current ISO timestamp
@@ -1763,6 +1799,7 @@ For **Brownfield** projects, announce:
1763
1799
  "Draft initialized successfully with comprehensive analysis!
1764
1800
 
1765
1801
  Created:
1802
+ - draft/index.md (Open Knowledge Format bundle root — cross-links every concept)
1766
1803
  - draft/.ai-profile.md (20-50 lines — ultra-compact always-injected profile, Tier 0)
1767
1804
  - draft/.ai-context.md (200-400 lines — token-optimized AI context, self-contained, Tier 1)
1768
1805
  - draft/architecture.md (comprehensive human-readable engineering reference, Tier 2)
@@ -1797,6 +1834,7 @@ For **Greenfield** projects, announce:
1797
1834
  "Draft initialized successfully!
1798
1835
 
1799
1836
  Created:
1837
+ - draft/index.md (Open Knowledge Format bundle root — cross-links every concept)
1800
1838
  - draft/product.md
1801
1839
  - draft/tech-stack.md
1802
1840
  - draft/workflow.md
@@ -2067,14 +2105,14 @@ Write the `GRAPH:module-deps` injection slot into architecture.md:
2067
2105
 
2068
2106
  If graph build succeeded (Step 1.4.7 completed), write the populated slot content using the diagram from Step 1.4.7. If filtered (>30 modules), include the filter note. Dashed edges indicate circular dependencies.
2069
2107
 
2070
- If graph binary was not found: write the slot with placeholder body so draft:index can populate it later:
2108
+ If graph binary was not found: write the slot with placeholder body so draft:init --graph-only can populate it later:
2071
2109
  ```
2072
2110
  <!-- GRAPH:module-deps:START -->
2073
- [Graph data unavailable — run draft:index to populate after graph binary is installed]
2111
+ [Graph data unavailable — run draft:init --graph-only to populate after graph binary is installed]
2074
2112
  <!-- GRAPH:module-deps:END -->
2075
2113
  ```
2076
2114
 
2077
- The slot markers MUST always be written — they are required for draft:index refresh to function.
2115
+ The slot markers MUST always be written — they are required for draft:init --graph-only refresh to function.
2078
2116
 
2079
2117
  #### 4.2 Process Lifecycle (or Usage Lifecycle for libraries)
2080
2118
 
@@ -2984,11 +3022,11 @@ If graph build succeeded and proto files exist (Step 1.4.7 completed), write the
2984
3022
  If graph binary was not found or no proto files exist, write the slot with placeholder:
2985
3023
  ```
2986
3024
  <!-- GRAPH:proto-map:START -->
2987
- [Graph data unavailable — run draft:index to populate after graph binary is installed]
3025
+ [Graph data unavailable — run draft:init --graph-only to populate after graph binary is installed]
2988
3026
  <!-- GRAPH:proto-map:END -->
2989
3027
  ```
2990
3028
 
2991
- The slot markers MUST always be written — they are required for draft:index refresh to function.
3029
+ The slot markers MUST always be written — they are required for draft:init --graph-only refresh to function.
2992
3030
 
2993
3031
  ---
2994
3032
 
@@ -3166,859 +3204,11 @@ Run this checklist before writing architecture.md:
3166
3204
 
3167
3205
  ---
3168
3206
 
3169
- ## Index Command
3170
-
3171
- When user says "index services" or "draft index [--init-missing]":
3172
-
3173
- You are building a federated knowledge index for a monorepo with multiple services.
3174
-
3175
- ## Red Flags - STOP if you're:
3176
-
3177
- - Running at a non-root directory in a monorepo
3178
- - Indexing services that haven't been initialized with `draft init`
3179
- - Overwriting root-level context without confirming with the user
3180
- - Aggregating without verifying each service's draft/ directory exists
3181
- - Skipping dependency mapping between services
3182
-
3183
- **Aggregate from initialized services only. Verify before overwriting.**
3184
-
3185
- ---
3186
-
3187
- ## Standard File Metadata
3188
-
3189
- **ALL generated files MUST include the standard YAML frontmatter.** This enables refresh tracking, sync verification, and traceability.
3190
-
3191
- ### Project Metadata File (single source of truth)
3192
-
3193
- 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.
3194
-
3195
- Use the `--project-metadata` flag (preferred):
3196
-
3197
- ```bash
3198
- DRAFT_TOOLS="${DRAFT_PLUGIN_ROOT:-$HOME/.claude/plugins/draft}/scripts/tools"
3199
- [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$HOME/.cursor/plugins/local/draft/scripts/tools"
3200
- [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$PWD/scripts/tools"
3201
- bash "$DRAFT_TOOLS/git-metadata.sh" --project-metadata \
3202
- --project "$PROJECT" --generated-by "draft:index"
3203
- ```
3204
-
3205
- ### Per-File Metadata Template
3206
-
3207
- 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`):
3208
-
3209
- ```yaml
3210
- ---
3211
- project: "{PROJECT_NAME}"
3212
- module: "root"
3213
- generated_by: "draft:index"
3214
- generated_at: "{ISO_TIMESTAMP}"
3215
- ---
3216
- ```
3217
-
3218
- > **Note**: `generated_by` uses `draft:command` format (not `draft command`) for cross-platform compatibility.
3219
-
3220
- ---
3221
-
3222
- ## Pre-Check
3223
-
3224
- ```bash
3225
- ls draft/ 2>/dev/null
3226
- ```
3227
-
3228
- **If `draft/` does NOT exist at root:**
3229
- - 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."
3230
- - Stop here.
3231
-
3232
- **If `draft/` exists:** Continue to lockfile check.
3233
-
3234
- ## Lockfile Check
3235
-
3236
- Before proceeding, check for a stale lock:
3237
-
3238
- ```bash
3239
- ls draft/.index-lock 2>/dev/null
3240
- ```
3241
-
3242
- - **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.
3243
- - **If `draft/.index-lock` exists and is older than 10 minutes:** Remove it and continue.
3244
- - **If no lock exists:** Continue.
3245
-
3246
- Create `draft/.index-lock` with the current timestamp before starting:
3247
-
3248
- ```bash
3249
- date -u +"%Y-%m-%dT%H:%M:%SZ" > draft/.index-lock
3250
- ```
3251
-
3252
- **On completion (Step 9) or fatal error, remove the lock:**
3253
-
3254
- ```bash
3255
- rm -f draft/.index-lock
3256
- ```
3257
-
3258
- ## Step 1: Parse Arguments
3259
-
3260
- Check for optional arguments:
3261
- - `--init-missing`: Also initialize services that don't have `draft/` directories
3262
- - `bughunt [dir1 dir2 ...]`: Run bug hunt across subdirectories with `draft/` folders
3263
- - If no directories specified: auto-discover all subdirectories with `draft/`
3264
- - If directories specified: run bughunt only in those subdirectories (skip if no `draft/`)
3265
- - Generate summary report at: `draft/bughunt-summary.md`
3266
-
3267
- **If `bughunt` argument detected:** Skip to Step 1A (Bughunt Mode) instead of continuing to Step 2.
3268
-
3269
- ## Step 1A: Bughunt Mode
3270
-
3271
- This mode runs `draft bughunt` across multiple subdirectories and aggregates results.
3272
-
3273
- ### 1A.1: Determine Target Directories
3274
-
3275
- **If directories explicitly specified** (e.g., `bughunt dir1 dir2 dir3`):
3276
- - Use provided directory list as targets
3277
- - Verify each directory exists
3278
- - Check each directory for `draft/` subdirectory
3279
- - Warn and skip any directory without `draft/`
3280
-
3281
- **If no directories specified** (e.g., just `bughunt`):
3282
- - Auto-discover all immediate child directories (depth=1)
3283
- - Filter for directories containing `draft/` subdirectory
3284
- - Exclude patterns: `node_modules/`, `vendor/`, `.git/`, `draft/`, `.*`
3285
-
3286
- ```bash
3287
- # Example auto-discovery
3288
- for dir in */; do
3289
- if [ -d "$dir/draft" ]; then
3290
- echo "$dir"
3291
- fi
3292
- done
3293
- ```
3294
-
3295
- **Output:**
3296
- ```
3297
- Target directories for bughunt:
3298
- - services/auth/
3299
- - services/billing/
3300
- - services/notifications/
3301
- ```
3302
-
3303
- ### 1A.2: Execute Bughunt Per Directory
3304
-
3305
- For each target directory:
3306
-
3307
- 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`:
3308
- ```
3309
- draft bughunt
3310
- → (scope prompt) → "Specific paths"
3311
- → (paths prompt) → <target-dir>
3312
- ```
3313
-
3314
- 2. **Announce:**
3315
- ```
3316
- Running bughunt in <target-dir>...
3317
- ```
3318
-
3319
- 3. **Let `draft bughunt` run its full workflow:**
3320
- - Report will be generated at `<target-dir>/draft/bughunt-report-<timestamp>.md`
3321
- - Capture exit status (success/failure)
3322
-
3323
- 4. **Record results:**
3324
- - Directory path
3325
- - Total bugs found (by severity)
3326
- - Report location
3327
- - Any errors encountered
3328
-
3329
- **Note:** Run bughunts sequentially, not in parallel, to avoid context conflicts.
3330
-
3331
- ### 1A.3: Parse Individual Reports
3332
-
3333
- After all bughunts complete, read each generated report:
3334
-
3335
- ```bash
3336
- # For each target directory
3337
- cat <dir>/draft/bughunt-report-latest.md
3338
- ```
3339
-
3340
- Extract from each report:
3341
- - Branch and commit (from header)
3342
- - Summary table (bug counts by severity)
3343
- - Critical/High issue count
3344
- - Total issues count
3345
-
3346
- ### 1A.4: Generate Aggregate Summary Report
3347
-
3348
- Create `draft/bughunt-summary.md`:
3349
-
3350
- ```markdown
3351
- # Draft Index: Bughunt Summary
3352
-
3353
- **Date:** YYYY-MM-DD HH:MM
3354
- **Mode:** [Auto-discovery | Explicit directories]
3355
- **Directories Scanned:** N
3356
-
3357
- ## Overview
3358
-
3359
- | Directory | Critical | High | Medium | Low | Total | Report |
3360
- |-----------|----------|------|--------|-----|-------|--------|
3361
- | services/auth/ | 0 | 2 | 5 | 3 | 10 | [→](services/auth/draft/bughunt-report.md) |
3362
- | services/billing/ | 1 | 1 | 2 | 1 | 5 | [→](services/billing/draft/bughunt-report.md) |
3363
- | services/notifications/ | 0 | 0 | 1 | 2 | 3 | [→](services/notifications/draft/bughunt-report.md) |
3364
-
3365
- **Grand Total:** X Critical, Y High, Z Medium, W Low
3366
-
3367
- ## Directories With Critical Issues
3368
-
3369
- | Directory | Count | Details |
3370
- |-----------|-------|---------|
3371
- | services/billing/ | 1 | [→](services/billing/draft/bughunt-report.md#critical-issues) |
3372
-
3373
- ## Directories With No Issues
3374
-
3375
- - services/api-gateway/
3376
- - services/user-service/
3377
-
3378
- ## Skipped Directories
3379
-
3380
- | Directory | Reason |
3381
- |-----------|--------|
3382
- | services/legacy-tools/ | No draft/ directory found |
3383
- | services/experiments/ | No draft/ directory found |
3384
-
3385
- ## Next Steps
3386
-
3387
- 1. **Prioritize Critical Issues:** Review directories with Critical bugs first
3388
- 2. **Review Individual Reports:** Click links above to see detailed findings
3389
- 3. **Track Fixes:** Use `draft new-track` to create implementation tracks for fixes
3390
- 4. **Re-run After Fixes:** Run `draft index bughunt` again to verify
3391
-
3392
- ---
3393
-
3394
- *Generated by `draft index bughunt` command*
3395
- ```
3396
-
3397
- ### 1A.5: Completion Report
3398
-
3399
- ```
3400
- ---
3401
- DRAFT INDEX BUGHUNT COMPLETE
3402
- ---
3403
- Scanned: N directories
3404
- Completed: X successful
3405
- Skipped: Y (no draft/)
3406
- Failed: Z errors
3407
-
3408
- Grand Total Bugs:
3409
- Critical: W
3410
- High: X
3411
- Medium: Y
3412
- Low: Z
3413
-
3414
- Summary Report: draft/bughunt-summary.md
3415
-
3416
- Directories requiring immediate attention:
3417
- - services/billing/ (1 CRITICAL)
3418
- - services/auth/ (2 HIGH)
3419
-
3420
- ---
3421
- ```
3422
-
3423
- **STOP HERE** if bughunt mode. Do not continue to Step 2 (normal indexing flow).
3424
-
3425
- ## Step 2: Discover Services (Depth=1 Only)
3426
-
3427
- Scan immediate child directories for service markers. Do NOT recurse beyond depth=1.
3428
-
3429
- **Service detection markers (any of these):**
3430
- - `package.json` (Node.js)
3431
- - `go.mod` (Go)
3432
- - `Cargo.toml` (Rust)
3433
- - `pom.xml` or `build.gradle` (Java)
3434
- - `pyproject.toml` or `requirements.txt` (Python)
3435
- - `Dockerfile` (containerized service)
3436
- - `src/` directory with code files
3437
-
3438
- **Exclude patterns:**
3439
- - `node_modules/`
3440
- - `vendor/`
3441
- - `.git/`
3442
- - `draft/` (the root draft directory itself)
3443
- - Any directory starting with `.`
3444
-
3445
- ```bash
3446
- # Example discovery (adapt to actual structure)
3447
- ls -d */ | head -50
3448
- ```
3449
-
3450
- **Output:** List of detected service directories.
3451
-
3452
- ## Step 3: Categorize Services
3453
-
3454
- For each detected service directory, check for `draft/` subdirectory:
3455
-
3456
- ```bash
3457
- # For each service
3458
- ls <service>/draft/ 2>/dev/null
3459
- ```
3460
-
3461
- Categorize into:
3462
- - **Initialized:** Has `draft/` with context files
3463
- - **Uninitialized:** No `draft/` directory
3464
-
3465
- Report:
3466
- ```
3467
- Scanning immediate child directories...
3468
-
3469
- Detected X service directories:
3470
- ✓ Y initialized (draft/ found)
3471
- ○ Z uninitialized
3472
-
3473
- Initialized services:
3474
- - services/auth/
3475
- - services/billing/
3476
- - ...
3477
-
3478
- Uninitialized services:
3479
- - services/legacy-reports/
3480
- - services/admin-tools/
3481
- - ...
3482
- ```
3483
-
3484
- ## Step 4: Handle Uninitialized Services
3485
-
3486
- **If `init-missing` argument is present:**
3487
- 1. For each uninitialized service, prompt:
3488
- ```
3489
- Initialize <service-name>/? [y/n/all/skip-rest]
3490
- ```
3491
- 2. If user selects:
3492
- - `y`: Run `draft init` in that directory
3493
- - `n`: Skip this service
3494
- - `all`: Initialize all remaining without prompting
3495
- - `skip-rest`: Skip all remaining uninitialized services
3496
-
3497
- **If `init-missing` argument is NOT present:**
3498
- - Just report uninitialized services and continue
3499
- - Suggest: "Run `draft index --init-missing` to initialize these services"
3500
-
3501
- ## Step 5: Aggregate Context from Initialized Services
3502
-
3503
- For each initialized service, read and extract:
3504
-
3505
- ### 5.1 From `<service>/draft/product.md`:
3506
- - Service name
3507
- - First paragraph of Vision (summary)
3508
- - Target users (list)
3509
- - Core features (list)
3510
-
3511
- ### 5.2 From `<service>/draft/.ai-context.md` (or legacy `<service>/draft/architecture.md`):
3512
- - Key Takeaway paragraph (from `## System Overview`)
3513
- - External dependencies (from `## External Dependencies`)
3514
- - Exposed APIs or entry points (from `## Entry Points`)
3515
- - Dependencies on other services (look for references to sibling service names)
3516
- - Critical invariants summary (from `## Critical Invariants`, if available)
3517
-
3518
- ### 5.3 From `<service>/draft/tech-stack.md`:
3519
- - Primary language/framework
3520
- - Database
3521
- - Key dependencies
3522
-
3523
- ### 5.4 Create/Update `<service>/draft/manifest.json`:
3524
- ```json
3525
- {
3526
- "name": "<service-name>",
3527
- "type": "service",
3528
- "summary": "<first line of product vision>",
3529
- "primaryTech": "<main language/framework>",
3530
- "dependencies": ["<other-service-names>", "<external-deps>"],
3531
- "dependents": [],
3532
- "team": "<if found in docs>",
3533
- "initialized": "<date>",
3534
- "lastIndexed": "<current-date>"
3535
- }
3536
- ```
3537
-
3538
- ## Step 6: Detect Inter-Service Dependencies
3539
-
3540
- Analyze extracted data to build dependency graph:
3541
-
3542
- 1. Look for service name references in each service's architecture.md
3543
- 2. Look for API client imports or service URLs in tech-stack.md
3544
- 3. Look for mentions in product.md that reference other services
3545
- 4. **Graph-enriched detection** (if individual services have `draft/graph/` directories):
3546
- - Read each service's `draft/graph/architecture.json` `.routes` to map which service defines vs consumes which endpoints
3547
- - Cross-reference proto consumers with proto producers to build precise inter-service dependency edges
3548
- - Read `draft/graph/architecture.json` (`.packages`) per service for internal module structure
3549
- - This provides deterministic, code-level dependency data that supplements the heuristic name-matching above
3550
-
3551
- Build a dependency map:
3552
- ```
3553
- auth-service: [] # no dependencies on other services
3554
- billing-service: [auth-service]
3555
- api-gateway: [auth-service, billing-service]
3556
- ```
3557
-
3558
- ### Step 6.1b: Cycle Detection
3559
-
3560
- **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.
3561
-
3562
- ### Step 6.2: Resolve Dependents (Reverse Lookup)
3563
-
3564
- 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.
3565
-
3566
- ## Step 7: Generate Root Aggregated Files
3567
-
3568
- ### 7.1 Generate `draft/service-index.md`
3569
-
3570
- Use the following inline template:
3571
-
3572
- ```markdown
3573
- # Service Index
3574
-
3575
- > Auto-generated by `draft index` on <date>. Do not edit directly.
3576
- > Re-run `draft index` to update.
3577
-
3578
- ## Overview
3579
-
3580
- | Metric | Count |
3581
- |--------|-------|
3582
- | Total Services Detected | X |
3583
- | Initialized | Y |
3584
- | Uninitialized | Z |
3585
-
3586
- ## Service Registry
3587
-
3588
- | Service | Status | Tech Stack | Dependencies | Team | Details |
3589
- |---------|--------|------------|--------------|------|---------|
3590
- | auth | ✓ | Go, Postgres | - | @auth-team | [→](../services/auth/draft/.ai-context.md) |
3591
- | billing | ✓ | Node, Stripe | auth | @billing | [→](../services/billing/draft/.ai-context.md) |
3592
- | legacy-reports | ○ | - | - | - | Not initialized |
3593
-
3594
- ## Uninitialized Services
3595
-
3596
- The following services have not been initialized with `draft init`:
3597
- - `services/legacy-reports/`
3598
- - `services/admin-tools/`
3599
-
3600
- Run `draft index --init-missing` or initialize individually with:
3601
- ```bash
3602
- cd services/legacy-reports && draft init
3603
- ```
3604
- ```
3605
-
3606
- ### 7.2 Generate `draft/dependency-graph.md`
3607
-
3608
- ```markdown
3609
- # Service Dependency Graph
3610
-
3611
- > Auto-generated by `draft index` on <date>. Do not edit directly.
3612
-
3613
- ## System Topology
3614
-
3615
- ```mermaid
3616
- graph LR
3617
- subgraph "Core Services"
3618
- auth[auth-service]
3619
- billing[billing-service]
3620
- users[user-service]
3621
- end
3622
-
3623
- subgraph "Edge"
3624
- gateway[api-gateway]
3625
- end
3626
-
3627
- subgraph "Background"
3628
- notifications[notification-service]
3629
- reports[report-service]
3630
- end
3631
-
3632
- gateway --> auth
3633
- gateway --> billing
3634
- gateway --> users
3635
- billing --> auth
3636
- notifications --> users
3637
- reports --> billing
3638
- ```
3639
-
3640
- ## Dependency Matrix
3641
-
3642
- | Service | Depends On | Depended By |
3643
- |---------|-----------|-------------|
3644
- | auth-service | - | billing, gateway, users |
3645
- | billing-service | auth | gateway, reports |
3646
- | user-service | auth | gateway, notifications |
3647
- | api-gateway | auth, billing, users | - |
3648
-
3649
- ## Dependency Order (Topological)
3650
-
3651
- 1. **auth-service** (foundational - no internal dependencies)
3652
- 2. **user-service** (depends on: auth)
3653
- 3. **billing-service** (depends on: auth)
3654
- 4. **notification-service** (depends on: users)
3655
- 5. **report-service** (depends on: billing)
3656
- 6. **api-gateway** (depends on: auth, billing, users)
3657
-
3658
- > This ordering helps when planning cross-service changes or understanding impact.
3659
- ```
3660
-
3661
- ### 7.3 Generate `draft/tech-matrix.md`
3662
-
3663
- ```markdown
3664
- # Technology Matrix
3665
-
3666
- > Auto-generated by `draft index` on <date>. Do not edit directly.
3667
-
3668
- ## Common Stack (Org Standards)
3669
-
3670
- Technologies used by majority of services:
3671
-
3672
- | Technology | Usage | Services |
3673
- |------------|-------|----------|
3674
- | PostgreSQL | Database | auth, billing, users (85%) |
3675
- | Redis | Caching | auth, gateway, notifications (60%) |
3676
- | Docker | Containerization | all (100%) |
3677
- | GitHub Actions | CI/CD | all (100%) |
3678
-
3679
- ## Technology Distribution
3680
-
3681
- ### Languages
3682
-
3683
- | Language | Services | Percentage |
3684
- |----------|----------|------------|
3685
- | Go | auth, users, gateway | 45% |
3686
- | TypeScript | billing, notifications, reports | 45% |
3687
- | Python | ml-service, analytics | 10% |
3688
-
3689
- ### Databases
3690
-
3691
- | Database | Services |
3692
- |----------|----------|
3693
- | PostgreSQL | auth, billing, users, reports |
3694
- | MongoDB | notifications, analytics |
3695
- | Redis | auth, gateway (cache only) |
3696
-
3697
- ## Variance Report
3698
-
3699
- Services deviating from org standards:
3700
-
3701
- | Service | Deviation | Reason |
3702
- |---------|-----------|--------|
3703
- | ml-service | Python instead of Go/TS | ML ecosystem |
3704
- | analytics | MongoDB instead of Postgres | Time-series workload |
3705
- ```
3706
-
3707
- ### Placeholder Detection
3708
-
3709
- 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.
3710
-
3711
- ### 7.4 Synthesize `draft/product.md` (if not exists or is placeholder)
3712
-
3713
- Read all service product.md files and synthesize:
3714
-
3715
- ```markdown
3716
- # Product: [Org/Product Name]
3717
-
3718
- > Synthesized from X service contexts by `draft index` on <date>.
3719
- > Edit this file to refine the overall product vision.
3720
-
3721
- ## Vision
3722
-
3723
- [Synthesized from common themes across service visions - one paragraph describing what the overall product/platform does]
3724
-
3725
- ## Target Users
3726
-
3727
- <!-- Aggregated from all services, deduplicated -->
3728
- - **End Users**: [common user types across services]
3729
- - **Developers**: [if developer-facing APIs exist]
3730
- - **Operators**: [if ops/admin services exist]
3731
-
3732
- ## Service Capabilities
3733
-
3734
- | Capability | Provided By | Description |
3735
- |------------|-------------|-------------|
3736
- | Authentication | auth-service | User identity, JWT, OAuth |
3737
- | Payments | billing-service | Stripe integration, invoicing |
3738
- | API Access | api-gateway | Rate limiting, routing |
3739
-
3740
- ## Cross-Cutting Concerns
3741
-
3742
- <!-- Extracted from common patterns across services -->
3743
- - **Authentication**: All services validate via auth-service
3744
- - **Observability**: [common logging/tracing approach]
3745
- - **Data Privacy**: [common compliance patterns]
3746
- ```
3747
-
3748
- ### 7.5 Synthesize `draft/architecture.md` (if not exists or is placeholder)
3749
-
3750
- ```markdown
3751
- # Architecture: [Org/Product Name]
3752
-
3753
- > Synthesized from X service contexts by `draft index` on <date>.
3754
- > This is a system-of-systems view. For service internals, see individual service contexts.
3755
-
3756
- ## System Overview
3757
-
3758
- **Key Takeaway:** [One paragraph synthesizing overall system purpose from service summaries]
3759
-
3760
- ### System Topology
3761
-
3762
- ```mermaid
3763
- graph TD
3764
- subgraph "External"
3765
- Users[Users/Clients]
3766
- ThirdParty[Third-Party Services]
3767
- end
3768
-
3769
- subgraph "Edge Layer"
3770
- Gateway[API Gateway]
3771
- CDN[CDN/Static]
3772
- end
3773
-
3774
- subgraph "Core Services"
3775
- Auth[Auth Service]
3776
- Billing[Billing Service]
3777
- Users2[User Service]
3778
- end
3779
-
3780
- subgraph "Background"
3781
- Notifications[Notifications]
3782
- Reports[Reports]
3783
- end
3784
-
3785
- subgraph "Data Layer"
3786
- Postgres[(PostgreSQL)]
3787
- Redis[(Redis)]
3788
- Queue[Message Queue]
3789
- end
3790
-
3791
- Users --> Gateway
3792
- Gateway --> Auth
3793
- Gateway --> Billing
3794
- Gateway --> Users2
3795
- Billing --> ThirdParty
3796
- Auth --> Postgres
3797
- Billing --> Postgres
3798
- Notifications --> Queue
3799
- Reports --> Queue
3800
- ```
3801
-
3802
- ## Service Directory
3803
-
3804
- | Service | Responsibility | Tech | Status | Details |
3805
- |---------|---------------|------|--------|---------|
3806
- | auth-service | Identity & access management | Go, Postgres | ✓ Active | [→ context](../services/auth/draft/.ai-context.md) |
3807
- | billing-service | Payments & invoicing | Node, Stripe | ✓ Active | [→ context](../services/billing/draft/.ai-context.md) |
3808
-
3809
- ## Shared Infrastructure
3810
-
3811
- <!-- Extracted from common external dependencies -->
3812
-
3813
- | Component | Purpose | Used By |
3814
- |-----------|---------|---------|
3815
- | PostgreSQL | Primary datastore | auth, billing, users |
3816
- | Redis | Caching, sessions | auth, gateway |
3817
- | RabbitMQ | Async messaging | notifications, reports |
3818
- | Stripe | Payment processing | billing |
3819
-
3820
- ## Cross-Service Patterns
3821
-
3822
- <!-- Extracted from common conventions -->
3823
-
3824
- | Pattern | Description | Services |
3825
- |---------|-------------|----------|
3826
- | JWT Auth | All services validate JWT via auth-service | all |
3827
- | Event-Driven | Async events via message queue | notifications, reports |
3828
-
3829
- ## Notes
3830
-
3831
- - For detailed service architecture, navigate to individual service contexts
3832
- - This file is regenerable via `draft index`
3833
- - Manual edits to non-synthesized sections will be preserved on re-index
3834
- ```
3835
-
3836
- ### 7.6 Synthesize `draft/tech-stack.md` (if not exists or is placeholder)
3837
-
3838
- ```markdown
3839
- # Tech Stack: [Org/Product Name]
3840
-
3841
- > Synthesized from X service contexts by `draft index` on <date>.
3842
- > This defines org-wide standards. Service-specific additions are in their local tech-stack.md.
3843
-
3844
- ## Org Standards
3845
-
3846
- ### Languages
3847
- - **Primary**: [most common language] — [X% of services]
3848
- - **Secondary**: [second most common] — [Y% of services]
3849
-
3850
- ### Frameworks
3851
- - **API**: [common API framework]
3852
- - **Testing**: [common test framework]
3853
-
3854
- ### Infrastructure
3855
- - **Database**: PostgreSQL (standard), MongoDB (approved for specific use cases)
3856
- - **Caching**: Redis
3857
- - **Messaging**: RabbitMQ / SQS
3858
- - **Container**: Docker
3859
- - **Orchestration**: Kubernetes
3860
-
3861
- ### CI/CD
3862
- - **Platform**: GitHub Actions
3863
- - **Registry**: [container registry]
3864
-
3865
- ## Approved Variances
3866
-
3867
- | Service | Variance | Justification |
3868
- |---------|----------|---------------|
3869
- | ml-service | Python | ML ecosystem requirements |
3870
- | analytics | MongoDB | Time-series workload |
3871
-
3872
- ## Shared Libraries
3873
-
3874
- | Library | Purpose | Version | Used By |
3875
- |---------|---------|---------|---------|
3876
- | @org/auth-client | Auth service client | 2.x | billing, gateway, notifications |
3877
- | @org/logging | Structured logging | 1.x | all services |
3878
- ```
3879
-
3880
- ### 7.7 Synthesize `draft/.ai-context.md` (if not exists or is placeholder)
3881
-
3882
- 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.
3883
-
3884
- - Read the synthesized `draft/architecture.md`
3885
- - Condense into 200-400 lines covering: system overview, service catalog, inter-service dependencies, shared infrastructure, cross-cutting patterns, critical invariants, and entry points
3886
- - If `draft/.ai-context.md` already exists and is not a placeholder, prompt before overwriting
3887
-
3888
- ## Step 8: Create Root Config
3889
-
3890
- Create `draft/config.yaml` if not exists:
3891
-
3892
- ```yaml
3893
- # Draft Index Configuration
3894
-
3895
- # Service detection patterns (immediate children only)
3896
- service_patterns:
3897
- - "package.json"
3898
- - "go.mod"
3899
- - "Cargo.toml"
3900
- - "pom.xml"
3901
- - "build.gradle"
3902
- - "pyproject.toml"
3903
- - "requirements.txt"
3904
- - "Dockerfile"
3905
-
3906
- # Directories to exclude from scanning
3907
- exclude_patterns:
3908
- - "node_modules"
3909
- - "vendor"
3910
- - ".git"
3911
- - "draft"
3912
- - ".*" # Hidden directories
3913
-
3914
- # Re-index on these events (for CI integration)
3915
- reindex_triggers:
3916
- - "service added"
3917
- - "service removed"
3918
- - "weekly"
3919
- ```
3920
-
3921
- ## Step 8.5: Refresh Graph Injection Slots
3922
-
3923
- For each initialized service with both `draft/architecture.md` AND `draft/graph/schema.yaml`:
3924
-
3925
- **A. Read current `architecture.md` into memory.**
3926
-
3927
- **B. Regenerate slot content from graph JSONL:**
3928
- - `GRAPH:module-deps` → run `scripts/tools/mermaid-from-graph.sh --repo . --diagram module-deps`
3929
- Parse JSON response, extract `.mermaid` string + `filtered` flag + stats
3930
- - `GRAPH:proto-map` → run `scripts/tools/mermaid-from-graph.sh --repo . --diagram proto-map`
3931
- Parse JSON response, extract `.mermaid` string + stats
3932
- - `GRAPH:hotspots` → read `draft/graph/hotspots.jsonl`, build top-10 markdown table:
3933
- `| File | Lines | fanIn | Score |` with one row per hotspot, ordered by score descending
3934
-
3935
- **C. For each slot, find `<!-- GRAPH:{id}:START -->` ... `<!-- GRAPH:{id}:END -->` markers.**
3936
- Replace entire block (inclusive of markers) with regenerated content.
3937
- If a marker pair is absent (legacy file): insert slot at the designated position and log:
3938
- `"Injected GRAPH:{id} slot into architecture.md (slot was absent — legacy file upgraded)"`
3939
-
3940
- **D. Write updated `architecture.md` back to disk.**
3941
- 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`.
3942
-
3943
- **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.
3944
-
3945
- **F. Report per service:**
3946
- ```
3947
- ✓ <service>: refreshed 3 graph slots (module-deps, proto-map, hotspots)
3948
- ✓ <service>: regenerated .ai-context.md (tier N, {lines} lines)
3949
- ```
3950
-
3951
- ## Step 9: Completion Report
3952
-
3953
- Remove the lockfile:
3954
-
3955
- ```bash
3956
- rm -f draft/.index-lock
3957
- ```
3958
-
3959
- ```
3960
- ---
3961
- DRAFT INDEX COMPLETE
3962
- ---
3963
- Scanned: X service directories (depth=1)
3964
- Indexed: Y services with draft/ context
3965
- Skipped: Z uninitialized services
3966
-
3967
- Generated/Updated:
3968
- ✓ draft/service-index.md (service registry)
3969
- ✓ draft/dependency-graph.md (inter-service topology)
3970
- ✓ draft/tech-matrix.md (technology distribution)
3971
- ✓ draft/product.md (synthesized product vision)
3972
- ✓ draft/architecture.md (system-of-systems view)
3973
- ✓ draft/tech-stack.md (org standards)
3974
- ✓ draft/config.yaml (index configuration)
3975
-
3976
- Service manifests updated: Y services
3977
-
3978
- Next steps:
3979
- 1. Review synthesized files in draft/
3980
- 2. Edit draft/product.md to refine overall vision
3981
- 3. Edit draft/architecture.md to add cross-cutting context
3982
- 4. Run draft index periodically to refresh
3983
-
3984
- For uninitialized services, run:
3985
- draft index init-missing
3986
- ---
3987
- ```
3988
-
3989
- ## Operational Notes
3990
-
3991
- ### What This Command Does NOT Do
3992
-
3993
- - **No deep code analysis** — Reads only existing `draft/*.md` files
3994
- - **No source code scanning** — That's `draft init`'s job per service
3995
- - **No recursive scanning** — Depth=1 only, immediate children
3996
- - **No duplication** — Root files link to service files, not copy content
3997
-
3998
- ### When to Re-Run
3999
-
4000
- - After running `draft init` on a new service
4001
- - After significant changes to service architectures
4002
- - Weekly/monthly as part of documentation hygiene
4003
- - Before major cross-service planning
4004
-
4005
- ### Preserving Manual Edits
4006
-
4007
- When regenerating, the skill:
4008
- 1. Reads existing root files
4009
- 2. Identifies manually-added sections (not marked as auto-generated)
4010
- 3. Preserves those sections while updating auto-generated parts
4011
- 4. Sections between `<!-- MANUAL START -->` and `<!-- MANUAL END -->` are never overwritten
4012
-
4013
- **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.
4014
-
4015
- ---
4016
-
4017
3207
  ## Graph Command
4018
3208
 
4019
3209
  When user says "build graph", "refresh graph", or "draft graph [path]":
4020
3210
 
4021
- Initialize or refresh the `draft/graph/` knowledge-graph snapshot for a repository. This is the narrow "give me a fresh structural graph" command — it does **not** generate `architecture.md`/`.ai-context.md` (that is `draft init`) and does **not** re-inject doc diagram slots (that is `draft index`).
3211
+ Initialize or refresh the `draft/graph/` knowledge-graph snapshot for a single repository. This is the narrow "give me a fresh structural graph" command — it does **not** generate `architecture.md`/`.ai-context.md` and does **not** re-inject doc diagram slots (both are `draft init`). For scope-aware, root-first graph memory across a monorepo (root spine + module→root links), use `draft init --graph-only`.
4022
3212
 
4023
3213
  ## Red Flags - STOP if you're:
4024
3214
 
@@ -4068,7 +3258,7 @@ echo "Engine: $ENGINE"
4068
3258
 
4069
3259
  ## Step 3: Build / refresh the snapshot
4070
3260
 
4071
- One call resolves the engine, indexes the repo (incrementally on refresh), and writes the committed snapshot under `<repo>/draft/graph/` — `schema.yaml`, `architecture.json`, `hotspots.jsonl`, `module-deps.mermaid`, `proto-map.mermaid`.
3261
+ One call resolves the engine, indexes the repo (incrementally on refresh), and writes the committed snapshot under `<repo>/draft/graph/` — `schema.yaml`, `architecture.json`, `hotspots.jsonl`, `module-deps.mermaid`, `proto-map.mermaid`, and an Open Knowledge Format bundle under `okf/` (a portable, vendor-neutral markdown mirror of the graph — `index.md` + one cross-linked `modules/<name>.md` concept per module).
4072
3262
 
4073
3263
  ```bash
4074
3264
  scripts/tools/graph-snapshot.sh --repo "$REPO_ABS"
@@ -4105,7 +3295,7 @@ Present a concise summary:
4105
3295
 
4106
3296
  Then point the user at the natural next steps:
4107
3297
 
4108
- - To re-inject the refreshed diagrams/hotspot tables into `architecture.md` / `.ai-context.md`: run `draft index`.
3298
+ - To re-inject the refreshed diagrams/hotspot tables into `architecture.md` / `.ai-context.md`: run `draft init refresh` (or `draft init --graph-only` to rebuild just the graph memory).
4109
3299
  - For a first-time full context bootstrap (architecture + profiles): run `draft init`.
4110
3300
 
4111
3301
  ## Graceful Degradation
@@ -7095,6 +6285,19 @@ Use track context to:
7095
6285
 
7096
6286
  If no Draft context exists, proceed with code-only analysis.
7097
6287
 
6288
+ ## Multi-Directory Mode (monorepo)
6289
+
6290
+ `draft bughunt` can sweep multiple sub-projects in one run — useful at a monorepo root. Trigger it with an explicit directory list (`bughunt <dir1> <dir2> ...`) or no list (auto-discover).
6291
+
6292
+ 1. **Resolve targets:**
6293
+ - **Explicit list** → use the given directories; verify each exists; skip (with a warning) any that lack a `draft/` directory.
6294
+ - **Auto-discover** → immediate child directories containing a `draft/` folder, excluding `node_modules/`, `vendor/`, `.git/`, `draft/`, and dotfiles.
6295
+ 2. **Run sequentially** (not in parallel — avoids context conflicts): for each target, run the full single-target bug hunt below scoped to that directory. Each writes its own `<dir>/draft/bughunt-report-latest.md`.
6296
+ 3. **Aggregate** into `draft/bughunt-summary.md` at the invocation root: a table of `dir | Critical | High | Medium | Low | Total | report link`, a grand total, and a "directories with Critical issues" callout.
6297
+ 4. Report skipped directories (no `draft/`) and suggest running `draft init` in them first.
6298
+
6299
+ For a single target (the common case), skip this section and proceed.
6300
+
7098
6301
  ## Dimension Applicability Check
7099
6302
 
7100
6303
  Before analyzing all 14 dimensions, determine which apply to this codebase:
@@ -9472,7 +8675,6 @@ When user says "discover debug" or "draft discover <intent>" (debug, bughunt, re
9472
8675
  - Code quality reviews (lightweight to exhaustive to architectural)
9473
8676
  - Coverage analysis and test strategy design
9474
8677
  - Discovering and codifying project conventions
9475
- - Monorepo indexing and context aggregation
9476
8678
  - Project tours, impact analysis, or reviewer assistance
9477
8679
 
9478
8680
  ## Routing Logic
@@ -9488,7 +8690,6 @@ Strong keyword and phrase matching with fallback to a menu when intent is broad
9488
8690
  | coverage, code coverage, test coverage report | `draft coverage` | Coverage measurement and gap report |
9489
8691
  | test strategy, testing plan, coverage targets, pyramid | `draft testing-strategy` | Test approach design |
9490
8692
  | learn patterns, discover conventions, update guardrails, anti-patterns | `draft learn` | Pattern mining + guardrail evolution |
9491
- | index services, aggregate context, monorepo index | `draft index` | Monorepo service context aggregation |
9492
8693
  | tour, walkthrough, onboard me, getting started tour | `draft tour` | Guided interactive project tour |
9493
8694
  | blast radius, code impact, affected modules, downstream callers | `draft review` or `scripts/tools/graph-impact.sh` | Graph-derived blast-radius before merge |
9494
8695
  | impact, delivery telemetry, track analytics, CDD effectiveness | `draft impact` | Project-wide track delivery telemetry |
@@ -9514,7 +8715,7 @@ User: "learn the coding patterns in this repo and tighten guardrails"
9514
8715
 
9515
8716
  User: "index the monorepo so agents see all services"
9516
8717
 
9517
- dispatches to `draft index --init-missing`
8718
+ Monorepo context is a foundation task, not a discover route: run `draft init` at the repo root (it builds the whole-repo code graph + a sparse root map linking each module). Running `draft init` inside a sub-module links that module up to the same root graph.
9518
8719
 
9519
8720
  ## Auto-Chains & Recommendations
9520
8721
 
@@ -15180,7 +14381,7 @@ Draft solves this through **Context-Driven Development**: structured documents t
15180
14381
  - [Command Workflows](#command-workflows)
15181
14382
  - [draft init](#draftinit--initialize-project)
15182
14383
  - [draft plan](#draftplan--planning-orchestrator)
15183
- - [draft index](#draftindex--monorepo-service-index)
14384
+ - [Monorepo Support (via draft init)](#monorepo-support-via-draftinit)
15184
14385
  - [draft new-track](#draftnew-track--create-feature-track)
15185
14386
  - [draft implement](#draftimplement--execute-tasks)
15186
14387
  - [draft status](#draftstatus--show-progress)
@@ -15555,7 +14756,7 @@ Draft auto-classifies the project:
15555
14756
  - **Brownfield (existing codebase):** Detected by the presence of `package.json`, `requirements.txt`, `go.mod`, `Cargo.toml`, `src/`, or git history with commits. Draft scans the existing stack and pre-fills `tech-stack.md`.
15556
14757
  - **Greenfield (new project):** Empty or near-empty directory. Developer provides all context through dialogue.
15557
14758
  - **Mature high-context brownfield:** Projects with strong existing agent-optimized docs (CLAUDE.md, INVARIANTS.md, ADRs, etc.) now receive an early Context Quality Audit, graph fidelity declaration, and explicit Relationship/Gaps sections so the generated architecture.md acts as graph-primary overlay rather than duplicative prose.
15558
- - **Monorepo:** Detected by `lerna.json`, `pnpm-workspace.yaml`, `nx.json`, `turbo.json`, or multiple package manifests in child directories. Suggests `draft index` instead.
14759
+ - **Monorepo:** Detected by `lerna.json`, `pnpm-workspace.yaml`, `nx.json`, `turbo.json`, or multiple package manifests in child directories. `draft init` is scope-aware — run it at the root for whole-repo context (sparse root map + the code-graph spine), or inside a sub-module to generate detailed module context that links up to the root graph. See **Monorepo Support (via draft init)** below.
15559
14760
 
15560
14761
  #### Initialization Sequence
15561
14762
 
@@ -15649,32 +14850,31 @@ The parent command should move planning forward rather than listing options.
15649
14850
 
15650
14851
  ---
15651
14852
 
15652
- ### `draft index` — Monorepo Service Index
14853
+ ### Monorepo Support (via `draft init`)
15653
14854
 
15654
- Aggregates Draft context from multiple services in a monorepo into unified root-level documents. Designed for organizations with multiple services, each with their own `draft/` context.
14855
+ There is no separate index command `draft init` is the single, scope-aware entry point. The same command behaves differently by where it is run, so a monorepo needs no special tooling.
15655
14856
 
15656
- #### What It Does
14857
+ #### Root init (run at the repo root)
15657
14858
 
15658
- 1. **Scans** immediate child directories for services (detects `package.json`, `go.mod`, `Cargo.toml`, etc.)
15659
- 2. **Reads** each service's `draft/product.md`, `draft/.ai-context.md` (or legacy `draft/architecture.md`), `draft/tech-stack.md`
15660
- 3. **Synthesizes** root-level documents:
14859
+ 1. **Builds the whole-repo code-graph spine** `graph-init.sh` indexes every file at every depth into one unified graph and writes the committed `draft/graph/` snapshot (the structural source of truth).
14860
+ 2. **Generates a sparse root map** (not deep per-module prose), aggregating the children into root-level documents:
15661
14861
  - `draft/service-index.md` — Service registry with status, tech, and links
15662
- - `draft/dependency-graph.md` — Inter-service dependency topology
14862
+ - `draft/dependency-graph.md` — Inter-service dependency topology (from the graph)
15663
14863
  - `draft/tech-matrix.md` — Technology distribution across services
15664
- - `draft/product.md` — Synthesized product vision (if not exists)
15665
- - `draft/.ai-context.md` — System-of-systems architecture view
15666
- - `draft/tech-stack.md` — Org-wide technology standards
14864
+ - `draft/architecture.md` — High-level system map linking *down* to each module's `draft/.ai-context.md`
14865
+ - `draft/.ai-context.md` / `draft/.ai-profile.md` Condensed system-of-systems views
15667
14866
 
15668
- #### Arguments
14867
+ #### Module init (run inside a sub-module)
15669
14868
 
15670
- - `init-missing` Run `draft init` on services that lack a `draft/` directory
15671
- - `bughunt [dir1 dir2 ...]` — Run `draft bughunt` across subdirectories with `draft/` folders. If no directories specified, auto-discovers all subdirectories with `draft/`. Generates summary report at `draft-index-bughunt-summary.md`.
14869
+ 1. **Ensures the root spine exists first** (builds it if missing), then builds the module's own `draft/graph/` snapshot.
14870
+ 2. **Writes `draft/graph/root-link.json`**a pointer up to the root graph so the module has full cross-module understanding regardless of where init ran.
14871
+ 3. **Generates the detailed module reference** (full 10-section `architecture.md` for the subtree). Use `--module-only` to skip touching the root (link marked `pending`).
15672
14872
 
15673
14873
  #### When to Use
15674
14874
 
15675
- - After running `draft init` on individual services
15676
- - After adding or removing services from the monorepo
15677
- - Periodically to refresh cross-service context
14875
+ - After cloning or adding a service — run `draft init` in it (auto-links to the root spine)
14876
+ - At the root after services change — refresh the whole-repo graph + sparse root map
14877
+ - `draft init --graph-only` to (re)build just the code-graph knowledge memory, no markdown
15678
14878
 
15679
14879
  ---
15680
14880
 
@@ -16554,7 +15754,7 @@ This matrix is the **single source of truth** for which Layer 0.5 files load per
16554
15754
 
16555
15755
  | Command type | Commands | Guardrails loaded |
16556
15756
  |---|---|---|
16557
- | **Read-only** | `draft status`, `draft standup`, `draft tour`, `draft index`, `draft coverage` | **none** |
15757
+ | **Read-only** | `draft status`, `draft standup`, `draft tour`, `draft coverage` | **none** |
16558
15758
  | **Spec / Plan** | `draft new-track`, `draft decompose`, `draft adr`, `draft testing-strategy`, `draft documentation` | `design-norms.md` only (architecture-shaped rules) |
16559
15759
  | **Code-touching (generation)** | `draft implement`, `draft debug`, `draft change`, `draft revert` | `code-quality.md` + `security.md` + `secure-patterns.md` + `language-standards.md` (detected stack) |
16560
15760
  | **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` |
@@ -16591,9 +15791,11 @@ If `draft/graph/schema.yaml` exists, the project has automated graph analysis da
16591
15791
  | `draft/graph/architecture.json` | Node labels, edge types, languages, packages (fan-in/out), entry points, routes, hotspots | JSON |
16592
15792
  | `draft/graph/hotspots.jsonl` | Fan-in-ranked symbols, one object per line: `{id, name, fanIn}` | JSONL |
16593
15793
 
15794
+ The snapshot also includes `draft/graph/okf/` — an Open Knowledge Format v0.1 bundle (`index.md` + `modules/*.md`) emitted by default. It is a portable mirror of the graph, not an always-load target.
15795
+
16594
15796
  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.
16595
15797
 
16596
- 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`.
15798
+ 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:init`. For current data, regenerate via `scripts/tools/mermaid-from-graph.sh`.
16597
15799
 
16598
15800
  **Live structural queries** (run on demand — no per-language index files; the engine's model is unified):
16599
15801
 
@@ -17093,7 +16295,7 @@ This is a self-contained, callable procedure for generating `draft/.ai-context.m
17093
16295
 
17094
16296
  Any skill that mutates `architecture.md` should execute this subroutine afterward to keep the derived context files in sync.
17095
16297
 
17096
- **Called by:** `draft init`, `draft init refresh`, `draft implement`, `draft decompose`, `draft coverage`, `draft index`
16298
+ **Called by:** `draft init`, `draft init refresh`, `draft implement`, `draft decompose`, `draft coverage`
17097
16299
 
17098
16300
  ### Inputs
17099
16301
 
@@ -17629,7 +16831,7 @@ Shared procedure for querying the knowledge graph from any skill. The graph prov
17629
16831
 
17630
16832
  This is the **single source of truth** for graph lookup procedure. Consumer skills MUST reference this file rather than inlining their own lookup logic.
17631
16833
 
17632
- 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`
16834
+ 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 graph`
17633
16835
 
17634
16836
  ## Mandatory Lookup Contract
17635
16837
 
@@ -17759,6 +16961,7 @@ When `draft/graph/` exists, the snapshot contains:
17759
16961
  | `hotspots.jsonl` | Always | Fan-in-ranked symbols, one JSON object per line: `{id, name, fanIn}`. |
17760
16962
  | `module-deps.mermaid` | Diagram injection | File co-change coupling diagram (`FILE_CHANGES_WITH`). |
17761
16963
  | `proto-map.mermaid` | Diagram injection | Detected service-route diagram (`Route` nodes). |
16964
+ | `okf/` | On demand | Open Knowledge Format v0.1 bundle (emitted by default): `index.md` (reserved bundle root, no frontmatter) + cross-linked `modules/<name>.md` concept pages. Portable, vendor-neutral mirror of the graph; validate with `okf-check.sh`. |
17762
16965
 
17763
16966
  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.
17764
16967
 
@@ -17820,7 +17023,7 @@ Emits a ready-to-inject ` ```mermaid ``` ` block, or an empty stub (exit 2) when
17820
17023
  scripts/tools/graph-snapshot.sh --repo .
17821
17024
  ```
17822
17025
 
17823
- 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.
17026
+ Writes the committed `draft/graph/` snapshot (`schema.yaml`, `architecture.json`, `hotspots.jsonl`, `*.mermaid`, plus the Open Knowledge Format bundle under `okf/`). Run during `draft init` and `draft graph`, or whenever the reviewable graph state should be refreshed.
17824
17027
 
17825
17028
  ## Finding the Engine (Resolution + Usage Report)
17826
17029
 
@@ -17846,7 +17049,7 @@ After successful detection, `draft/.graph-binary-report.json` contains: `detecte
17846
17049
 
17847
17050
  ## Building the Snapshot
17848
17051
 
17849
- Run during `draft:init` / `draft:index`, or manually:
17052
+ Run during `draft:init` / `draft:graph`, or manually:
17850
17053
 
17851
17054
  ```bash
17852
17055
  scripts/tools/graph-snapshot.sh --repo .
@@ -18644,6 +17847,7 @@ whose `pre_deploy_status != passing`.
18644
17847
  <core-file path="core/templates/guardrails.md">
18645
17848
 
18646
17849
  ---
17850
+ type: Guardrails
18647
17851
  project: "{PROJECT_NAME}"
18648
17852
  module: "root"
18649
17853
  generated_by: "draft:init"
@@ -19208,6 +18412,7 @@ Structured questions for track creation. **Ask ONE question at a time.** Wait fo
19208
18412
  <core-file path="core/templates/ai-context.md">
19209
18413
 
19210
18414
  ---
18415
+ type: ContextMap
19211
18416
  project: "{PROJECT_NAME}"
19212
18417
  module: "root"
19213
18418
  generated_by: "draft:init"
@@ -19487,6 +18692,7 @@ interface {ServiceName} {
19487
18692
  <core-file path="core/templates/ai-profile.md">
19488
18693
 
19489
18694
  ---
18695
+ type: Profile
19490
18696
  project: "{PROJECT_NAME}"
19491
18697
  module: "{MODULE_NAME or 'root'}"
19492
18698
  generated_by: "draft:{COMMAND_NAME}"
@@ -19537,6 +18743,7 @@ generated_at: "{ISO_TIMESTAMP}"
19537
18743
  <core-file path="core/templates/architecture.md">
19538
18744
 
19539
18745
  ---
18746
+ type: Architecture
19540
18747
  project: "{PROJECT_NAME}"
19541
18748
  module: "root"
19542
18749
  generated_by: "draft:init"
@@ -20196,6 +19403,7 @@ Use Cases:
20196
19403
  <core-file path="core/templates/product.md">
20197
19404
 
20198
19405
  ---
19406
+ type: Product
20199
19407
  project: "{PROJECT_NAME}"
20200
19408
  module: "root"
20201
19409
  generated_by: "draft:init"
@@ -20315,6 +19523,7 @@ Things explicitly out of scope for this product:
20315
19523
  <core-file path="core/templates/tech-stack.md">
20316
19524
 
20317
19525
  ---
19526
+ type: TechStack
20318
19527
  project: "{PROJECT_NAME}"
20319
19528
  module: "root"
20320
19529
  generated_by: "draft:init"
@@ -20493,6 +19702,7 @@ graph TD
20493
19702
  <core-file path="core/templates/workflow.md">
20494
19703
 
20495
19704
  ---
19705
+ type: Workflow
20496
19706
  project: "{PROJECT_NAME}"
20497
19707
  module: "root"
20498
19708
  generated_by: "draft:init"
@@ -20689,6 +19899,7 @@ If task exceeds 5 iterations:
20689
19899
  <core-file path="core/templates/spec.md">
20690
19900
 
20691
19901
  ---
19902
+ type: Spec
20692
19903
  project: "{PROJECT_NAME}"
20693
19904
  module: "root"
20694
19905
  track_id: "{TRACK_ID}"
@@ -20863,6 +20074,7 @@ approvers:
20863
20074
  <core-file path="core/templates/plan.md">
20864
20075
 
20865
20076
  ---
20077
+ type: Plan
20866
20078
  project: "{PROJECT_NAME}"
20867
20079
  module: "root"
20868
20080
  track_id: "{TRACK_ID}"
@@ -21113,7 +20325,7 @@ Portable stub. Content generalized from proven internal patterns.
21113
20325
  ---
21114
20326
  project: "{PROJECT_NAME}"
21115
20327
  module: "root"
21116
- generated_by: "draft:index"
20328
+ generated_by: "draft:init"
21117
20329
  generated_at: "{ISO_TIMESTAMP}"
21118
20330
  ---
21119
20331
 
@@ -21127,7 +20339,7 @@ generated_at: "{ISO_TIMESTAMP}"
21127
20339
  | **Synced To** | `{FULL_SHA}` |
21128
20340
 
21129
20341
  > Auto-generated. Do not edit directly.
21130
- > Re-run `draft index` to update.
20342
+ > Re-run `draft init` to update.
21131
20343
 
21132
20344
  ---
21133
20345
 
@@ -21154,7 +20366,7 @@ The following services have not been initialized with `draft init`:
21154
20366
 
21155
20367
  - `[path/to/service]/`
21156
20368
 
21157
- Run `draft index --init-missing` or initialize individually with:
20369
+ Initialize each one by running `draft init` inside its directory — it links the module's graph up to the root spine:
21158
20370
  ```bash
21159
20371
  cd [path/to/service] && draft init
21160
20372
  ```
@@ -21177,7 +20389,7 @@ cd [path/to/service] && draft init
21177
20389
  ---
21178
20390
  project: "{PROJECT_NAME}"
21179
20391
  module: "root"
21180
- generated_by: "draft:index"
20392
+ generated_by: "draft:init"
21181
20393
  generated_at: "{ISO_TIMESTAMP}"
21182
20394
  ---
21183
20395
 
@@ -21191,7 +20403,7 @@ generated_at: "{ISO_TIMESTAMP}"
21191
20403
  | **Synced To** | `{FULL_SHA}` |
21192
20404
 
21193
20405
  > Auto-generated. Do not edit directly.
21194
- > Re-run `draft index` to update.
20406
+ > Re-run `draft init` to update.
21195
20407
 
21196
20408
  ---
21197
20409
 
@@ -21289,7 +20501,7 @@ Services depending on external systems:
21289
20501
  ---
21290
20502
  project: "{PROJECT_NAME}"
21291
20503
  module: "root"
21292
- generated_by: "draft:index"
20504
+ generated_by: "draft:init"
21293
20505
  generated_at: "{ISO_TIMESTAMP}"
21294
20506
  ---
21295
20507
 
@@ -21303,7 +20515,7 @@ generated_at: "{ISO_TIMESTAMP}"
21303
20515
  | **Synced To** | `{FULL_SHA}` |
21304
20516
 
21305
20517
  > Auto-generated. Do not edit directly.
21306
- > Re-run `draft index` to update.
20518
+ > Re-run `draft init` to update.
21307
20519
 
21308
20520
  ---
21309
20521
 
@@ -21399,7 +20611,7 @@ Current versions in production:
21399
20611
  ---
21400
20612
  project: "{PROJECT_NAME}"
21401
20613
  module: "root"
21402
- generated_by: "draft:index"
20614
+ generated_by: "draft:init"
21403
20615
  generated_at: "{ISO_TIMESTAMP}"
21404
20616
  ---
21405
20617
 
@@ -21414,7 +20626,7 @@ generated_at: "{ISO_TIMESTAMP}"
21414
20626
 
21415
20627
  > Synthesized from [X] service contexts.
21416
20628
  > Edit this file to refine the overall product vision.
21417
- > Re-running `draft index` will update auto-generated sections but preserve manual edits.
20629
+ > Re-running `draft init` will update auto-generated sections but preserve manual edits.
21418
20630
 
21419
20631
  ---
21420
20632
 
@@ -21461,7 +20673,7 @@ generated_at: "{ISO_TIMESTAMP}"
21461
20673
  ---
21462
20674
  project: "{PROJECT_NAME}"
21463
20675
  module: "root"
21464
- generated_by: "draft:index"
20676
+ generated_by: "draft:init"
21465
20677
  generated_at: "{ISO_TIMESTAMP}"
21466
20678
  ---
21467
20679
 
@@ -21476,7 +20688,7 @@ generated_at: "{ISO_TIMESTAMP}"
21476
20688
 
21477
20689
  > Synthesized from [X] service contexts.
21478
20690
  > This is a **system-of-systems** view. For service internals, see individual service contexts.
21479
- > Re-running `draft index` will update auto-generated sections but preserve manual edits.
20691
+ > Re-running `draft init` will update auto-generated sections but preserve manual edits.
21480
20692
 
21481
20693
  ---
21482
20694
 
@@ -21583,7 +20795,7 @@ sequenceDiagram
21583
20795
  ## Notes
21584
20796
 
21585
20797
  - For detailed service architecture, navigate to individual service contexts via the Details column
21586
- - This file is regenerable via `draft index`
20798
+ - This file is regenerable via `draft init`
21587
20799
  - Manual edits between `<!-- MANUAL START -->` and `<!-- MANUAL END -->` are preserved
21588
20800
 
21589
20801
  </core-file>
@@ -21597,7 +20809,7 @@ sequenceDiagram
21597
20809
  ---
21598
20810
  project: "{PROJECT_NAME}"
21599
20811
  module: "root"
21600
- generated_by: "draft:index"
20812
+ generated_by: "draft:init"
21601
20813
  generated_at: "{ISO_TIMESTAMP}"
21602
20814
  ---
21603
20815
 
@@ -21612,7 +20824,7 @@ generated_at: "{ISO_TIMESTAMP}"
21612
20824
 
21613
20825
  > Synthesized from [X] service contexts.
21614
20826
  > This defines **org-wide standards**. Service-specific additions are in their local tech-stack.md.
21615
- > Re-running `draft index` will update auto-generated sections but preserve manual edits.
20827
+ > Re-running `draft init` will update auto-generated sections but preserve manual edits.
21616
20828
 
21617
20829
  ---
21618
20830
 
@@ -21721,6 +20933,7 @@ Org-wide conventions:
21721
20933
  <core-file path="core/templates/rca.md">
21722
20934
 
21723
20935
  ---
20936
+ type: RCA
21724
20937
  project: "{PROJECT_NAME}"
21725
20938
  track_id: "{TRACK_ID}"
21726
20939
  jira_ticket: "{JIRA_KEY}"
@@ -21895,6 +21108,7 @@ git-ignored at the track level. No HTML or PDF templates ship here.
21895
21108
  <core-file path="core/templates/discovery.md">
21896
21109
 
21897
21110
  ---
21111
+ type: Discovery
21898
21112
  project: "{PROJECT_NAME}"
21899
21113
  module: "root"
21900
21114
  track_id: "{TRACK_ID}"
@@ -21983,6 +21197,7 @@ without line numbers are exempt from drift checks (they document
21983
21197
  <core-file path="core/templates/hld.md">
21984
21198
 
21985
21199
  ---
21200
+ type: HLD
21986
21201
  project: "{PROJECT_NAME}"
21987
21202
  module: "root"
21988
21203
  track_id: "{TRACK_ID}"
@@ -22319,6 +21534,7 @@ Result stored in `metadata.json:pre_deploy_status`
22319
21534
  <core-file path="core/templates/lld.md">
22320
21535
 
22321
21536
  ---
21537
+ type: LLD
22322
21538
  project: "{PROJECT_NAME}"
22323
21539
  module: "root"
22324
21540
  track_id: "{TRACK_ID}"