@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,6 +1,6 @@
1
1
  ---
2
2
  name: init
3
- description: "Initialize Draft project context for Context-Driven Development. Run once per project to create product.md, tech-stack.md, workflow.md, tracks.md, architecture.md (brownfield), .ai-context.md (derived), and .ai-profile.md (ultra-compact profile). Always performs deep analysis. Use when the user asks to 'init draft', 'set up Draft for this project', 'bootstrap context', or says 'start using Draft', 'I want to use Draft here'."
3
+ description: "Initialize Draft project context for Context-Driven Development — the single, scope-aware entry point (works at the repo root or inside any sub-module; no separate index command). Builds the root-first code-graph knowledge memory (draft/graph/, with a module→root link) and creates product.md, tech-stack.md, workflow.md, tracks.md, architecture.md (brownfield), .ai-context.md (derived), and .ai-profile.md. Supports --graph-only (graph memory only, no markdown) and --module-only. Use when the user asks to 'init draft', 'set up Draft for this project', 'bootstrap context', 'build the code graph', or says 'start using Draft', 'I want to use Draft here'."
4
4
  ---
5
5
 
6
6
  # Draft Init
@@ -52,7 +52,7 @@ Initialize a Draft project for Context-Driven Development.
52
52
 
53
53
  ## Graph Fidelity & Diagram-First Priority (MANDATORY)
54
54
 
55
- The knowledge graph in `draft/graph/` (architecture.json with packages, languages, routes, and fan-in/out; hotspots.jsonl) is the **deterministic structural ground truth** for the system's actual architecture.
55
+ The knowledge graph served live by the local `codebase-memory-mcp` engine (packages, languages, routes, fan-in/out, hotspots) and queried via the `graph-*.sh` wrappers — is the **deterministic structural ground truth** for the system's actual architecture. Draft is engine-only: `draft/graph/` holds only the `schema.yaml` gate marker; all graph data comes from live queries.
56
56
 
57
57
  **You are running inside a powerful agentic coding environment** (Cursor, Claude Code, Copilot, Windsurf, etc.) that maintains its own rich, continuously updated index of the entire codebase. **Use that indexed knowledge aggressively** in addition to the explicit graph data and direct source reads. Your environment's index often captures higher-level intent, naming patterns, cross-file workflows, and architectural signals that the static graph may not fully express yet. Combine both sources:
58
58
  - Graph = authoritative modules, edges, public surfaces, hotspots, call relationships.
@@ -193,18 +193,24 @@ synced_to_commit: "a1b2c3d4e5f6789012345678901234567890abcd"
193
193
 
194
194
  Check for arguments:
195
195
  - `refresh`: Update existing context without full re-init
196
- - `index`: Route to `/draft:index`
196
+ - `--graph-only`: Build/refresh only the code-graph knowledge memory (no markdown) — see the fast path below
197
+ - `--module-only`: When run in a sub-module, do not touch the root graph (the module→root link is marked `pending`)
197
198
  - `discover`: Route to `/draft:discover`
198
199
 
200
+ > `/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.
201
+
199
202
  ### Route Explicit Modes Before Initialization
200
203
 
201
204
  If the user explicitly invoked a specialist mode, route directly:
202
205
 
203
- - `/draft:init index` → follow `/draft:index`
204
206
  - `/draft:init discover` → follow `/draft:discover`
205
207
 
206
208
  Explicit mode always wins. Do not perform standard initialization if an explicit mode is requested.
207
209
 
210
+ ### `--graph-only` Fast Path
211
+
212
+ 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).
213
+
208
214
  ### Standard Init Check
209
215
 
210
216
  ```bash
@@ -236,16 +242,16 @@ mv draft.tmp/ draft/
236
242
 
237
243
  > **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.
238
244
 
239
- ### Monorepo Detection
245
+ ### Scope Detection (root vs sub-module)
240
246
 
241
- Check for monorepo indicators:
242
- - Multiple `package.json` / `go.mod` / `Cargo.toml` in child directories
243
- - `lerna.json`, `pnpm-workspace.yaml`, `nx.json`, or `turbo.json` at root
244
- - `packages/`, `apps/`, `services/` directories with independent manifests
247
+ `/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.
245
248
 
246
- If monorepo detected:
247
- - Announce: "Detected monorepo structure. Consider using `/draft:init index` at root level to aggregate service context, or run `/draft:init` within individual service directories."
248
- - Ask user to confirm: initialize here (single service) or abort (use /draft:init index instead)
249
+ Resolve **ROOT** = nearest ancestor (above the current dir) containing `draft/` → else the git toplevel → else the current dir. Then:
250
+
251
+ - **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.)
252
+ - **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.
253
+
254
+ 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).
249
255
 
250
256
  ### Migration Detection
251
257
 
@@ -478,20 +484,25 @@ If **Greenfield**: skip to Step 2 (Product Definition).
478
484
 
479
485
  **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.
480
486
 
481
- ### 1. Build the graph snapshot
487
+ ### 1. Build the graph (scope-aware, root-first)
482
488
 
483
- 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.
489
+ 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.
484
490
 
485
- One command resolves the engine, indexes the repo, and writes the committed snapshot under `draft/graph/`:
491
+ 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:
486
492
 
487
493
  ```bash
