@drafthq/draft 3.5.3 → 3.7.1

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 (143) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/.cursor-plugin/plugin.json +1 -1
  4. package/README.md +28 -49
  5. package/bin/README.md +47 -1
  6. package/cli/src/hosts/cursor.js +3 -0
  7. package/cli/src/installer.js +8 -4
  8. package/cli/src/lib/cursor-registry.js +10 -0
  9. package/cli/src/lib/fsx.js +3 -0
  10. package/cli/src/lib/marker.js +8 -3
  11. package/core/agents/architect.md +21 -9
  12. package/core/agents/debugger.md +5 -0
  13. package/core/agents/ops.md +7 -2
  14. package/core/agents/planner.md +7 -0
  15. package/core/agents/rca.md +14 -3
  16. package/core/agents/reviewer.md +1 -0
  17. package/core/agents/writer.md +6 -0
  18. package/core/knowledge-base.md +22 -3
  19. package/core/methodology.md +30 -5
  20. package/core/shared/condensation.md +28 -18
  21. package/core/shared/context-verify.md +3 -1
  22. package/core/shared/cross-skill-dispatch.md +7 -3
  23. package/core/shared/draft-context-loading.md +3 -0
  24. package/core/shared/git-report-metadata.md +2 -1
  25. package/core/shared/graph-query.md +24 -26
  26. package/core/shared/graph-usage-report.md +1 -1
  27. package/core/shared/jira-sync.md +10 -6
  28. package/core/shared/okf-retrieval.md +1 -1
  29. package/core/shared/parallel-analysis.md +14 -7
  30. package/core/shared/pattern-learning.md +2 -0
  31. package/core/shared/template-contract.md +1 -1
  32. package/core/shared/tool-resolver.md +20 -15
  33. package/core/shared/vcs-commands.md +5 -2
  34. package/core/templates/ai-context.md +3 -2
  35. package/core/templates/ai-profile.md +7 -0
  36. package/core/templates/architecture.md +6 -2
  37. package/core/templates/discovery.md +1 -1
  38. package/core/templates/guardrails.md +9 -0
  39. package/core/templates/hld.md +5 -4
  40. package/core/templates/intake-questions.md +45 -0
  41. package/core/templates/jira.md +11 -2
  42. package/core/templates/lld.md +8 -5
  43. package/core/templates/okf/concept.md +0 -1
  44. package/core/templates/plan.md +1 -1
  45. package/core/templates/product.md +11 -2
  46. package/core/templates/rca.md +6 -0
  47. package/core/templates/service-index.md +1 -0
  48. package/core/templates/spec.md +15 -0
  49. package/core/templates/tech-stack.md +12 -0
  50. package/core/templates/workflow.md +20 -0
  51. package/integrations/agents/AGENTS.md +1449 -817
  52. package/integrations/copilot/.github/copilot-instructions.md +1449 -817
  53. package/package.json +1 -1
  54. package/scripts/fetch-memory-engine.sh +25 -7
  55. package/scripts/lib.sh +90 -6
  56. package/scripts/tools/_graph_queries.sh +22 -8
  57. package/scripts/tools/_lib.sh +81 -11
  58. package/scripts/tools/adr-index.sh +1 -1
  59. package/scripts/tools/check-repo-size.sh +125 -0
  60. package/scripts/tools/check-skill-line-caps.sh +3 -4
  61. package/scripts/tools/check-template-noop.sh +0 -1
  62. package/scripts/tools/check-track-hygiene.sh +41 -21
  63. package/scripts/tools/classify-files.sh +3 -3
  64. package/scripts/tools/cycle-detect.sh +18 -17
  65. package/scripts/tools/detect-test-framework.sh +1 -1
  66. package/scripts/tools/emit-skill-metrics.sh +7 -2
  67. package/scripts/tools/fix-whitespace.sh +3 -0
  68. package/scripts/tools/freshness-check.sh +2 -2
  69. package/scripts/tools/git-metadata.sh +12 -6
  70. package/scripts/tools/graph-arch.sh +5 -11
  71. package/scripts/tools/graph-callers.sh +10 -15
  72. package/scripts/tools/graph-deps.sh +3 -10
  73. package/scripts/tools/graph-errors.sh +4 -11
  74. package/scripts/tools/graph-hierarchy.sh +4 -11
  75. package/scripts/tools/graph-impact.sh +21 -19
  76. package/scripts/tools/graph-init.sh +13 -9
  77. package/scripts/tools/graph-preflight.sh +4 -1
  78. package/scripts/tools/graph-query.sh +74 -18
  79. package/scripts/tools/graph-risk.sh +3 -10
  80. package/scripts/tools/graph-search.sh +4 -11
  81. package/scripts/tools/graph-snapshot.sh +38 -9
  82. package/scripts/tools/graph-snippet.sh +3 -10
  83. package/scripts/tools/graph-tests.sh +3 -10
  84. package/scripts/tools/graph-traces.sh +3 -10
  85. package/scripts/tools/hotspot-rank.sh +6 -12
  86. package/scripts/tools/install-smoke-test.sh +223 -0
  87. package/scripts/tools/mermaid-from-graph.sh +5 -11
  88. package/scripts/tools/migrate-track-frontmatter.sh +11 -10
  89. package/scripts/tools/okf-coverage-check.sh +8 -7
  90. package/scripts/tools/okf-emit-catalog.sh +256 -0
  91. package/scripts/tools/okf-fix-links.sh +251 -0
  92. package/scripts/tools/okf-plan-concepts.sh +242 -14
  93. package/scripts/tools/okf-render-views.sh +63 -21
  94. package/scripts/tools/okf-validate-all.sh +20 -9
  95. package/scripts/tools/okf-validate-quality.sh +15 -10
  96. package/scripts/tools/okf-validate.sh +20 -6
  97. package/scripts/tools/parse-git-log.sh +23 -5
  98. package/scripts/tools/parse-reports.sh +1 -1
  99. package/scripts/tools/render-track.sh +1 -1
  100. package/scripts/tools/resolve-tools.sh +24 -8
  101. package/scripts/tools/run-coverage.sh +1 -1
  102. package/scripts/tools/scan-markers.sh +4 -4
  103. package/scripts/tools/validate-frontmatter.sh +2 -2
  104. package/scripts/tools/verify-citations.sh +3 -4
  105. package/scripts/tools/verify-doc-anchors.sh +14 -34
  106. package/scripts/tools/verify-graph-binary.sh +15 -5
  107. package/skills/GRAPH.md +21 -10
  108. package/skills/adr/SKILL.md +25 -7
  109. package/skills/assist-review/SKILL.md +2 -1
  110. package/skills/bughunt/SKILL.md +55 -12
  111. package/skills/bughunt/references/regression-tests.md +14 -4
  112. package/skills/change/SKILL.md +19 -9
  113. package/skills/coverage/SKILL.md +28 -12
  114. package/skills/debug/SKILL.md +13 -3
  115. package/skills/decompose/SKILL.md +42 -12
  116. package/skills/deep-review/SKILL.md +19 -6
  117. package/skills/deploy-checklist/SKILL.md +10 -3
  118. package/skills/documentation/SKILL.md +12 -1
  119. package/skills/draft/SKILL.md +40 -29
  120. package/skills/draft/context-files.md +8 -1
  121. package/skills/draft/quality-guide.md +10 -2
  122. package/skills/graph/SKILL.md +2 -2
  123. package/skills/impact/SKILL.md +4 -2
  124. package/skills/implement/SKILL.md +62 -20
  125. package/skills/incident-response/SKILL.md +5 -2
  126. package/skills/init/SKILL.md +112 -30
  127. package/skills/init/references/architecture-spec.md +32 -8
  128. package/skills/init/references/okf-emitter.md +42 -78
  129. package/skills/jira/SKILL.md +33 -13
  130. package/skills/jira/references/review.md +61 -19
  131. package/skills/learn/SKILL.md +30 -7
  132. package/skills/new-track/SKILL.md +73 -18
  133. package/skills/quick-review/SKILL.md +8 -3
  134. package/skills/revert/SKILL.md +11 -5
  135. package/skills/review/SKILL.md +126 -27
  136. package/skills/review/references/zero-setup-mode.md +117 -0
  137. package/skills/standup/SKILL.md +10 -2
  138. package/skills/status/SKILL.md +7 -7
  139. package/skills/tech-debt/SKILL.md +9 -3
  140. package/skills/testing-strategy/SKILL.md +10 -2
  141. package/skills/tour/SKILL.md +2 -1
  142. package/skills/upload/SKILL.md +4 -3
  143. package/core/templates/track-architecture.md +0 -311
