@drafthq/draft 2.8.3 → 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 (46) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +3 -3
  4. package/bin/README.md +13 -0
  5. package/core/methodology.md +17 -18
  6. package/core/shared/condensation.md +1 -1
  7. package/core/shared/draft-context-loading.md +4 -2
  8. package/core/shared/graph-query.md +4 -3
  9. package/core/templates/ai-context.md +1 -0
  10. package/core/templates/ai-profile.md +1 -0
  11. package/core/templates/architecture.md +1 -0
  12. package/core/templates/dependency-graph.md +2 -2
  13. package/core/templates/discovery.md +1 -0
  14. package/core/templates/guardrails.md +1 -0
  15. package/core/templates/hld.md +1 -0
  16. package/core/templates/lld.md +1 -0
  17. package/core/templates/plan.md +1 -0
  18. package/core/templates/product.md +1 -0
  19. package/core/templates/rca.md +1 -0
  20. package/core/templates/root-architecture.md +3 -3
  21. package/core/templates/root-product.md +2 -2
  22. package/core/templates/root-tech-stack.md +2 -2
  23. package/core/templates/service-index.md +3 -3
  24. package/core/templates/spec.md +1 -0
  25. package/core/templates/tech-matrix.md +2 -2
  26. package/core/templates/tech-stack.md +1 -0
  27. package/core/templates/workflow.md +1 -0
  28. package/integrations/agents/AGENTS.md +134 -918
  29. package/integrations/copilot/.github/copilot-instructions.md +134 -918
  30. package/package.json +1 -1
  31. package/scripts/lib.sh +4 -1
  32. package/scripts/tools/graph-init.sh +187 -0
  33. package/scripts/tools/graph-snapshot.sh +6 -1
  34. package/scripts/tools/okf-bundle.sh +141 -0
  35. package/scripts/tools/okf-check.sh +137 -0
  36. package/scripts/tools/okf-emit.sh +161 -0
  37. package/scripts/tools/skill-caps.conf +0 -1
  38. package/skills/GRAPH.md +7 -10
  39. package/skills/bughunt/SKILL.md +13 -0
  40. package/skills/discover/SKILL.md +2 -4
  41. package/skills/draft/SKILL.md +2 -2
  42. package/skills/draft/intent-mapping.md +3 -2
  43. package/skills/graph/SKILL.md +3 -3
  44. package/skills/init/SKILL.md +58 -19
  45. package/skills/init/references/architecture-spec.md +5 -5
  46. package/skills/index/SKILL.md +0 -848