488
- if scripts/tools/graph-snapshot.sh --repo .; then
489
- echo "Graph snapshot written to draft/graph/ (schema.yaml, architecture.json, hotspots.jsonl, *.mermaid)."
494
+ # Add --module-only to skip touching the root (link marked "pending").
495
+ if scripts/tools/graph-init.sh --scope .; then
496
+ echo "Graph memory ready under draft/graph/ (the root spine is the structural source of truth)."
490
497
  else
491
- echo "Graph engine unavailable — skipping automated graph analysis. Downstream skills degrade gracefully."
498
+ echo "Graph engine unavailable — proceeding with degraded manual discovery. Downstream skills degrade gracefully."
492
499
  fi
493
500
  ```
494
501
 
502
+ - **Root init** writes `<root>/draft/graph/schema.yaml` — the committed gate marker. Draft is engine-only: graph data is served live by the engine, never committed.
503
+ - **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.
504
+ - Only `schema.yaml` (and `root-link.json` in a module) is committed. The engine's `~/.cache` index is the live structural store — never commit it; it rebuilds deterministically from source.
505
+
495
506
  Optionally record which engine was selected (usage-report contract):
496
507
 
497
508
  ```bash
@@ -500,15 +511,20 @@ scripts/tools/verify-graph-binary.sh --repo . --json 2>/dev/null || true
500
511
 
501
512
  See `core/shared/graph-query.md` and `bin/README.md` for the query contract and engine resolution.
502
513
 
503
- If the snapshot succeeds, `draft/graph/` is populated and later steps consume the always-load artifacts + injection slots.
514
+ If indexing succeeds, `draft/graph/schema.yaml` is written and later steps query the engine live for structure + populate the injection slots.
504
515
 
505
- ### 2. If graph build succeeds, load the always-load artifacts
516
+ ### 2. If indexing succeeds, query the engine for structural context
506
517
 
507
- Read these files to get structural context for all subsequent phases:
508
- - `draft/graph/schema.yaml` — module count, file count, edge count, language stats per module
509
- - `draft/graph/architecture.json` — module list (`.packages`) with fan-in/out
510
- - `draft/graph/architecture.json` `.routes` — detected service endpoints
511
- - `draft/graph/hotspots.jsonl` — all complexity hotspots (files ranked by lines + fanIn * 50)
518
+ Pull the architecture view once and reuse it across phases:
519
+
520
+ ```bash
521
+ ARCH=$(scripts/tools/graph-arch.sh --repo .)
522
+ ```
523
+
524
+ - `$ARCH | jq '.packages'` — module list with fan-in/out
525
+ - `$ARCH | jq '.routes'` — detected service endpoints
526
+ - `$ARCH | jq '.languages, .node_labels, .layers, .boundaries'` — language mix, node shape, layering
527
+ - `scripts/tools/hotspot-rank.sh --repo . --top 20` — complexity/fan-in hotspots (live)
512
528
 
513
529
  ### 3. Use graph data to accelerate Step 1.5
514
530
 
@@ -522,10 +538,10 @@ Read these files to get structural context for all subsequent phases:
522
538
  ### 4. Compute codebase tier and module priority
523
539
 
524
540
  **Step 1.4.5 — Compute Codebase Tier:**
525
- Read `draft/graph/schema.yaml`. Extract:
526
- - `M = stats.modules`
527
- - `F = stats.go_functions + stats.py_functions`
528
- - `P = stats.proto_rpcs`
541
+ From the live `$ARCH` (above), extract:
542
+ - `M = $ARCH | jq '.packages | length'` (modules)
543
+ - `F = $ARCH | jq '[.node_labels[] | select(.label=="Function" or .label=="Method") | .count] | add // 0'` (functions+methods)
544
+ - `P = $ARCH | jq '.routes | length'` (routes / RPCs)
529
545
 
530
546
  Apply tier table:
531
547
 
@@ -540,8 +556,8 @@ Apply tier table:
540
556
  Hold tier in memory. This governs: architecture.md length minimum, .ai-context.md budget, and module deep-dive depth.
541
557
 
542
558
  **Step 1.4.6 — Build Module Priority List:**
543
- From `draft/graph/hotspots.jsonl`: count hotspot files per module (group by `module` field).
544
- From `draft/graph/architecture.json` `.packages[]`: read `fan_in` per module.
559
+ From `scripts/tools/hotspot-rank.sh --repo .`: count hotspot symbols per module.
560
+ From `$ARCH | jq '.packages[]'`: read `fan_in` per module.
545
561
  Rank modules by: `(hotspot_count × 2) + fan_in_count`.
546
562
  Top-ranked modules drive Section 6 deep-dive ordering and depth. Modules ranked zero on both: summary treatment only.
547
563
  Hold ranked list in memory — it replaces directory scanning for module discovery.