@@ -7,7 +7,7 @@ description: Incident management lifecycle — triage, communicate, mitigate, po
7
7
 
8
8
  You are managing an incident through its full lifecycle using structured incident management practices.
9
9
 
10
- ## Red Flags — STOP if you're:
10
+ ## Red Flags — STOP if you're
11
11
 
12
12
  - Fixing before communicating (stakeholders must know first)
13
13
  - Skipping severity classification
@@ -22,6 +22,7 @@ You are managing an incident through its full lifecycle using structured inciden
22
22
  ## Pre-Check
23
23
 
24
24
  1. Check for Draft context:
25
+
25
26
  ```bash
26
27
  ls draft/ 2>/dev/null
27
28
  ```
@@ -53,6 +54,7 @@ Classify severity:
53
54
  | **SEV4** | Next business day | Assigned engineer | Cosmetic issue, minor inconvenience |
54
55
 
55
56
  Assess:
57
+
56
58
  1. **What is broken?** (from description or Jira ticket)
57
59
  2. **Who is affected?** (from `draft/product.md` user types if available)
58
60
  3. **What is the blast radius?** (from `draft/.ai-context.md` service topology if available)
@@ -62,7 +64,7 @@ Assess:
62
64
 
63
65
  Generate initial status update:
64
66
 
65
- ```
67
+ ```yaml
66
68
  INCIDENT: {description}
67
69
  Severity: SEV{1-4}
68
70
  Impact: {who/what is affected}
@@ -228,6 +230,7 @@ Or track-scoped: `draft/tracks/<id>/postmortem.md`
228
230
  ### Step 5: Jira Sync
229
231
 
230
232
  Follow `core/shared/jira-sync.md`:
233
+
231
234
  - Attach postmortem to Jira ticket
232
235
  - Post comment: "[draft] Postmortem complete. Root cause: {1-line summary}. {N} action items."
233
236
 
@@ -7,7 +7,7 @@ description: "Initialize Draft project context for Context-Driven Development
7
7
 
8
8
  Initialize a Draft project for Context-Driven Development.
9
9
 
10
- ## Red Flags - STOP if you're:
10
+ ## Red Flags - STOP if you're
11
11
 
12
12
  - Re-initializing a project that already has `draft/` without using `refresh` mode
13
13
  - Skipping brownfield analysis for an existing codebase
@@ -31,7 +31,7 @@ Initialize a Draft project for Context-Driven Development.
31
31
  > **READ THIS BEFORE WRITING A SINGLE LINE OF architecture.md.**
32
32
  > The document MUST use the EXACT modern graph-primary structure below. Freeform sections, renamed headings, or missing mandatory sections are FAILURES. This is the single forward-looking format — no legacy 28-section or volume-oriented material is accepted.
33
33
 
34
- ```
34
+ ```text
35
35
  ## 1. Executive Summary + Graph Health Dashboard
36
36
  ## 2. Critical Invariants & Safety Rules (with provenance)
37
37
  ## 3. Primary Control & Data Flows (Graph + Synthesis)