@@ -0,0 +1,161 @@
1
+ #!/usr/bin/env bash
2
+ # okf-emit.sh — emit an Open Knowledge Format (OKF) bundle from a graph snapshot.
3
+ #
4
+ # OKF is an open, vendor-neutral spec (Google Cloud): a directory of markdown
5
+ # files with YAML frontmatter, one file per concept, where the file path is the
6
+ # concept's identity and concepts cross-link with normal markdown links. The
7
+ # only required frontmatter field is `type`. This makes Draft's knowledge graph
8
+ # portable — consumable by any OKF reader (visualizers, catalogs, other agents).
9
+ # https://cloud.google.com/blog/products/data-analytics/how-the-open-knowledge-format-can-improve-data-sharing
10
+ #
11
+ # Reads a graph snapshot's architecture.json and writes a conformant bundle:
12
+ # index.md type: Repository — bundle root + progressive disclosure
13
+ # modules/<slug>.md type: Module — one concept per package, cross-linked
14
+ #
15
+ # Degrades gracefully: with no packages/boundaries in the snapshot it still emits
16
+ # index.md (counts, languages, hotspots) and an empty modules/ directory.
17
+ #
18
+ # Usage: scripts/tools/okf-emit.sh [--repo DIR] [--snapshot DIR] [--out DIR]
19
+ # Exit codes: 0 OK, 1 invocation error, 2 snapshot/architecture.json unavailable.
20
+ set -euo pipefail
21
+
22
+ REPO="."
23
+ SNAPSHOT=""
24
+ OUT=""
25
+
26
+ usage() {
27
+ cat <<'EOF'
28
+ okf-emit.sh — emit an Open Knowledge Format (OKF) bundle from a graph snapshot.
29
+
30
+ Usage:
31
+ scripts/tools/okf-emit.sh [--repo DIR] [--snapshot DIR] [--out DIR]
32
+
33
+ Flags:
34
+ --repo DIR Repository root (default: cwd).
35
+ --snapshot DIR Snapshot dir holding architecture.json (default: <repo>/draft/graph).
36
+ --out DIR Bundle output dir (default: <snapshot>/okf).
37
+ --help Show this help.
38
+
39
+ Writes index.md + modules/<slug>.md (OKF v0.1). Exit 0 on success, 2 when no
40
+ architecture.json is available (nothing emitted).
41
+ EOF
42
+ }
43
+
44
+ while [[ $# -gt 0 ]]; do
45
+ case "$1" in
46
+ --repo) REPO="$2"; shift 2;;
47
+ --snapshot) SNAPSHOT="$2"; shift 2;;
48
+ --out) OUT="$2"; shift 2;;
49
+ --help|-h) usage; exit 0;;
50
+ -*) echo "Unknown flag: $1" >&2; usage >&2; exit 1;;
51
+ *) echo "Unexpected arg: $1" >&2; usage >&2; exit 1;;
52
+ esac
53
+ done
54
+
55
+ [[ -d "$REPO" ]] || { echo "ERROR: --repo '$REPO' is not a directory" >&2; exit 1; }
56
+ REPO_ABS="$(cd "$REPO" && pwd)"
57
+ SNAP="${SNAPSHOT:-$REPO_ABS/draft/graph}"
58
+ ARCH="$SNAP/architecture.json"
59
+ OUT="${OUT:-$SNAP/okf}"
60
+
61
+ command -v jq >/dev/null 2>&1 || { echo "jq required for OKF emit" >&2; exit 2; }
62
+ [[ -f "$ARCH" ]] || { echo "no architecture.json at $ARCH — nothing to emit" >&2; exit 2; }
63
+
64
+ # slugify a concept name into a filesystem- and link-safe identifier.
65
+ slug() {
66
+ local s
67
+ s="$(printf '%s' "$1" | tr '[:upper:]' '[:lower:]' \
68
+ | sed -e 's#[^a-z0-9]\{1,\}#-#g' -e 's#^-##' -e 's#-$##')"
69
+ [[ -n "$s" ]] || s="module"
70
+ printf '%s' "$s"
71
+ }
72
+
73
+ # escape a value for a YAML double-quoted scalar.
74
+ yesc() {
75
+ local s="$1"
76
+ s="${s//\\/\\\\}"
77
+ s="${s//\"/\\\"}"
78
+ printf '%s' "$s"
79
+ }
80
+
81
+ TS="$(date -Iseconds 2>/dev/null || date)"
82
+ PROJECT="$(jq -r '.project // "repository"' "$ARCH")"
83
+ TOTAL_NODES="$(jq -r '.total_nodes // 0' "$ARCH")"
84
+ TOTAL_EDGES="$(jq -r '.total_edges // 0' "$ARCH")"
85
+
86
+ PKGS="$(jq -r '.packages[]? | [.name, (.node_count//0), (.fan_in//0), (.fan_out//0)] | @tsv' "$ARCH")"
87
+ BOUNDS="$(jq -r '.boundaries[]? | [.from, .to, (.call_count//0)] | @tsv' "$ARCH")"
88
+
89
+ mkdir -p "$OUT/modules"
90
+
91
+ # --- One concept file per package, cross-linked via boundaries ---
92
+ PKG_COUNT=0
93
+ if [[ -n "$PKGS" ]]; then
94
+ while IFS=$'\t' read -r name nc fi fo; do
95
+ [[ -n "$name" ]] || continue
96
+ PKG_COUNT=$((PKG_COUNT + 1))
97
+ s="$(slug "$name")"
98
+ {
99
+ printf -- '---\n'
100
+ printf 'type: Module\n'
101
+ printf 'title: "%s"\n' "$(yesc "$name")"
102
+ printf 'description: "Code module %s: %s nodes, fan-in %s, fan-out %s."\n' \
103
+ "$(yesc "$name")" "$nc" "$fi" "$fo"
104
+ printf 'tags: [module, knowledge-graph]\n'
105
+ printf 'timestamp: "%s"\n' "$TS"
106
+ printf -- '---\n\n'
107
+ printf '# %s\n\n' "$name"
108
+ printf 'Structural module derived from the knowledge graph. Nodes: %s, fan-in: %s, fan-out: %s.\n' \
109
+ "$nc" "$fi" "$fo"
110
+
111
+ # Depends on (outbound boundaries)
112
+ outs="$(awk -F'\t' -v n="$name" '$1==n && $2!="" {print $2"\t"$3}' <<< "$BOUNDS")"
113
+ if [[ -n "$outs" ]]; then
114
+ printf '\n## Depends on\n\n'
115
+ while IFS=$'\t' read -r to cc; do
116
+ [[ -n "$to" ]] || continue
117
+ printf -- '- [%s](%s.md) — %s call(s)\n' "$to" "$(slug "$to")" "$cc"
118
+ done <<< "$outs"
119
+ fi
120
+
121
+ # Depended on by (inbound boundaries)
122
+ ins="$(awk -F'\t' -v n="$name" '$2==n && $1!="" {print $1"\t"$3}' <<< "$BOUNDS")"
123
+ if [[ -n "$ins" ]]; then
124
+ printf '\n## Depended on by\n\n'
125
+ while IFS=$'\t' read -r from cc; do
126
+ [[ -n "$from" ]] || continue
127
+ printf -- '- [%s](%s.md) — %s call(s)\n' "$from" "$(slug "$from")" "$cc"
128
+ done <<< "$ins"
129
+ fi
130
+ } > "$OUT/modules/$s.md"
131
+ done <<< "$PKGS"
132
+ fi
133
+
134
+ # --- Bundle index.md (reserved file: no frontmatter, §6 progressive disclosure) ---
135
+ {
136
+ printf '# %s\n\n' "$PROJECT"
137
+ printf 'Open Knowledge Format bundle generated by Draft from the codebase-memory-mcp knowledge graph. Nodes: %s, edges: %s, modules: %s.\n' \
138
+ "$TOTAL_NODES" "$TOTAL_EDGES" "$PKG_COUNT"
139
+
140
+ langs="$(jq -r '.languages[]? | "* \(.language) - \(.file_count) file(s)"' "$ARCH")"
141
+ if [[ -n "$langs" ]]; then
142
+ printf '\n# Languages\n\n%s\n' "$langs"
143
+ fi
144
+
145
+ if [[ "$PKG_COUNT" -gt 0 ]]; then
146
+ printf '\n# Modules\n\n'
147
+ while IFS=$'\t' read -r name nc fi fo; do
148
+ [[ -n "$name" ]] || continue
149
+ printf -- '* [%s](modules/%s.md) - %s nodes, fan-in %s, fan-out %s\n' \
150
+ "$name" "$(slug "$name")" "$nc" "$fi" "$fo"
151
+ done < <(printf '%s\n' "$PKGS" | sort)
152
+ fi
153
+
154
+ hot="$(jq -r '.hotspots[:10][]? | "* \(.name) - fan-in \(.fan_in)"' "$ARCH")"
155
+ if [[ -n "$hot" ]]; then
156
+ printf '\n# Top hotspots\n\n%s\n' "$hot"
157
+ fi
158
+ } > "$OUT/index.md"
159
+
160
+ echo "OKF bundle written to $OUT (modules=$PKG_COUNT)"
161
+ exit 0
@@ -19,6 +19,5 @@ status 1300
19
19
  bughunt 1200
20
20
  new-track 1100
21
21
  review 1000
22
- index 900
23
22
  implement 900
24
23
  decompose 700
package/skills/GRAPH.md CHANGED
@@ -55,7 +55,6 @@ graph TD
55
55
  subgraph "Architecture"
56
56
  decompose["/draft:decompose"]
57
57
  adr["/draft:adr"]
58
- index["/draft:index"]
59
58
  tech-debt["/draft:tech-debt"]
60
59
  impact["/draft:impact"]
61
60
  end
@@ -96,7 +95,6 @@ graph TD
96
95
  init --> learn
97
96
  init --> adr
98
97
  init --> bughunt
99
- init --> index
100
98
  init --> status
101
99
  init --> deep-review
102
100
  init --> debug
@@ -124,7 +122,6 @@ graph TD
124
122
  discover --> coverage
125
123
  discover --> testing-strategy
126
124
  discover --> learn
127
- discover --> index
128
125
  discover --> tour
129
126
  discover --> impact
130
127
  discover --> assist-review
@@ -178,8 +175,7 @@ graph TD
178
175
  impact -.->|reads graph| new-track
179
176
  impact -.->|reads graph| implement
180
177
 
181
- %% Monorepo chain
182
- init -.->|per-service| index
178
+ %% Monorepo: init is scope-aware — root build + module→root graph link (no separate index command)
183
179
  ```
184
180
 
185
181
  ## Dependency Matrix
@@ -193,7 +189,7 @@ graph TD
193
189
  | `implement` | init, new-track | review (triggers at phase boundaries) | Modifies source code; regenerates .ai-context.md |
194
190
  | `review` | init, new-track | implement (called at phase boundaries) | review-report-latest.md |
195
191
  | `quick-review` | init | review (fast alternative) | quick-review-report.md |
196
- | `bughunt` | init | review (optional), index (optional), jira (optional) | bughunt-report-latest.md |
192
+ | `bughunt` | init | review (optional), jira (optional) | bughunt-report-latest.md |
197
193
  | `deep-review` | init | -- | deep-review audit report |
198
194
  | `coverage` | init, new-track | -- | Regenerates .ai-context.md |
199
195
  | `testing-strategy` | init | coverage (informs), bughunt (informs) | testing-strategy.md |
@@ -248,7 +244,8 @@ deep-review ──→ tech-debt ──→ new-track (prioritized items)
248
244
 
249
245
  ### Monorepo Flow
250
246
  ```
251
- init (per-service) index (at root) aggregated context
247
+ init (root) whole-repo code-graph spine + sparse root map
248
+ init (sub-module) → module snapshot + root-link.json → cross-module context via the root spine
252
249
  ```
253
250
 
254
251
  ### Quality Audit Flow
@@ -280,15 +277,15 @@ init → learn → (updates guardrails.md)
280
277
 
281
278
  | Subroutine | Defined In | Called By |
282
279
  |------------|-----------|----------|
283
- | Condensation Subroutine (.ai-context.md regeneration) | `core/shared/condensation.md` | implement, decompose, coverage, index |
280
+ | Condensation Subroutine (.ai-context.md regeneration) | `core/shared/condensation.md` | implement, decompose, coverage |
284
281
  | Standard File Metadata (YAML frontmatter) | `init` | All skills that generate draft/ files |
285
282
  | Three-Stage Review | `review` | implement (at phase boundaries) |
286
- | Signal Classification | `init` | init refresh, index (future) |
283
+ | Signal Classification | `init` | init refresh |
287
284
  | Pattern Learning | `core/shared/pattern-learning.md` | learn, bughunt, review, deep-review (updates guardrails.md) |
288
285
  | Context Loading | `core/shared/draft-context-loading.md` | All skills requiring draft/ context |
289
286
  | Cross-Skill Dispatch | `core/shared/cross-skill-dispatch.md` | bughunt, deep-review, implement, review |
290
287
  | Jira Sync | `core/shared/jira-sync.md` | bughunt, review, implement (when ticket linked) |
291
- | Graph Query | `core/shared/graph-query.md` | init, implement, bughunt, review, debug, decompose, index, impact |
288
+ | Graph Query | `core/shared/graph-query.md` | init, implement, bughunt, review, debug, decompose, impact |
292
289
  | Graph Mermaid | `scripts/tools/mermaid-from-graph.sh` | init (injects module-deps + proto-map into architecture.md) |
293
290
 
294
291
  ## Artifact Flow
@@ -94,6 +94,19 @@ Use track context to:
94
94
 
95
95
  If no Draft context exists, proceed with code-only analysis.
96
96
 
97
+ ## Multi-Directory Mode (monorepo)
98
+
99
+ `/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).
100
+
101
+ 1. **Resolve targets:**
102
+ - **Explicit list** → use the given directories; verify each exists; skip (with a warning) any that lack a `draft/` directory.
103
+ - **Auto-discover** → immediate child directories containing a `draft/` folder, excluding `node_modules/`, `vendor/`, `.git/`, `draft/`, and dotfiles.
104
+ 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`.
105
+ 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.
106
+ 4. Report skipped directories (no `draft/`) and suggest running `/draft:init` in them first.
107
+
108
+ For a single target (the common case), skip this section and proceed.
109
+
97
110
  ## Dimension Applicability Check
98
111
 
99
112
  Before analyzing all 14 dimensions, determine which apply to this codebase:
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: discover
3
- description: "Primary router for discovery, debugging, investigation, quality, and exploration workflows. Analyzes user intent and dispatches to debug, bughunt, quick-review, deep-review, coverage, testing-strategy, learn, index, tour, impact, assist-review. The recommended entry point for any 'find out', 'check', 'review', or 'investigate' request."
3
+ description: "Primary router for discovery, debugging, investigation, quality, and exploration workflows. Analyzes user intent and dispatches to debug, bughunt, quick-review, deep-review, coverage, testing-strategy, learn, tour, impact, assist-review. The recommended entry point for any 'find out', 'check', 'review', or 'investigate' request."
4
4
  ---
5
5
 
6
6
  # Discover - Investigation & Quality Router
@@ -13,7 +13,6 @@ description: "Primary router for discovery, debugging, investigation, quality, a
13
13
  - Code quality reviews (lightweight to exhaustive to architectural)
14
14
  - Coverage analysis and test strategy design
15
15
  - Discovering and codifying project conventions
16
- - Monorepo indexing and context aggregation
17
16
  - Project tours, impact analysis, or reviewer assistance
18
17
 
19
18
  ## Routing Logic
@@ -29,7 +28,6 @@ Strong keyword and phrase matching with fallback to a menu when intent is broad
29
28
  | coverage, code coverage, test coverage report | `/draft:coverage` | Coverage measurement and gap report |
30
29
  | test strategy, testing plan, coverage targets, pyramid | `/draft:testing-strategy` | Test approach design |
31
30
  | learn patterns, discover conventions, update guardrails, anti-patterns | `/draft:learn` | Pattern mining + guardrail evolution |
32
- | index services, aggregate context, monorepo index | `/draft:index` | Monorepo service context aggregation |
33
31
  | tour, walkthrough, onboard me, getting started tour | `/draft:tour` | Guided interactive project tour |
34
32
  | blast radius, code impact, affected modules, downstream callers | `/draft:review` or `scripts/tools/graph-impact.sh` | Graph-derived blast-radius before merge |
35
33
  | impact, delivery telemetry, track analytics, CDD effectiveness | `/draft:impact` | Project-wide track delivery telemetry |
@@ -55,7 +53,7 @@ User: "learn the coding patterns in this repo and tighten guardrails"
55
53
 
56
54
  User: "index the monorepo so agents see all services"
57
55
 
58
- dispatches to `/draft:index --init-missing`
56
+ 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.
59
57
 
60
58
  ## Auto-Chains & Recommendations
61
59
 
@@ -39,7 +39,7 @@ The 5 router commands provide intent-based dispatch into the 20+ specialist comm
39
39
  | `/draft:plan` | Planning & architecture | new-track, decompose, adr, tech-debt, change |
40
40
  | `/draft:ops` | Operations & lifecycle | deploy-checklist, incident-response, standup, status, revert |
41
41
  | `/draft:docs` | Authoring | documentation |
42
- | `/draft:discover` | Investigation & quality | debug, bughunt, quick/deep-review, coverage, testing-strategy, learn, index, tour, impact, assist-review |
42
+ | `/draft:discover` | Investigation & quality | debug, bughunt, quick/deep-review, coverage, testing-strategy, learn, tour, impact, assist-review |
43
43
  | `/draft:jira` | Jira integration (preview, create, review) | - |
44
44
 
45
45
  ### Specialist Commands (leaf skills, invoked via routers or directly)
@@ -74,7 +74,7 @@ These commands remain available for targeted, specialist execution outside paren
74
74
 
75
75
  #### 4. Setup & Documentation
76
76
  * `/draft` - Display this command overview and help reference
77
- * `/draft:index` - Aggregate multi-service context in monorepo structures
77
+ * `/draft:init` - Single scope-aware entry point: builds the root-first code graph (`draft/graph/`) and project context; run at the repo root or inside any sub-module (monorepo context comes from running it at root)
78
78
  * `/draft:discover` - Phase 0 code-spike report (hotspots, mode flags, open questions) before spec freeze
79
79
  * `/draft:documentation` - Generate structured codebase documentation (API, Onboarding, Runbooks)
80
80
  * `/draft:tech-debt` - Audit technical debt across 6 key dimensions
@@ -33,5 +33,6 @@ Draft commands can be invoked using natural language. If you describe your goal
33
33
  | "write docs", "create readme", "api documentation" | `/draft:documentation` | Generate professional, structured docs |
34
34
  | "preview jira", "export jira issues", "jira draft" | `/draft:jira-preview` | Generate Jira markdown export from plan |
35
35
  | "create jira", "push to jira board" | `/draft:jira-create` | Create actual Jira issues via MCP integrations |
36
- | "index services", "aggregate context", "monorepo setup" | `/draft:index` | Aggregate multi-service context at the root |
37
- | "build graph", "refresh graph", "rebuild the knowledge graph", "index this repo's structure" | `/draft:graph` | Initialize/refresh the `draft/graph/` snapshot (optionally `draft graph <path>`) |
36
+ | "index services", "aggregate context", "monorepo setup" | `/draft:init` | Single entry point — run at the repo root to build the whole-repo code graph + sparse root map; run in a sub-module to link up to it |
37
+ | "build the code graph", "index this repo's structure", "graph memory only" | `/draft:init --graph-only` | Scope-aware, root-first code-graph build with no markdown |
38
+ | "build graph", "refresh graph", "rebuild the knowledge graph" | `/draft:graph` | Narrow refresh of the `draft/graph/` snapshot for one repo (optionally `draft graph <path>`) |
@@ -5,7 +5,7 @@ description: Initialize or refresh the knowledge-graph snapshot for a repository
5
5
 
6
6
  # Draft Graph
7
7
 
8
- 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`).
8
+ 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`.
9
9
 
10
10
  ## Red Flags - STOP if you're:
11
11
 
@@ -55,7 +55,7 @@ echo "Engine: $ENGINE"
55
55
 
56
56
  ## Step 3: Build / refresh the snapshot
57
57
 
58
- 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`.
58
+ 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).
59
59
 
60
60
  ```bash
61
61
  scripts/tools/graph-snapshot.sh --repo "$REPO_ABS"
@@ -92,7 +92,7 @@ Present a concise summary:
92
92
 
93
93
  Then point the user at the natural next steps:
94
94
 
95
- - To re-inject the refreshed diagrams/hotspot tables into `architecture.md` / `.ai-context.md`: run `/draft:index`.
95
+ - 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).
96
96
  - For a first-time full context bootstrap (architecture + profiles): run `/draft:init`.
97
97
 
98
98
  ## Graceful Degradation
@@ -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
@@ -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)
246
+
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.
240
248
 
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
249
+ Resolve **ROOT** = nearest ancestor (above the current dir) containing `draft/` → else the git toplevel → else the current dir. Then:
245
250
 
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)
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/` — the committed, git-tracked whole-repo memory.
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 `draft/graph/` is committed. The engine's `~/.cache` index is a disposable accelerator — 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,7 +511,7 @@ 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 the build succeeds, `draft/graph/` is populated and later steps consume the always-load artifacts + injection slots.
504
515
 
505
516
  ### 2. If graph build succeeds, load the always-load artifacts
506
517
 
@@ -1008,11 +1019,19 @@ The document is:
1008
1019
 
1009
1020
  **Full details, per-section guidance, provenance rules, and examples** live in:
1010
1021
  - `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
1022
  - `references/architecture-spec.md` (deprecated legacy notes — **10-section template wins on any conflict**)
1013
1023
 
1014
1024
  There is no legacy 28-section structure and no volume targets. The template itself is the contract.
1015
1025
 
1026
+ ### Root vs Module Markdown (scope asymmetry)
1027
+
1028
+ The depth of generated markdown depends on the scope resolved in **Scope Detection**:
1029
+
1030
+ - **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.
1031
+ - **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."
1032
+
1033
+ The graph is symmetric (root spine + per-module snapshots, linked); only the **prose** is asymmetric. Both consume `draft/graph/`.
1034
+
1016
1035
  **After completing analysis AND passing verification**, write to `draft/architecture.md`. This is the PRIMARY output. Then run the Condensation Subroutine.
1017
1036
 
1018
1037
  ## .ai-context.md Specification
@@ -1588,6 +1607,7 @@ Create `draft/tracks.md` with metadata header:
1588
1607
 
1589
1608
  ```markdown
1590
1609
  ---
1610
+ type: TrackIndex
1591
1611
  project: "{PROJECT_NAME}"
1592
1612
  module: "root"
1593
1613
  generated_by: "draft:init"
@@ -1633,6 +1653,23 @@ For **brownfield** projects, run `/draft:learn` (no arguments — full codebase
1633
1653
 
1634
1654
  ## Completion
1635
1655
 
1656
+ **Finalize OKF bundle:** After all `draft/` files are written, run the bundle tool
1657
+ to (re)generate the Open Knowledge Format root index so the whole `draft/` tree is
1658
+ a portable, vendor-neutral OKF bundle. This is the default — no flag required.
1659
+
1660
+ ```bash
1661
+ scripts/tools/okf-bundle.sh --dir draft # writes the bundle-root draft/index.md
1662
+ scripts/tools/okf-check.sh --dir draft # OKF v0.1 conformance (advisory, non-fatal)
1663
+ ```
1664
+
1665
+ `okf-bundle.sh` links every concept file present (`.ai-profile.md`, `.ai-context.md`,
1666
+ `architecture.md`, `product.md`, `tech-stack.md`, `workflow.md`, `guardrails.md`), the
1667
+ tracks, and the graph sub-bundle (`graph/okf/`). Concept `type:` frontmatter comes from
1668
+ the templates; `okf-check.sh` validates §9 conformance (frontmatter + `type` on every
1669
+ concept; reserved `index.md`/`log.md` structure). It is advisory — report the result,
1670
+ do not fail init. Note: operational reports later written into `draft/` (e.g.
1671
+ `deep-review-report.md`) are not OKF concepts and will be flagged.
1672
+
1636
1673
  **Finalize run memory:** Update `draft/.state/run-memory.json`:
1637
1674
  - `status`: `"completed"`
1638
1675
  - `completed_at`: current ISO timestamp
@@ -1642,6 +1679,7 @@ For **Brownfield** projects, announce:
1642
1679
  "Draft initialized successfully with comprehensive analysis!
1643
1680
 
1644
1681
  Created:
1682
+ - draft/index.md (Open Knowledge Format bundle root — cross-links every concept)
1645
1683
  - draft/.ai-profile.md (20-50 lines — ultra-compact always-injected profile, Tier 0)
1646
1684
  - draft/.ai-context.md (200-400 lines — token-optimized AI context, self-contained, Tier 1)
1647
1685
  - draft/architecture.md (comprehensive human-readable engineering reference, Tier 2)
@@ -1676,6 +1714,7 @@ For **Greenfield** projects, announce:
1676
1714
  "Draft initialized successfully!
1677
1715
 
1678
1716
  Created:
1717
+ - draft/index.md (Open Knowledge Format bundle root — cross-links every concept)
1679
1718
  - draft/product.md
1680
1719
  - draft/tech-stack.md
1681
1720
  - 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
 
@@ -1078,11 +1078,11 @@ If graph build succeeded and proto files exist (Step 1.4.7 completed), write the
1078
1078
  If graph binary was not found or no proto files exist, write the slot with placeholder:
1079
1079
  ```
1080
1080
  <!-- GRAPH:proto-map:START -->
1081
- [Graph data unavailable — run draft:index to populate after graph binary is installed]
1081
+ [Graph data unavailable — run draft:init --graph-only to populate after graph binary is installed]
1082
1082
  <!-- GRAPH:proto-map:END -->
1083
1083
  ```
1084
1084
 
1085
- The slot markers MUST always be written — they are required for draft:index refresh to function.
1085
+ The slot markers MUST always be written — they are required for draft:init --graph-only refresh to function.
1086
1086
 
1087
1087
  ---
1088
1088