@@ -561,7 +577,7 @@ The tool emits a ready-to-inject ` ```mermaid ``` ` block (or an empty stub on e
561
577
  ```
562
578
 
563
579
  For Section 20 (hotspots slot):
564
- Read `draft/graph/hotspots.jsonl` (or run `scripts/tools/hotspot-rank.sh --repo . --top 10`), take the top 10 by fanIn, build a markdown table:
580
+ Run `scripts/tools/hotspot-rank.sh --repo . --top 10`, take the top 10 by fanIn, build a markdown table:
565
581
  ```
566
582
  <!-- GRAPH:hotspots:START -->
567
583
  | Symbol | fanIn |
@@ -620,7 +636,7 @@ Perform a **one-time, exhaustive analysis** of the existing codebase. This is NO
620
636
 
621
637
  If the codebase is large (200+ files), focus on the module boundaries but still enumerate exhaustively within each module.
622
638
 
623
- > **Large codebase guardrail:** If the codebase exceeds 500 source files, limit Section 7 deep dives to the top 20 most-imported modules and summarize others in a table. Rank modules by the number of unique files that import/reference them (descending) — use `draft/graph/architecture.json` `.packages[].fan_in` if graph data is available. For dynamic languages where static import counting is impractical, rank by file count within each module directory (larger modules first). **Even for summarized modules, enumerate immediate sub-directories with file counts** (one-line per sub-dir) — this is cheap with graph data and provides essential navigation context.
639
+ > **Large codebase guardrail:** If the codebase exceeds 500 source files, limit Section 7 deep dives to the top 20 most-imported modules and summarize others in a table. Rank modules by the number of unique files that import/reference them (descending) — use the engine's `.packages[].fan_in` (`get_architecture`, captured as `$ARCH` in Step 1.4.2) if the engine is available. For dynamic languages where static import counting is impractical, rank by file count within each module directory (larger modules first). **Even for summarized modules, enumerate immediate sub-directories with file counts** (one-line per sub-dir) — this is cheap with graph data and provides essential navigation context.
624
640
 
625
641
  ### Parallel Analysis Protocol (Tiers 3–5)
626
642
 
@@ -647,16 +663,16 @@ For tier 3+, readers run simultaneously; wall clock = slowest reader, not the su
647
663
 
648
664
  #### Phase 0: Graph Data (already done in Step 1.4)
649
665
 
650
- The graph binary has already run. Use its output throughout this protocol:
651
- - `draft.tmp/graph/schema.yaml` — module list, file counts, tier metrics
652
- - `draft.tmp/graph/architecture.json` — `.packages[].fan_in` per module (for grouping)
653
- - `draft.tmp/graph/hotspots.jsonl` — top hotspot files per module (feed to readers)
666
+ The engine is already indexed. Query it live throughout this protocol (reuse `$ARCH` from Step 1.4.2):
667
+ - `$ARCH | jq '.packages'` — module list with `.fan_in`/`.fan_out` (for grouping)
668
+ - `$ARCH | jq '.languages, .node_labels'` — file/symbol counts, tier metrics
669
+ - `scripts/tools/hotspot-rank.sh --repo .` — top hotspot symbols per module (feed to readers)
654
670
 
655
671
  #### Phase 1: Spawn Parallel Module Readers
656
672
 
657
673
  **Step 1: Group modules.**
658
674
 
659
- From `draft.tmp/graph/architecture.json` `.packages[]`, extract all module names and their `fan_in` counts.
675
+ From `$ARCH | jq '.packages[]'`, extract all module names and their `fan_in` counts.
660
676
  Apply dependency-aware grouping (see `core/shared/parallel-analysis.md`).
661
677
  Use the modules-per-agent count from the tier table above (4 for tier 4/5; all modules in one agent for tier 1):
662
678
  - Assign highest fan-in modules to separate readers (tier 3+)
@@ -672,7 +688,7 @@ Hotspot files:
672
688
  execution/engine.go (847 lines, fanIn=12)
673
689
  execution/router.go (412 lines, fanIn=8)
674
690
  fill_processor/handler.go (623 lines, fanIn=5)
675
- Module edges (from architecture.json .packages fan-in/out):
691
+ Module edges (from $ARCH .packages fan-in/out):
676
692
  execution → [risk, data, services]
677
693
  fill_processor → [execution, persistence]
678
694
  ```
@@ -777,7 +793,7 @@ If any reader agent fails to produce valid JSON after one retry:
777
793
  When the Agent tool is unavailable or reader agents fail after retry, write `draft/architecture.md` using the **10-section graph-primary structure** (checklist above + `core/templates/architecture.md`). Do not use legacy 28-section or Pass 1/2/3 volume protocols.
778
794
 
779
795
  1. Use the ranked module list from Step 1.4.6 (graph-first — do not re-scan by directory if Phase 0 succeeded).
780
- 2. For each top module (up to 20 by fan-in), read `draft/graph/modules/{name}.jsonl`, hotspot files, and 3–5 key sources; embed graph blocks and at least one workflow/state diagram per significant module inside §4–§8 as appropriate.
796
+ 2. For each top module (up to 20 by fan-in), query the engine for its symbols/callers (`scripts/tools/graph-callers.sh`, `graph-impact.sh`, or `$ARCH | jq '.packages[] | select(.name=="<m>")'`), read the hotspot files and 3–5 key sources; embed graph blocks and at least one workflow/state diagram per significant module inside §4–§8 as appropriate.
781
797
  3. Always include §9 Graph Coverage Gaps and §10 Relationship when the Context Audit requires them.
782
798
  4. Run Completion Verification (defined later in this skill) before condensation. Fidelity, provenance, and gap honesty block completion — not line counts.
783
799
 
@@ -900,11 +916,11 @@ Follow these steps in order. The specific files to look for depend on the langua
900
916
 
901
917
  #### Phase 1: Discovery (Broad Scan)
902
918
 
903
- 1. **Map the directory tree**: Recursively list the project to understand the file layout. Note subdirectory groupings. (If Step 1.4 graph analysis succeeded, use `draft.tmp/graph/schema.yaml` module list instead — it is exhaustive and includes file counts.)
919
+ 1. **Map the directory tree**: Recursively list the project to understand the file layout. Note subdirectory groupings. (If Step 1.4 graph analysis succeeded, use the engine's `$ARCH | jq '.packages, .file_tree'` instead — it is exhaustive and includes file counts.)
904
920
 
905
921
  2. **Read build / dependency files**: These reveal the module structure, dependencies, and targets. (See language guide above for which files.)
906
922
 
907
- 3. **Read API definition files**: These define the module's data model and service interfaces. (See language guide above for which files. If Step 1.4 succeeded, `draft.tmp/graph/architecture.json` `.routes` already has all detected service endpoints.)
923
+ 3. **Read API definition files**: These define the module's data model and service interfaces. (See language guide above for which files. If Step 1.4 succeeded, the engine's `$ARCH | jq '.routes'` already has all detected service endpoints.)
908
924
 
909
925
  4. **Read interface / type definition files**: Class declarations, interface definitions, and type annotations reveal the public API and design intent.
910
926
 
@@ -1008,11 +1024,19 @@ The document is:
1008
1024
 
1009
1025
  **Full details, per-section guidance, provenance rules, and examples** live in:
1010
1026
  - `core/templates/architecture.md` (the source of truth for the 10 sections + Generation Contract)
1011
- - `docs/research/proposed-graph-backed-architecture-template.md` (design rationale and fidelity rules)
1012
1027
  - `references/architecture-spec.md` (deprecated legacy notes — **10-section template wins on any conflict**)
1013
1028
 
1014
1029
  There is no legacy 28-section structure and no volume targets. The template itself is the contract.
1015
1030
 
1031
+ ### Root vs Module Markdown (scope asymmetry)
1032
+
1033
+ The depth of generated markdown depends on the scope resolved in **Scope Detection**:
1034
+
1035
+ - **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.
1036
+ - **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."
1037
+
1038
+ The graph is symmetric (root spine + per-module snapshots, linked); only the **prose** is asymmetric. Both consume `draft/graph/`.
1039
+
1016
1040
  **After completing analysis AND passing verification**, write to `draft/architecture.md`. This is the PRIMARY output. Then run the Condensation Subroutine.
1017
1041
 
1018
1042
  ## .ai-context.md Specification
@@ -1588,6 +1612,7 @@ Create `draft/tracks.md` with metadata header:
1588
1612
 
1589
1613
  ```markdown
1590
1614
  ---
1615
+ type: TrackIndex
1591
1616
  project: "{PROJECT_NAME}"
1592
1617
  module: "root"
1593
1618
  generated_by: "draft:init"
@@ -1633,6 +1658,38 @@ For **brownfield** projects, run `/draft:learn` (no arguments — full codebase
1633
1658
 
1634
1659
  ## Completion
1635
1660
 
1661
+ **Finalize the context index:** After all `draft/` files are written, author (or refresh)
1662
+ `draft/index.md` — a plain, navigable index over the context bundle. No OKF framing, no
1663
+ special frontmatter; it is a human- and agent-readable table of contents.
1664
+
1665
+ Write `draft/index.md` with this structure (omit rows whose files were not generated):
1666
+
1667
+ ```md
1668
+ # <project> — Draft Context
1669
+
1670
+ Start here. This indexes the Draft context for this repo.
1671
+
1672
+ ## Context
1673
+ - [Architecture](architecture.md) — module map, dependencies, hotspots (graph-grounded)
1674
+ - [Product](product.md) — what this system does and for whom
1675
+ - [Tech Stack](tech-stack.md) — languages, frameworks, infra
1676
+ - [Workflow](workflow.md) — how work flows through the repo
1677
+ - [Guardrails](guardrails.md) — learned conventions and anti-patterns
1678
+ - [AI Context Map](.ai-context.md) — condensed orientation for agents
1679
+ - [AI Profile](.ai-profile.md) — repo profile + tiering
1680
+
1681
+ ## Tracks
1682
+ - [Track Index](tracks.md) — active, completed, and archived tracks
1683
+
1684
+ ## Knowledge graph
1685
+ - Engine-only (`codebase-memory-mcp`). Structural data is queried live via the
1686
+ `graph-*.sh` wrappers; `draft/graph/schema.yaml` is the gate marker. There is no
1687
+ committed graph mirror to browse.
1688
+ ```
1689
+
1690
+ Keep one-line descriptions accurate to what each file actually contains. This index is
1691
+ the single committed entry point to the `draft/` bundle.
1692
+
1636
1693
  **Finalize run memory:** Update `draft/.state/run-memory.json`:
1637
1694
  - `status`: `"completed"`
1638
1695
  - `completed_at`: current ISO timestamp
@@ -1642,6 +1699,7 @@ For **Brownfield** projects, announce:
1642
1699
  "Draft initialized successfully with comprehensive analysis!
1643
1700
 
1644
1701
  Created:
1702
+ - draft/index.md (plain docs index — navigable table of contents for the draft/ bundle)
1645
1703
  - draft/.ai-profile.md (20-50 lines — ultra-compact always-injected profile, Tier 0)
1646
1704
  - draft/.ai-context.md (200-400 lines — token-optimized AI context, self-contained, Tier 1)
1647
1705
  - draft/architecture.md (comprehensive human-readable engineering reference, Tier 2)
@@ -1676,6 +1734,7 @@ For **Greenfield** projects, announce:
1676
1734
  "Draft initialized successfully!
1677
1735
 
1678
1736
  Created:
1737
+ - draft/index.md (plain docs index — navigable table of contents for the draft/ bundle)
1679
1738
  - draft/product.md
1680
1739
  - draft/tech-stack.md
1681
1740
  - draft/workflow.md
@@ -161,14 +161,14 @@ Write the `GRAPH:module-deps` injection slot into architecture.md:
161
161
 
162
162
  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.
163
163
 
164
- If graph binary was not found: write the slot with placeholder body so draft:index can populate it later:
164
+ If graph binary was not found: write the slot with placeholder body so draft:init --graph-only can populate it later:
165
165
  ```
166
166
  <!-- GRAPH:module-deps:START -->
167
- [Graph data unavailable — run draft:index to populate after graph binary is installed]
167
+ [Graph data unavailable — run draft:init --graph-only to populate after graph binary is installed]
168
168
  <!-- GRAPH:module-deps:END -->
169
169
  ```
170
170
 
171
- The slot markers MUST always be written — they are required for draft:index refresh to function.
171
+ The slot markers MUST always be written — they are required for draft:init --graph-only refresh to function.
172
172
 
173
173
  #### 4.2 Process Lifecycle (or Usage Lifecycle for libraries)
174
174
 
@@ -275,13 +275,13 @@ Only when material: authentication/authorization checkpoints, distributed transa
275
275
 
276
276
  **Core rule:** The graph is the source of truth for structure. LLM synthesis exists only to interpret the graph into actionable design understanding — primarily via one accurate workflow or state diagram per module — plus tiny supporting notes. The previous volume-oriented deep-dive expectations are superseded.
277
277
 
278
- For each module in `draft/graph/architecture.json` (`.packages[]`), produce a subsection whose **primary content** is the deterministic graph block followed by one synthesized behavioral diagram. Every module gets a slot; do not sample. The block's fan-in/out and node counts come from `.packages[]`; public API and key call edges come from live per-package queries (`scripts/tools/graph-callers.sh`, `graph-impact.sh`) and `hotspots.jsonl`.
278
+ For each module returned by `scripts/tools/graph-arch.sh --repo . | jq '.packages[]'`, produce a subsection whose **primary content** is the deterministic graph block followed by one synthesized behavioral diagram. Every module gets a slot; do not sample. The block's fan-in/out and node counts come from `.packages[]`; public API and key call edges come from live per-package queries (`scripts/tools/graph-callers.sh`, `graph-impact.sh`) and `scripts/tools/hotspot-rank.sh --repo .`.
279
279
 
280
280
  #### 7.{N} {module-name}
281
281
 
282
282
  <!-- GRAPH:module-deep/{module-name}:START -->
283
283
  <!-- Rendered deterministic block: package name, node count, public API list, fan-in/fan-out (from
284
- architecture.json .packages), hotspot fan-in (from hotspots.jsonl), key call edges (from
284
+ get_architecture .packages), hotspot fan-in (from hotspot-rank.sh), key call edges (from
285
285
  graph-callers.sh/graph-impact.sh), entry points if known. No LLM prose inside fence. -->
286
286
  <!-- GRAPH:module-deep/{module-name}:END -->
287
287
 
@@ -300,7 +300,7 @@ Synthesize a single, accurate Mermaid diagram (`stateDiagram-v2`, `sequenceDiagr
300
300
 
301
301
  #### Sub-Module Guidance (when graph justifies recursion)
302
302
 
303
- When a module has clear internal structure visible in `draft/graph/architecture.json` (`.packages` fan-in/out) or live per-package queries:
303
+ When a module has clear internal structure visible in live engine query `get_architecture .packages` (fan-in/out) or live per-package queries:
304
304
  - Create `##### 7.X.Y {Parent}/{Child}` subsections only for children that have their own meaningful public surface or high internal fan-in.
305
305
  - Each sub-module subsection follows the same compact pattern: graph facts + **one mandatory workflow/state diagram** + ≤60 words Design Notes.
306
306
  - Do not descend further unless the child itself shows additional clear boundaries in the graph data.
@@ -362,7 +362,7 @@ Regardless of tier, any directory whose name contains `ops`, `handlers`, `execut
362
362
  | ... | (enumerate ALL — no sampling, no "and others") | | | |
363
363
  ```
364
364
 
365
- Use `draft/graph/modules/{module}.jsonl` to get the complete file list with line counts. Use `draft/graph/hotspots.jsonl` to flag high-complexity operations.
365
+ Use `scripts/tools/graph-callers.sh --symbol <module>` or `scripts/tools/graph-arch.sh --repo .` to get the complete file list. Use `scripts/tools/hotspot-rank.sh --repo .` to flag high-complexity operations.
366
366
 
367
367
  #### Example: Full Sub-Module Treatment for `icebox/` (917 files)
368
368
 
@@ -409,7 +409,7 @@ stateDiagram-v2
409
409
  After writing Section 7, run these checks before proceeding. **If any check fails, STOP and fix.**
410
410
 
411
411
  **Check 1 — Graph block present and faithful for every module:**
412
- Every top-level module from `draft/graph/architecture.json` (`.packages`) has its `<!-- GRAPH:module-deep/...:START --> ... <!-- GRAPH:module-deep/...:END -->` fence rendered verbatim. No LLM prose inside the fence. No modules missing.
412
+ Every top-level module from the live engine (`get_architecture .packages`) has its `<!-- GRAPH:module-deep/...:START --> ... <!-- GRAPH:module-deep/...:END -->` fence rendered verbatim. No LLM prose inside the fence. No modules missing.
413
413
 
414
414
  **Check 2 — One mandatory workflow/state diagram per module:**
415
415
  Every `#### 7.X` (and every `##### 7.X.Y` that the graph justified) contains exactly one high-signal `Primary Workflow / State` Mermaid diagram (`stateDiagram-v2`, `sequenceDiagram`, or clear `flowchart`). The diagram must reflect facts from the module's graph record (entry points, public symbols, call targets). Generic placeholder diagrams fail this check.
@@ -513,12 +513,13 @@ Include architecturally significant implementations (high fan-in, core extension
513
513
  |---|-----------|-------------|-------|-------------|
514
514
  | 1 | ArchiveFilesOp | `icebox/master/ops/archive_files_op.cc` | 2100 | Archives files to cloud vault |
515
515
  | 2 | CancelJobOp | `icebox/master/ops/cancel_job_op.cc` | 450 | Cancels running archive job |
516
- | (enumerate ALL — use graph hotspots.jsonl and per-module JSONL for file list and line counts) |
516
+ | (enumerate ALL — use hotspot-rank.sh and graph-callers.sh / get_architecture for file list and line counts) |
517
517
  ```
518
518
 
519
- > **MANDATORY (graph data)**: Read `draft/graph/modules/{module}.jsonl` to get the complete file
520
- > list with line counts. Filter for files in operation sub-directories (paths containing `/ops/`,
521
- > `/handlers/`, `/executors/`, `/workers/`). Use `draft/graph/hotspots.jsonl` to flag
519
+ > **MANDATORY (graph data)**: Query `scripts/tools/graph-arch.sh --repo .` or
520
+ > `scripts/tools/graph-callers.sh --symbol <module>` to get the complete file list with line counts.
521
+ > Filter for files in operation sub-directories (paths containing `/ops/`,
522
+ > `/handlers/`, `/executors/`, `/workers/`). Use `scripts/tools/hotspot-rank.sh --repo .` to flag
522
523
  > high-complexity operations (high line count or fanIn). Do NOT skip this step — incomplete
523
524
  > catalogs cause AI agents to reinvent existing functionality.
524
525
 
@@ -1078,11 +1079,11 @@ If graph build succeeded and proto files exist (Step 1.4.7 completed), write the
1078
1079
  If graph binary was not found or no proto files exist, write the slot with placeholder:
1079
1080
  ```
1080
1081
  <!-- GRAPH:proto-map:START -->
1081
- [Graph data unavailable — run draft:index to populate after graph binary is installed]
1082
+ [Graph data unavailable — run draft:init --graph-only to populate after graph binary is installed]
1082
1083
  <!-- GRAPH:proto-map:END -->
1083
1084
  ```
1084
1085
 
1085
- The slot markers MUST always be written — they are required for draft:index refresh to function.
1086
+ The slot markers MUST always be written — they are required for draft:init --graph-only refresh to function.
1086
1087
 
1087
1088
  ---
1088
1089
 
@@ -1209,11 +1210,11 @@ Fix: Add actual payload descriptions on arrows, `alt`/`opt` blocks for condition
1209
1210
 
1210
1211
  **FAILURE 3 — Empty Appendices:**
1211
1212
  Detection: Appendix B, C, or D tables have fewer than 10 data rows.
1212
- Fix: Cross-reference ALL data sources (Appendix B), ALL implementation outputs (Appendix C), and add 2-3 detailed sequence diagrams to Appendix D. Use graph data (`architecture.json` `.packages`/`.routes`) to enumerate exhaustively.
1213
+ Fix: Cross-reference ALL data sources (Appendix B), ALL implementation outputs (Appendix C), and add 2-3 detailed sequence diagrams to Appendix D. Use live engine queries (`get_architecture .packages`/`.routes`) to enumerate exhaustively.
1213
1214
 
1214
1215
  **FAILURE 4 — Missing Sub-Modules:**
1215
1216
  Detection: A module with 100+ source files (check graph data) has no Sub-Module Structure table.
1216
- Fix: Read `draft/graph/modules/{name}.jsonl`, group files by immediate sub-directory, and generate the table with file counts and one-line role descriptions per sub-directory.
1217
+ Fix: Query `scripts/tools/graph-arch.sh --repo .` or `scripts/tools/graph-callers.sh --symbol <name>`, group results by immediate sub-directory, and generate the table with file counts and one-line role descriptions per sub-directory.
1217
1218
 
1218
1219
  **FAILURE 4b — Shallow Sub-Module Treatment:**
1219
1220
  Detection: Large sub-modules (50+ files) listed only as table rows with no dedicated deep-dive subsection. Or ops/handler directories have no operation catalog.
@@ -11,8 +11,8 @@ Scan the codebase to discover recurring coding patterns and update `draft/guardr
11
11
 
12
12
  When `draft/graph/schema.yaml` exists, this skill **must** follow the graph-first lookup contract in [core/shared/graph-query.md](../../core/shared/graph-query.md) §Mandatory Lookup Contract. Use the graph to:
13
13
 
14
- 1. Enumerate a module's symbols/files via `scripts/tools/graph-callers.sh`/`graph-impact.sh` and `architecture.json` (preferred over `find`).
15
- 2. Prioritize hotspots from `draft/graph/hotspots.jsonl` — patterns in high-fanIn files are more impactful when learned.
14
+ 1. Enumerate a module's symbols/files via `scripts/tools/graph-callers.sh`/`graph-impact.sh` and `scripts/tools/graph-arch.sh --repo .` (preferred over `find`).
15
+ 2. Prioritize hotspots via `scripts/tools/hotspot-rank.sh --repo .` — patterns in high-fanIn files are more impactful when learned.
16
16
  3. For TS/Python/Go/C/C++, use `*-index.jsonl` to identify class/function definitions rather than re-discovering them via regex.
17
17
 
18
18
  Filesystem `find` for source discovery (Step 2.1) is permitted **as a complement** to the graph for languages not covered by indexes (e.g. Ruby, Java without ctags). Record the rationale in the Graph Usage Report.
@@ -246,15 +246,15 @@ git log --follow --oneline -1 -- {file_containing_pattern}
246
246
 
247
247
  ### 2.7: Graph-Aware Severity Enrichment
248
248
 
249
- If `draft/graph/hotspots.jsonl` exists, derive objective severity for all anti-pattern candidates based on the fanIn of files where the pattern was found.
249
+ If `draft/graph/schema.yaml` exists (engine live), derive objective severity for all anti-pattern candidates based on the fanIn of files where the pattern was found via `scripts/tools/hotspot-rank.sh --repo .`.
250
250
 
251
251
  For each anti-pattern candidate from Step 2.2:
252
- 1. Check if any evidence files appear in `draft/graph/hotspots.jsonl`
252
+ 1. Check if any evidence files appear in the hotspot output from `scripts/tools/hotspot-rank.sh --repo .`
253
253
  2. Take the highest fanIn value across all evidence files:
254
254
  - fanIn ≥ 10 → `graph_severity: critical` (breakage propagates to many callers)
255
255
  - fanIn 5–9 → `graph_severity: high`
256
256
  - fanIn 1–4 → `graph_severity: medium`
257
- - fanIn 0 or file not in hotspots.jsonl → `graph_severity: low`
257
+ - fanIn 0 or file not in hotspot output → `graph_severity: low`
258
258
  3. If no graph data exists → `graph_severity: unresolved`
259
259
 
260
260
  Collect all evidence files with fanIn ≥ 5 for the `high_fanin_files` field.
@@ -11,7 +11,7 @@ You are performing a lightweight, ad-hoc code review. This is the fast alternati
11
11
 
12
12
  When `draft/graph/schema.yaml` exists, this skill **must** follow the graph-first lookup contract in [core/shared/graph-query.md](../../core/shared/graph-query.md) §Mandatory Lookup Contract. Quick-review keeps the graph load light:
13
13
 
14
- 1. Always check `draft/graph/hotspots.jsonl` for every changed file (Step 2 blast-radius pre-check below).
14
+ 1. Always run `scripts/tools/hotspot-rank.sh --repo .` for every changed file (Step 2 blast-radius pre-check below).
15
15
  2. If a finding spans more than one file, run `scripts/tools/graph-callers.sh --repo . --symbol <name>` to enumerate the call sites before claiming "no other usages".
16
16
 
17
17
  Filesystem `grep` is reserved for source-text scans (literal strings, regex patterns). Symbol and caller discovery go through the graph.
@@ -68,9 +68,9 @@ Determine the diff to review:
68
68
  3. If commit range: `git diff <range>`
69
69
  4. Default: `git diff HEAD~1..HEAD` (last commit)
70
70
 
71
- ## Step 2: Blast Radius Pre-check (if `draft/graph/hotspots.jsonl` exists)
71
+ ## Step 2: Blast Radius Pre-check (if `draft/graph/schema.yaml` exists)
72
72
 
73
- Before the four-dimension review, check if any files in scope appear in `draft/graph/hotspots.jsonl`. If any file has a `fanIn` in the top 20% of the list, add this warning at the top of the review report:
73
+ Before the four-dimension review, run `scripts/tools/hotspot-rank.sh --repo .` and check if any files in scope appear in the output. If any file has a `fanIn` in the top 20% of the list, add this warning at the top of the review report:
74
74
 
75
75
  ```
76
76
  ⚠ HIGH IMPACT: {file} is a high-fanIn hotspot (fanIn={N}). Changes here propagate to many callers — review with extra care.
@@ -11,7 +11,7 @@ You are conducting a code review using Draft's Context-Driven Development method
11
11
 
12
12
  When `draft/graph/schema.yaml` exists, this skill **must** follow the graph-first lookup contract in [core/shared/graph-query.md](../../core/shared/graph-query.md) §Mandatory Lookup Contract. Stage 1 (Automated Validation) **starts from the graph**:
13
13
 
14
- 1. Run blast-radius assessment from `draft/graph/hotspots.jsonl` and `scripts/tools/graph-impact.sh` (see Stage 1).
14
+ 1. Run blast-radius assessment via `scripts/tools/hotspot-rank.sh --repo .` and `scripts/tools/graph-impact.sh` (see Stage 1).
15
15
  2. For each changed file with non-trivial diff size, run `scripts/tools/graph-impact.sh --repo . --file <path>` to obtain the affected module set deterministically.
16
16
  3. For each public symbol modified, run `scripts/tools/graph-callers.sh --repo . --symbol <name>` to enumerate downstream callers before judging breaking-change severity.
17
17
 
@@ -370,18 +370,18 @@ For the files changed in the diff, perform static checks using `grep` or similar
370
370
 
371
371
  - **Blast Radius Assessment** (if the `draft/graph/` snapshot exists):
372
372
  - List all changed files from the diff
373
- - For each changed file, check if it appears in `hotspots.jsonl` — if yes, record its `fanIn` value
374
- - Classify: files with fanIn in the top 20% of the hotspots list = **HIGH IMPACT**; top 21–50% = **MEDIUM**; below 50% or not in list = **STANDARD**
375
- - For any file in a HIGH or MEDIUM module, check `architecture.json` `.packages[].fan_in` (how many modules depend on this module)
373
+ - For each changed file, check if it appears in `scripts/tools/hotspot-rank.sh --repo .` output — if yes, record its `fanIn` value
374
+ - Classify: files with fanIn in the top 20% of the hotspot output = **HIGH IMPACT**; top 21–50% = **MEDIUM**; below 50% or not in output = **STANDARD**
375
+ - For any file in a HIGH or MEDIUM module, query `scripts/tools/graph-arch.sh --repo . | jq '.packages[].fan_in'` (how many modules depend on this module)
376
376
  - Include a `Blast Radius` line in the Stage 1 report summary: `Blast Radius: HIGH | MEDIUM | STANDARD — <N> changed files affect high-fanIn modules: [file list]`
377
377
  - If any changed file is HIGH IMPACT: escalate Stage 3 thoroughness (check all callers of changed functions) and note this in the report header
378
378
  - **Architecture Conformance:** Search for pattern violations documented in `draft/.ai-context.md`. (e.g. `import * from 'database'` in a React component).
379
379
  - **Dead Code:** Check for newly exported functions/classes in the diff that have 0 references across the codebase.
380
380
  - **Dependency Cycles:** Trace the import chains for new imports to ensure no circular dependencies (e.g., A → B → C → A) are introduced.
381
- - **Graph Boundary Check** (if `draft/graph/architecture.json` exists) `[RC-013]`:
381
+ - **Graph Boundary Check** (if `draft/graph/schema.yaml` exists) `[RC-013]`:
382
382
  - For each changed file, identify its module from the graph
383
383
  - Check if any new cross-module includes were added in the diff
384
- - Verify they follow the established dependency direction from `architecture.json` package fan-in/out
384
+ - Verify they follow the established dependency direction from `scripts/tools/graph-arch.sh --repo .` package fan-in/out
385
385
  - Flag reverse-direction dependencies (module A now depends on module B, but only B→A existed before) as "Potential architecture violation — new dependency direction"
386
386
  - Check if changes introduce files in modules listed in graph cycles — flag as higher risk
387
387
  - **Security Scan** `[RC-001, RC-002, RC-003, RC-011]`:
@@ -1075,7 +1075,7 @@ If Jira ticket linked, sync via `core/shared/jira-sync.md`:
1075
1075
 
1076
1076
  Before printing the final verdict, internally verify and report:
1077
1077
 
1078
- 1. **Graph files queried** — which JSONL files were loaded (e.g. `architecture.json, hotspots.jsonl`) plus any live graph query-tool invocations (impact, callers, cycles).
1078
+ 1. **Graph data queried** — which live-engine tools were invoked (e.g. `get_architecture`, `hotspot-rank.sh`, `graph-impact.sh`, `graph-callers.sh`, `cycle-detect.sh`).
1079
1079
  2. **Layer 1 files deliberately skipped** — list any context sections skipped as irrelevant to the diff under review.
1080
1080
  3. **Filesystem grep fallback justification** — for every `grep`/`find` run, state the concept it searched for. Source-text scans (string literals, regex matches in code) are exempt — they are not symbol/file discovery.
1081
1081
 
@@ -11,8 +11,8 @@ You are conducting a technical debt analysis to catalog, prioritize, and plan re
11
11
 
12
12
  When `draft/graph/schema.yaml` exists, this skill **must** follow the graph-first lookup contract in [core/shared/graph-query.md](../../core/shared/graph-query.md) §Mandatory Lookup Contract. Tech-debt prioritization is fundamentally driven by graph data:
13
13
 
14
- 1. Load `draft/graph/hotspots.jsonl` — **rank candidates by `fanIn × complexity`** to surface high-leverage debt first.
15
- 2. Read `draft/graph/architecture.json` (`.packages`) and run `scripts/tools/cycle-detect.sh --repo .` — flag debt in modules involved in cycles as higher priority.
14
+ 1. Run `scripts/tools/hotspot-rank.sh --repo .` — **rank candidates by `fanIn × complexity`** to surface high-leverage debt first.
15
+ 2. Query `scripts/tools/graph-arch.sh --repo .` and run `scripts/tools/cycle-detect.sh --repo .` — flag debt in modules involved in cycles as higher priority.
16
16
  3. Run `scripts/tools/cycle-detect.sh --repo .` to enumerate dependency cycles — every cycle is a candidate architecture-debt entry.
17
17
  4. For each catalogued finding, run `scripts/tools/graph-impact.sh --repo . --file <path>` so the remediation plan includes blast-radius.
18
18