@@ -55,6 +55,7 @@ Initialize a Draft project for Context-Driven Development.
55
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
59
  - Graph = authoritative modules, edges, public surfaces, hotspots, call relationships.
59
60
  - Your IDE/Agent index + full project understanding = semantic layer, workflow discovery, intent, and validation of the graph.
60
61
 
@@ -163,6 +164,7 @@ synced_to_commit: "{FULL_SHA}"
163
164
  ### Usage in Refresh
164
165
 
165
166
  The `synced_to_commit` field is critical for incremental refresh:
167
+
166
168
  - `/draft:init refresh` reads this field to find changed files since last sync
167
169
  - If `git.dirty: true`, warn user that docs may not reflect committed state
168
170
  - After refresh, update `synced_to_commit` to current HEAD
@@ -192,6 +194,7 @@ synced_to_commit: "a1b2c3d4e5f6789012345678901234567890abcd"
192
194
  ## Pre-Check
193
195
 
194
196
  Check for arguments:
197
+
195
198
  - `refresh`: Update existing context without full re-init
196
199
  - `--graph-only`: Build/refresh only the code-graph knowledge memory (no markdown) — see the fast path below
197
200
  - `--module-only`: When run in a sub-module, do not touch the root graph (the module→root link is marked `pending`)
@@ -218,13 +221,16 @@ The tier-gated default rests on **maintainability/readability** (one navigable c
218
221
 
219
222
  **OKF Completeness Verification (blocking — tier 3+ `okf` mode).** Completeness is enforced by tooling, not honor system, so the wiki is generated completely for every module/sub-module/component on every run. Before promoting `draft.tmp/` → `draft/`, ALL must hold (see `references/okf-emitter.md` for the pipeline):
220
223
 
221
- 1. `okf-plan-concepts.sh` ran and the expected/required/deferred counts were logged **before** any page was written (the concept boundary is a tool output, not an in-context guess).
222
- 2. Every `required` entry in `concept-plan.json` has a non-stub page.
223
- 3. `okf-validate-all.sh --plan … --strict` exits 0 (structure + per-type quality + coverage all pass).
224
- 4. `systems/coverage.md` was generated by tooling (verify the `<!-- okf:coverage-generated -->` marker) — **every** package/module the graph found is required by default (the fan-in floor only types Subsystem-vs-Module, it does not exempt), so none may be **MISSING**. Section `index.md` tables are regenerated by `okf-render-views.sh --section-indexes`, never hand-authored, so their links cannot dangle.
225
- 5. On any failure: **do not** atomic-rename; surface `.state/validation-report.json`.
224
+ 1. `okf-plan-concepts.sh` ran and counts were logged **before** any page was written. Plan discovery is language-aware: **Cargo workspace members / npm workspaces / Go modules first**, then graph packages (noise-filtered), then heuristic dirs. Log `discovery[]` (e.g. `cargo+graph`).
225
+ 2. `okf-emit-catalog.sh` ran so every REQUIRED plan entry has at least a minimum non-stub catalog page (LLM deep-dives may enrich top hotspots afterward).
226
+ 3. Every `required` entry in `concept-plan.json` has a non-stub page.
227
+ 4. `okf-render-views.sh` + `okf-fix-links.sh --fix` produced `architecture.md` with resolving `wiki/…` links and GFM TOC anchors.
228
+ 5. `okf-validate-all.sh --plan --strict` exits 0 (**quality coverage → structure**; structure runs last so coverage.md rewrites are checked).
229
+ 6. `okf-fix-links.sh --draft draft.tmp --check` exits 0 (zero dead links in architecture / wiki views).
230
+ 7. `systems/coverage.md` has the `<!-- okf:coverage-generated -->` marker; section indexes were regenerated by `okf-render-views.sh --section-indexes`.
231
+ 8. On any failure: **do not** atomic-rename; surface `.state/validation-report.json`.
226
232
 
227
- > **Red flag:** writing concept pages without first running `okf-plan-concepts.sh`, or finishing generation while any `required` plan entry is unwritten, is a **completeness failure** — not a stylistic one.
233
+ > **Red flag:** writing concept pages without first running `okf-plan-concepts.sh` + `okf-emit-catalog.sh`, or finishing while any `required` plan entry is unwritten, is a **completeness failure** — not a stylistic one.
228
234
 
229
235
  ### Route Explicit Modes Before Initialization
230
236
 
@@ -245,6 +251,7 @@ ls draft/ 2>/dev/null
245
251
  ```
246
252
 
247
253
  If `draft/` exists with context files:
254
+
248
255
  - Announce: "Project already initialized. Use `/draft:init refresh` to update context or `/draft:new-track` to create a feature."
249
256
  - Stop here.
250
257
 
@@ -283,11 +290,13 @@ Use `--module-only` to skip touching the root (the link is marked `pending` and
283
290
  ### Migration Detection
284
291
 
285
292
  If `draft/architecture.md` exists WITHOUT `draft/.ai-context.md`:
293
+
286
294
  - Announce: "Detected architecture.md without .ai-context.md. Would you like to generate .ai-context.md? This will condense your existing architecture.md into a token-optimized AI context file."
287
295
  - If user accepts: Run the Condensation Subroutine to derive `.ai-context.md` from existing `architecture.md`
288
296
  - If user declines: Continue without .ai-context.md
289
297
 
290
298
  If `draft/.ai-context.md` exists WITHOUT `draft/architecture.md`:
299
+
291
300
  - Announce: "Detected .ai-context.md without its source architecture.md. The derived file exists but its primary source is missing (may have been accidentally deleted). Recommend running `/draft:init refresh` to regenerate architecture.md from codebase analysis."
292
301
  - Do NOT delete the existing `.ai-context.md` — it still provides useful context until `architecture.md` is regenerated
293
302
 
@@ -298,16 +307,21 @@ If the user runs `/draft:init refresh`:
298
307
  **0. State-Aware Pre-Check** (before any refresh work):
299
308
 
300
309
  **a. Check for interrupted previous run:**
310
+
301
311
  ```bash
302
312
  cat draft/.state/run-memory.json 2>/dev/null
303
313
  ```
314
+
304
315
  If `status` is `"in_progress"`, offer to resume from `resumable_checkpoint` or start fresh.
305
316
 
306
317
  **b. Load freshness state (if available):**
318
+
307
319
  ```bash
308
320
  cat draft/.state/freshness.json 2>/dev/null
309
321
  ```
322
+
310
323
  If `freshness.json` exists, compute current file hashes and diff against stored hashes:
324
+
311
325
  - **Changed files**: Hash differs from stored → these files need re-analysis
312
326
  - **New files**: Present in current tree but not in stored → new modules/components to document
313
327
  - **Deleted files**: Present in stored but not in current tree → sections to prune
@@ -318,16 +332,20 @@ If the user runs `/draft:init refresh`:
318
332
  Stop here unless the user insists.
319
333
 
320
334
  **c. Load signal state (if available):**
335
+
321
336
  ```bash
322
337
  cat draft/.state/signals.json 2>/dev/null
323
338
  ```
339
+
324
340
  If `signals.json` exists, re-run signal classification (Phase 1 step 5) and diff against stored signals:
341
+
325
342
  - **New signal categories** (0→N): A new architectural concern appeared (e.g., auth files added for the first time). Flag these — new architecture.md sections may need to be generated.
326
343
  - **Removed signal categories** (N→0): An architectural concern was removed. Flag for section pruning.
327
344
  - **Signal count changes**: Significant growth (>50% increase) suggests the section needs deeper treatment.
328
345
 
329
346
  Report signal drift:
330
- ```
347
+
348
+ ```text
331
349
  Signal drift detected:
332
350
  NEW: auth_files (0 → 5) — §16 Security Architecture needs generation
333
351
  GROWN: backend_routes (12 → 24) — §12 API Definitions, §14 Cross-Module Integration need expansion
@@ -352,6 +370,7 @@ If the user runs `/draft:init refresh`:
352
370
  Otherwise (**`monolith` mode** — `draft/architecture.md` is the source of truth and no `draft/wiki/` exists), use metadata-based incremental analysis. If freshness state is available from step 0b, use file-level deltas to scope the refresh more precisely than git-diff alone:
353
371
 
354
372
  **a. Read synced commit from metadata:**
373
+
355
374
  ```bash
356
375
  # Extract synced_to_commit from YAML frontmatter
357
376
  SYNCED_SHA=$(grep "synced_to_commit:" draft/architecture.md | head -1 | sed 's/.*synced_to_commit:[[:space:]]*"\{0,1\}\([^"]*\)"\{0,1\}/\1/')
@@ -362,12 +381,15 @@ If the user runs `/draft:init refresh`:
362
381
  # Jump to step (i) — full refresh
363
382
  fi
364
383
  ```
384
+
365
385
  This returns the commit SHA the docs were last synced to (more reliable than file modification time). The SHA is validated before use to prevent silent failures in `git diff`.
366
386
 
367
387
  **b. Get changed files since that commit:**
388
+
368
389
  ```bash
369
390
  git diff --name-only <SYNCED_SHA> HEAD -- . ':!draft/'
370
391
  ```
392
+
371
393
  This lists all source files changed since the last architecture sync, excluding the draft/ directory itself.
372
394
 
373
395
  **c. Check if docs were generated with dirty state:**
@@ -408,9 +430,11 @@ If the user runs `/draft:init refresh`:
408
430
 
409
431
  **i. Fallback to full refresh:**
410
432
  If `synced_to_commit` is missing from metadata, or the commit SHA doesn't exist in git history:
433
+
411
434
  ```bash
412
435
  git cat-file -t <SYNCED_SHA> 2>/dev/null || echo "not found"
413
436
  ```
437
+
414
438
  If this returns "not found", run full 5-phase architecture discovery instead.
415
439
 
416
440
  - If `draft/architecture.md` does NOT exist and the project is brownfield, offer to generate it now
@@ -440,7 +464,8 @@ If the user runs `/draft:init refresh`:
440
464
  - **NEW**: Fact not previously recorded — add with full timestamps
441
465
  - **STALE**: Fact's source file was deleted — mark `last_active_at` as stale, reduce confidence
442
466
  3. **Generate Fact Evolution Report** — display summary to user:
443
- ```
467
+
468
+ ```text
444
469
  Fact Evolution Report:
445
470
  CONFIRMED: N facts unchanged
446
471
  UPDATED: N facts superseded (old → new)
@@ -448,6 +473,7 @@ If the user runs `/draft:init refresh`:
448
473
  NEW: N facts discovered
449
474
  STALE: N facts from deleted files
450
475
  ```
476
+
451
477
  4. **Update relationship edges** in `facts.json` knowledge graph
452
478
 
453
479
  3. **Product Refinement**: Ask if product vision/goals in `draft/product.md` need updates.
@@ -473,8 +499,10 @@ Classify and emit **Context Quality Report** (always, even if none found):
473
499
  - Low/None: Standard project.
474
500
 
475
501
  If High or Medium:
502
+
476
503
  - Emit terminal report with file list, sizes/signals, and explicit warning:
477
- ```
504
+
505
+ ```text
478
506
  Context Quality Report:
479
507
  High-quality agent-optimized docs detected:
480
508
  - CLAUDE.md (10k+ lines, purpose-built for AI coding assistants)
@@ -483,6 +511,7 @@ If High or Medium:
483
511
  Duplication risk: Generating a large parallel architecture.md can create divergence in safety-critical systems. Highest risk is inconsistent documentation, not insufficient volume.
484
512
  Action: architecture.md will be graph-primary (Full mode) with mandatory "Graph Coverage Gaps" and "Relationship to Existing Authoritative Documentation" sections. Strong cross-references + provenance tags required. Prose duplication of existing high-fidelity material is a verification failure.
485
513
  ```
514
+
486
515
  - Set internal flag `EXISTING_CONTEXT_QUALITY=high` (propagate to synthesis, writing, and Completion Verification steps).
487
516
  - Force §30 (Relationship) and §29 (Gaps) as non-skippable in later phases.
488
517
  - In Completion Verification: add explicit check that Relationship section defers appropriately and adds only graph-derived or synthesized value.
@@ -494,11 +523,13 @@ This audit ensures Draft is safe and effective for mature brownfield projects th
494
523
  Analyze the current directory to classify the project:
495
524
 
496
525
  **Brownfield (Existing)** indicators:
526
+
497
527
  - Has `package.json`, `requirements.txt`, `go.mod`, `Cargo.toml`, etc.
498
528
  - Has `src/`, `lib/`, or similar code directories
499
529
  - Has git history with commits
500
530
 
501
531
  **Greenfield (New)** indicators:
532
+
502
533
  - Empty or near-empty directory
503
534
  - Only has README or basic config
504
535
 
@@ -524,7 +555,7 @@ One command resolves ROOT, ensures the engine, builds the whole-repo spine, and
524
555
  ```bash
525
556
  # Locate Draft's bundled helpers (cwd is the user's project; ${CLAUDE_PLUGIN_ROOT}
526
557
  # is not exported into skill Bash). See core/shared/tool-resolver.md.
527
- DRAFT_TOOLS="$(cat ~/.cache/draft/plugin-root 2>/dev/null)/scripts/tools"
558
+ DRAFT_TOOLS="${DRAFT_PLUGIN_ROOT:-$(cat ~/.cache/draft/plugin-root 2>/dev/null)}/scripts/tools"
528
559
  [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$(ls -d ~/.claude/plugins/cache/*/draft/*/scripts/tools 2>/dev/null | sort -V | tail -1)"
529
560
  [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$(ls -d ~/.claude/plugins/marketplaces/*draft*/scripts/tools 2>/dev/null | tail -1)"
530
561
  [ -d "$DRAFT_TOOLS" ] || DRAFT_TOOLS="$PWD/scripts/tools"
@@ -577,6 +608,7 @@ ARCH=$("$DRAFT_TOOLS/graph-arch.sh" --repo .)
577
608
 
578
609
  **Step 1.4.5 — Compute Codebase Tier:**
579
610
  From the live `$ARCH` (above), extract:
611
+
580
612
  - `M = $ARCH | jq '.packages | length'` (modules)
581
613
  - `F = $ARCH | jq '[.node_labels[] | select(.label=="Function" or .label=="Method") | .count] | add // 0'` (functions+methods)
582
614
  - `P = $ARCH | jq '.routes | length'` (routes / RPCs)
@@ -606,11 +638,14 @@ Hold ranked list in memory — it replaces directory scanning for module discove
606
638
  Query for diagram content and write into architecture.md slots using the standard marker format.
607
639
 
608
640
  For Section 4.4 (module-deps slot):
641
+
609
642
  ```bash
610
643
  "$DRAFT_TOOLS/mermaid-from-graph.sh" --repo . --diagram module-deps
611
644
  ```
645
+
612
646
  The tool emits a ready-to-inject ` ```mermaid ``` ` block (or an empty stub on exit 2). Write between the markers:
613
- ```
647
+
648
+ ```text
614
649
  <!-- GRAPH:module-deps:START -->
615
650
  {mermaid block from the tool}
616
651
  <!-- GRAPH:module-deps:END -->
@@ -618,7 +653,8 @@ The tool emits a ready-to-inject ` ```mermaid ``` ` block (or an empty stub on e
618
653
 
619
654
  For Section 20 (hotspots slot):
620
655
  Run `"$DRAFT_TOOLS/hotspot-rank.sh" --repo . --top 10`, take the top 10 by fanIn, build a markdown table:
621
- ```
656
+
657
+ ```text
622
658
  <!-- GRAPH:hotspots:START -->
623
659
  | Symbol | fanIn |
624
660
  |--------|-------|
@@ -628,17 +664,20 @@ Run `"$DRAFT_TOOLS/hotspot-rank.sh" --repo . --top 10`, take the top 10 by fanIn
628
664
  ```
629
665
 
630
666
  For Appendix E (proto-map slot):
667
+
631
668
  ```bash
632
669
  "$DRAFT_TOOLS/mermaid-from-graph.sh" --repo . --diagram proto-map
633
670
  ```
671
+
634
672
  The tool emits a ` ```mermaid ``` ` block from detected routes (empty stub if none). Write:
635
- ```
673
+
674
+ ```text
636
675
  <!-- GRAPH:proto-map:START -->
637
676
  ```mermaid
638
677
  {diagram content}
639
678
  ```
640
679
  <!-- GRAPH:proto-map:END -->
641
- ```
680
+ ```text
642
681
 
643
682
  **If slot markers are absent** (first run on a repo that has no prior slot structure): write the slot content at the designated location in the template. The markers are always present in `core/templates/architecture.md`, so this path is only hit if a user has an older pre-slot architecture.md.
644
683
 
@@ -723,6 +762,7 @@ Use the modules-per-agent count from the tier table above (4 for tier 4/5; all m
723
762
 
724
763
  For each reader group, prepare a compact summary from graph artifacts:
725
764
  ```
765
+
726
766
  Modules: [execution, fill_processor, order_manager]
727
767
  Hotspot files:
728
768
  execution/engine.go (847 lines, fanIn=12)
@@ -731,7 +771,8 @@ Hotspot files:
731
771
  Module edges (from $ARCH .packages fan-in/out):
732
772
  execution → [risk, data, services]
733
773
  fill_processor → [execution, persistence]
734
- ```
774
+
775
+ ```text
735
776
 
736
777
  **Step 3: Spawn all reader agents in parallel using the Agent tool.**
737
778
 
@@ -747,11 +788,13 @@ Each reader agent:
747
788
 
748
789
  **Critical constraints to include in reader prompts:**
749
790
  ```
791
+
750
792
  MUST output IR JSON array only.
751
793
  MUST NOT write any documentation or architecture sections.
752
794
  MUST NOT read files outside assigned modules.
753
795
  Token budget: max 600 tokens per module in IR output.
754
- ```
796
+
797
+ ```text
755
798
 
756
799
  **Step 4: Collect and validate reader outputs.**
757
800
 
@@ -783,7 +826,9 @@ The synthesis agent:
783
826
 
784
827
  **Source reading policy for synthesis agent (enforce in prompt):**
785
828
  ```
829
+
786
830
  Read source (and aggressively use your full project index) for:
831
+
787
832
  - §6 Core Operational Flows — the most important system-level workflows, lifecycles, and state machines (this is the highest-ROI section for future coding accuracy)
788
833
  - §12 API / Interface surface
789
834
  - §14 Cross-module integration sequences
@@ -791,7 +836,8 @@ Read source (and aggressively use your full project index) for:
791
836
  - §18 Key Design Patterns
792
837
 
793
838
  All other sections: compose primarily from the graph + reader outputs + IR, with light additional reads only where needed for diagram accuracy.
794
- ```
839
+
840
+ ```text
795
841
 
796
842
  #### Phase 3: Parallel Finalization
797
843
 
@@ -993,7 +1039,7 @@ Follow these steps in order. The specific files to look for depend on the langua
993
1039
 
994
1040
  **Build a signal summary** (hold in memory for Phase 5):
995
1041
 
996
- ```
1042
+ ```text
997
1043
  Signal Classification:
998
1044
  backend_routes: 12 files → §12, §14 HIGH
999
1045
  services: 8 files → §5, §7 HIGH
@@ -1057,12 +1103,14 @@ Follow these steps in order. The specific files to look for depend on the langua
1057
1103
  Generate `draft/architecture.md` using the modern 10-section graph-primary structure defined in the **MANDATORY SECTION CHECKLIST** above and in `core/templates/architecture.md`.
1058
1104
 
1059
1105
  The document is:
1106
+
1060
1107
  - Primarily derived from the deterministic knowledge graph (`draft/graph/`).
1061
1108
  - Explicit about fidelity (frontmatter `graph:` block + Dashboard).
1062
1109
  - Required to carry provenance/fidelity tags on all significant claims.
1063
1110
  - Duplication-aware when high-quality agent docs (CLAUDE.md, INVARIANTS.md, etc.) are detected by the Context Audit.
1064
1111
 
1065
1112
  **Full details, per-section guidance, provenance rules, and examples** live in:
1113
+
1066
1114
  - `core/templates/architecture.md` (the source of truth for the 10 sections + Generation Contract)
1067
1115
  - `references/architecture-spec.md` (deprecated legacy notes — **10-section template wins on any conflict**)
1068
1116
 
@@ -1088,12 +1136,14 @@ Generate `draft/.ai-context.md` — a **machine-optimized** context file for AI/
1088
1136
  ### Design Principles
1089
1137
 
1090
1138
  This file is **NOT for humans**. It is optimized for:
1139
+
1091
1140
  1. **Token efficiency** — minimize tokens while maximizing information density
1092
1141
  2. **Machine parseability** — use consistent, structured formats that LLMs process efficiently
1093
1142
  3. **Self-containment** — complete context without referencing other files
1094
1143
  4. **Action-orientation** — everything an AI needs to make safe, correct code changes
1095
1144
 
1096
1145
  **Format choices**:
1146
+
1097
1147
  - Use YAML-like key-value pairs (not prose paragraphs)
1098
1148
  - Use arrow notation for graphs (not Mermaid)
1099
1149
  - Use compact tables with `|` separators
@@ -1191,33 +1241,40 @@ interface {Name} {
1191
1241
  ```
1192
1242
 
1193
1243
  ## CATALOG:{Category}
1244
+
1194
1245
  {id}|{type}|{file}|{purpose}
1195
1246
  {id}|{type}|{file}|{purpose}
1196
1247
 
1197
1248
  ## CATALOG:{AnotherCategory}
1249
+
1198
1250
  {id}|{type}|{file}|{purpose}
1199
1251
 
1200
1252
  ## THREADS
1253
+
1201
1254
  {pool_name}|{count}|{runs_what}
1202
1255
  {pool_name}|{count}|{runs_what}
1203
1256
 
1204
1257
  ## CONFIG
1258
+
1205
1259
  {param}|{default}|{critical:Y/N}|{purpose}
1206
1260
  {param}|{default}|{critical:Y/N}|{purpose}
1207
1261
 
1208
1262
  ## ERRORS
1263
+
1209
1264
  {scenario}: {recovery}
1210
1265
  {scenario}: {recovery}
1211
1266
  retry_policy: {policy}
1212
1267
  backoff: {strategy}
1213
1268
 
1214
1269
  ## CONCURRENCY
1270
+
1215
1271
  {component}: {rule} -> {violation_consequence}
1216
1272
  {component}: {rule} -> {violation_consequence}
1217
1273
  locks: [{lock1}@{file}, {lock2}@{file}]
1218
1274
  lock_order: {lock1} < {lock2} < {lock3}
1219
1275
 
1220
1276
  ## EXTEND:{ExtensionType}
1277
+
1221
1278
  create: {path/pattern}
1222
1279
  implement: {interface}@{file}
1223
1280
  required: [{method1}, {method2}]
@@ -1227,14 +1284,17 @@ deps: [{dep1}, {dep2}]
1227
1284
  test: {test_pattern}
1228
1285
 
1229
1286
  ## EXTEND:{AnotherType}
1287
+
1230
1288
  ...
1231
1289
 
1232
1290
  ## TEST
1291
+
1233
1292
  unit: {command}
1234
1293
  integration: {command}
1235
1294
  hooks: [{hook1}@{file}, {hook2}@{file}]
1236
1295
 
1237
1296
  ## FILES
1297
+
1238
1298
  entry: {path}
1239
1299
  config: {path}
1240
1300
  routes: {path}
@@ -1244,14 +1304,17 @@ tests: {path}
1244
1304
  build: {path}
1245
1305
 
1246
1306
  ## VOCAB
1307
+
1247
1308
  {term}: {definition}
1248
1309
  {term}: {definition}
1249
1310
 
1250
1311
  ## REFS
1312
+
1251
1313
  tech_stack: draft/tech-stack.md
1252
1314
  workflow: draft/workflow.md
1253
1315
  product: draft/product.md
1254
- ```
1316
+
1317
+ ```text
1255
1318
 
1256
1319
  ### Machine-Readable Graph Notation
1257
1320
 
@@ -1259,34 +1322,42 @@ Use these consistent notations for graphs:
1259
1322
 
1260
1323
  **Component hierarchy** (tree notation):
1261
1324
  ```
1325
+
1262
1326
  Root
1263
1327
  ├─Child1: purpose
1264
1328
  ├─Child2: purpose
1265
1329
  │ ├─Grandchild1: purpose
1266
1330
  │ └─Grandchild2: purpose
1267
1331
  └─Child3: purpose
1268
- ```
1332
+
1333
+ ```text
1269
1334
 
1270
1335
  **Dependency arrows** (directed graph):
1271
1336
  ```
1337
+
1272
1338
  A -[protocol]-> B # A depends on B via protocol
1273
1339
  A --> B # A depends on B (direct call)
1274
1340
  A -.-> B # A optionally depends on B
1275
1341
  A <--> B # bidirectional dependency
1276
- ```
1342
+
1343
+ ```text
1277
1344
 
1278
1345
  **Data flow** (pipeline notation):
1279
1346
  ```
1347
+
1280
1348
  Source --{DataType}--> Transform --{DataType}--> Sink
1281
1349
  |
1282
1350
  +--> Branch --{DataType}--> AlternateSink
1283
- ```
1351
+
1352
+ ```text
1284
1353
 
1285
1354
  **State transitions**:
1286
1355
  ```
1356
+
1287
1357
  State1 --(event)--> State2
1288
1358
  State2 --(event)--> State3 | State4 # conditional
1289
- ```
1359
+
1360
+ ```text
1290
1361
 
1291
1362
  ### Compression Techniques
1292
1363
 
@@ -1357,6 +1428,7 @@ After completing the 5-phase analysis:
1357
1428
  ```
1358
1429
 
1359
1430
  2. **Write `draft/architecture.md`** with this EXACT structure:
1431
+
1360
1432
  ```markdown
1361
1433
  ---
1362
1434
  project: "{PROJECT_NAME from above}"
@@ -1387,7 +1459,7 @@ After completing the 5-phase analysis:
1387
1459
 
1388
1460
  3. **Run Completion Verification (MANDATORY)** — Before proceeding to `.ai-context.md`, verify architecture.md meets signal-quality, fidelity, and duplication-aware requirements (volume is now guidance only, secondary to provenance and honesty):
1389
1461
 
1390
- ```
1462
+ ```text
1391
1463
  SIGNAL QUALITY & FIDELITY VERIFICATION (replaces volume proxy)
1392
1464
 
1393
1465
  Hard (blocking) checks — all must PASS:
@@ -1432,6 +1504,7 @@ After completing the 5-phase analysis:
1432
1504
  6. **Present for review**: Show the user a summary of what was discovered, including the Completion Verification scores, before proceeding to Step 2.
1433
1505
 
1434
1506
  **CRITICAL**:
1507
+
1435
1508
  - Do NOT skip the YAML frontmatter metadata block — it enables incremental refresh
1436
1509
  - Do NOT skip the Completion Verification — it catches shallow output before it becomes permanent
1437
1510
  - Generate architecture.md FIRST, verify it meets thresholds, then derive .ai-context.md, then .ai-profile.md
@@ -1481,6 +1554,7 @@ Extract atomic architectural facts discovered during Phases 1-5. Each fact is a
1481
1554
  ```
1482
1555
 
1483
1556
  **Fact categories:**
1557
+
1484
1558
  - `data-flow` — How data moves through the system
1485
1559
  - `architecture` — Structural patterns and module organization
1486
1560
  - `invariant` — Rules that must always hold true
@@ -1496,7 +1570,7 @@ Extract atomic architectural facts discovered during Phases 1-5. Each fact is a
1496
1570
 
1497
1571
  ### 1.7.1 Freshness State (`draft/.state/freshness.json`)
1498
1572
 
1499
- Compute SHA-256 hashes of all source files analyzed during Phases 1-5. This enables **file-level staleness detection** on subsequent refreshes — more granular than `synced_to_commit` which only detects that _some_ commits happened.
1573
+ Compute SHA-256 hashes of all source files analyzed during Phases 1-5. This enables **file-level staleness detection** on subsequent refreshes — more granular than `synced_to_commit` which only detects that *some* commits happened.
1500
1574
 
1501
1575
  ```bash
1502
1576
  # Generate SHA-256 hashes for all analyzed source files (exclude draft/, node_modules/, .git/, vendor/)
@@ -1590,6 +1664,7 @@ Persist run state for cross-session continuity. If `draft:init` is interrupted m
1590
1664
  **On completion:** Update `status` to `"completed"` and set `completed_at`. Keep `unresolved_questions` — these are surfaced to the user in the completion report and are valuable context for future refreshes.
1591
1665
 
1592
1666
  **On next invocation:** If `run-memory.json` exists with `status: "in_progress"`:
1667
+
1593
1668
  - Announce: "Detected incomplete previous run (started {started_at}, completed phases: {list}). Resume from {last_phase} or start fresh?"
1594
1669
  - If resume: Skip completed phases, continue from `resumable_checkpoint`
1595
1670
  - If fresh: Overwrite run memory and start from Phase 1
@@ -1616,6 +1691,7 @@ Present for approval, iterate if needed, then write to `draft/product.md`.
1616
1691
  ## Step 3: Tech Stack
1617
1692
 
1618
1693
  For Brownfield projects, auto-detect from:
1694
+
1619
1695
  - `package.json` → Node.js/TypeScript
1620
1696
  - `requirements.txt` / `pyproject.toml` → Python
1621
1697
  - `go.mod` → Go
@@ -1634,6 +1710,7 @@ Create `draft/workflow.md` using the template from `core/templates/workflow.md`.
1634
1710
  **Include the Standard File Metadata header at the top of the file.**
1635
1711
 
1636
1712
  Ask about:
1713
+
1637
1714
  - TDD preference (strict/flexible/none)
1638
1715
  - Commit style and frequency
1639
1716
  - Validation settings (auto-validate, blocking behavior)
@@ -1731,6 +1808,7 @@ Keep one-line descriptions accurate to what each file actually contains. This in
1731
1808
  the single committed entry point to the `draft/` bundle.
1732
1809
 
1733
1810
  **Finalize run memory:** Update `draft/.state/run-memory.json`:
1811
+
1734
1812
  - `status`: `"completed"`
1735
1813
  - `completed_at`: current ISO timestamp
1736
1814
  - Preserve `unresolved_questions` — these are displayed in the completion report below
@@ -1739,6 +1817,7 @@ For **Brownfield** projects, announce:
1739
1817
  "Draft initialized successfully with comprehensive analysis!
1740
1818
 
1741
1819
  Created:
1820
+
1742
1821
  - draft/index.md (plain docs index — navigable table of contents for the draft/ bundle)
1743
1822
  - draft/.ai-profile.md (20-50 lines — ultra-compact always-injected profile, Tier 0)
1744
1823
  - draft/.ai-context.md (200-400 lines — token-optimized AI context, self-contained, Tier 1)
@@ -1760,6 +1839,7 @@ Unresolved questions from analysis:
1760
1839
  {list each question — these are areas where the AI couldn't determine the answer with confidence}
1761
1840
 
1762
1841
  Next steps:
1842
+
1763
1843
  1. Review draft/product.md — verify product vision, users, and goals reflect current reality
1764
1844
  2. Review draft/tech-stack.md — verify languages, frameworks, and accepted patterns are accurate
1765
1845
  3. Review draft/workflow.md — verify TDD, commit, and review settings match your team's process
@@ -1774,6 +1854,7 @@ For **Greenfield** projects, announce:
1774
1854
  "Draft initialized successfully!
1775
1855
 
1776
1856
  Created:
1857
+
1777
1858
  - draft/index.md (plain docs index — navigable table of contents for the draft/ bundle)
1778
1859
  - draft/product.md
1779
1860
  - draft/tech-stack.md
@@ -1783,6 +1864,7 @@ Created:
1783
1864
  - draft/.state/run-memory.json (run metadata)
1784
1865
 
1785
1866
  Next steps:
1867
+
1786
1868
  1. Review draft/product.md — verify product vision, users, and goals reflect current reality
1787
1869
  2. Review draft/tech-stack.md — verify languages, frameworks, and accepted patterns are accurate
1788
1870
  3. Review draft/workflow.md — verify TDD, commit, and review settings match your team's process
@@ -1800,7 +1882,6 @@ A self-contained procedure for generating `draft/.ai-context.md` from `draft/arc
1800
1882
 
1801
1883
  After running condensation, also run the **Profile Generation Subroutine** below to regenerate `draft/.ai-profile.md`.
1802
1884
 
1803
-
1804
1885
  ## Profile Generation Subroutine
1805
1886
 
1806
1887
  This is a self-contained procedure for generating `draft/.ai-profile.md` from `draft/.ai-context.md`. Run after every Condensation Subroutine execution.
@@ -1818,6 +1899,7 @@ Read `draft/.ai-context.md`. Extract the YAML frontmatter metadata block.
1818
1899
  #### Step 2: Write YAML Frontmatter
1819
1900
 
1820
1901
  Start `draft/.ai-profile.md` with an updated YAML frontmatter block. Copy all `git.*` and `synced_to_commit` fields. Set:
1902
+
1821
1903
  - `generated_by`: the calling command (e.g., `draft:init`, `draft:implement`)
1822
1904
  - `generated_at`: current ISO 8601 timestamp
1823
1905
 
@@ -1851,7 +1933,7 @@ After initialization completes, suggest relevant follow-up skills based on proje
1851
1933
 
1852
1934
  If during architecture discovery (Step 1.5), anti-patterns or technical debt signals are detected in signal classification:
1853
1935
 
1854
- ```
1936
+ ```text
1855
1937
  "Detected architectural debt patterns in this codebase. Consider running:
1856
1938
  → /draft:tech-debt — Catalog and prioritize existing technical debt"
1857
1939
  ```
@@ -1860,7 +1942,7 @@ If during architecture discovery (Step 1.5), anti-patterns or technical debt sig
1860
1942
 
1861
1943
  At completion (Step 6), after announcing next steps, present categorized follow-up skills:
1862
1944
 
1863
- ```
1945
+ ```text
1864
1946
  What's Next:
1865
1947
  ─────────────────────────────
1866
1948
  Start building: