@drafthq/draft 3.6.0 → 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 (117) 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/installer.js +1 -1
  7. package/cli/src/lib/cursor-registry.js +10 -0
  8. package/core/agents/architect.md +21 -9
  9. package/core/agents/debugger.md +5 -0
  10. package/core/agents/ops.md +7 -2
  11. package/core/agents/planner.md +7 -0
  12. package/core/agents/rca.md +14 -3
  13. package/core/agents/reviewer.md +1 -0
  14. package/core/agents/writer.md +6 -0
  15. package/core/knowledge-base.md +22 -3
  16. package/core/methodology.md +30 -5
  17. package/core/shared/condensation.md +27 -17
  18. package/core/shared/context-verify.md +3 -1
  19. package/core/shared/cross-skill-dispatch.md +7 -3
  20. package/core/shared/draft-context-loading.md +3 -0
  21. package/core/shared/git-report-metadata.md +1 -0
  22. package/core/shared/graph-query.md +0 -2
  23. package/core/shared/graph-usage-report.md +1 -1
  24. package/core/shared/jira-sync.md +10 -6
  25. package/core/shared/okf-retrieval.md +1 -1
  26. package/core/shared/parallel-analysis.md +14 -7
  27. package/core/shared/pattern-learning.md +2 -0
  28. package/core/shared/template-contract.md +1 -1
  29. package/core/shared/vcs-commands.md +5 -2
  30. package/core/templates/ai-context.md +3 -2
  31. package/core/templates/ai-profile.md +7 -0
  32. package/core/templates/architecture.md +6 -2
  33. package/core/templates/discovery.md +1 -1
  34. package/core/templates/guardrails.md +9 -0
  35. package/core/templates/hld.md +5 -4
  36. package/core/templates/intake-questions.md +45 -0
  37. package/core/templates/jira.md +11 -2
  38. package/core/templates/lld.md +8 -5
  39. package/core/templates/okf/concept.md +0 -1
  40. package/core/templates/product.md +11 -2
  41. package/core/templates/rca.md +6 -0
  42. package/core/templates/service-index.md +1 -0
  43. package/core/templates/spec.md +15 -0
  44. package/core/templates/tech-stack.md +12 -0
  45. package/core/templates/workflow.md +20 -0
  46. package/integrations/agents/AGENTS.md +1272 -292
  47. package/integrations/copilot/.github/copilot-instructions.md +1272 -292
  48. package/package.json +1 -1
  49. package/scripts/fetch-memory-engine.sh +24 -6
  50. package/scripts/lib.sh +11 -4
  51. package/scripts/tools/_graph_queries.sh +10 -3
  52. package/scripts/tools/_lib.sh +33 -11
  53. package/scripts/tools/check-repo-size.sh +125 -0
  54. package/scripts/tools/check-skill-line-caps.sh +1 -2
  55. package/scripts/tools/check-template-noop.sh +0 -1
  56. package/scripts/tools/classify-files.sh +2 -2
  57. package/scripts/tools/cycle-detect.sh +16 -8
  58. package/scripts/tools/fix-whitespace.sh +3 -0
  59. package/scripts/tools/git-metadata.sh +6 -0
  60. package/scripts/tools/graph-arch.sh +1 -1
  61. package/scripts/tools/graph-callers.sh +6 -3
  62. package/scripts/tools/graph-impact.sh +4 -2
  63. package/scripts/tools/graph-init.sh +12 -8
  64. package/scripts/tools/graph-preflight.sh +3 -0
  65. package/scripts/tools/graph-query.sh +70 -7
  66. package/scripts/tools/graph-snapshot.sh +29 -5
  67. package/scripts/tools/hotspot-rank.sh +2 -1
  68. package/scripts/tools/install-smoke-test.sh +223 -0
  69. package/scripts/tools/mermaid-from-graph.sh +2 -1
  70. package/scripts/tools/migrate-track-frontmatter.sh +9 -10
  71. package/scripts/tools/okf-coverage-check.sh +4 -3
  72. package/scripts/tools/okf-fix-links.sh +18 -93
  73. package/scripts/tools/okf-plan-concepts.sh +5 -8
  74. package/scripts/tools/okf-render-views.sh +19 -14
  75. package/scripts/tools/okf-validate-quality.sh +13 -2
  76. package/scripts/tools/okf-validate.sh +13 -2
  77. package/scripts/tools/parse-git-log.sh +19 -1
  78. package/scripts/tools/resolve-tools.sh +24 -8
  79. package/scripts/tools/verify-citations.sh +1 -2
  80. package/scripts/tools/verify-doc-anchors.sh +13 -33
  81. package/scripts/tools/verify-graph-binary.sh +13 -3
  82. package/skills/GRAPH.md +21 -10
  83. package/skills/adr/SKILL.md +24 -6
  84. package/skills/assist-review/SKILL.md +2 -1
  85. package/skills/bughunt/SKILL.md +54 -11
  86. package/skills/bughunt/references/regression-tests.md +14 -4
  87. package/skills/change/SKILL.md +19 -9
  88. package/skills/coverage/SKILL.md +26 -10
  89. package/skills/debug/SKILL.md +12 -2
  90. package/skills/decompose/SKILL.md +39 -9
  91. package/skills/deep-review/SKILL.md +17 -4
  92. package/skills/deploy-checklist/SKILL.md +9 -2
  93. package/skills/documentation/SKILL.md +12 -1
  94. package/skills/draft/SKILL.md +40 -29
  95. package/skills/draft/context-files.md +8 -1
  96. package/skills/draft/quality-guide.md +10 -2
  97. package/skills/graph/SKILL.md +1 -1
  98. package/skills/impact/SKILL.md +3 -1
  99. package/skills/implement/SKILL.md +60 -18
  100. package/skills/incident-response/SKILL.md +5 -2
  101. package/skills/init/SKILL.md +102 -23
  102. package/skills/init/references/architecture-spec.md +31 -7
  103. package/skills/init/references/okf-emitter.md +3 -3
  104. package/skills/jira/SKILL.md +33 -13
  105. package/skills/jira/references/review.md +61 -19
  106. package/skills/learn/SKILL.md +29 -6
  107. package/skills/new-track/SKILL.md +73 -18
  108. package/skills/quick-review/SKILL.md +7 -2
  109. package/skills/revert/SKILL.md +11 -5
  110. package/skills/review/SKILL.md +123 -24
  111. package/skills/review/references/zero-setup-mode.md +117 -0
  112. package/skills/standup/SKILL.md +9 -1
  113. package/skills/status/SKILL.md +6 -6
  114. package/skills/tech-debt/SKILL.md +7 -1
  115. package/skills/testing-strategy/SKILL.md +10 -2
  116. package/skills/tour/SKILL.md +2 -1
  117. package/skills/upload/SKILL.md +3 -2
@@ -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`)
@@ -248,6 +251,7 @@ ls draft/ 2>/dev/null
248
251
  ```
249
252
 
250
253
  If `draft/` exists with context files:
254
+
251
255
  - Announce: "Project already initialized. Use `/draft:init refresh` to update context or `/draft:new-track` to create a feature."
252
256
  - Stop here.
253
257
 
@@ -286,11 +290,13 @@ Use `--module-only` to skip touching the root (the link is marked `pending` and
286
290
  ### Migration Detection
287
291
 
288
292
  If `draft/architecture.md` exists WITHOUT `draft/.ai-context.md`:
293
+
289
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."
290
295
  - If user accepts: Run the Condensation Subroutine to derive `.ai-context.md` from existing `architecture.md`
291
296
  - If user declines: Continue without .ai-context.md
292
297
 
293
298
  If `draft/.ai-context.md` exists WITHOUT `draft/architecture.md`:
299
+
294
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."
295
301
  - Do NOT delete the existing `.ai-context.md` — it still provides useful context until `architecture.md` is regenerated
296
302
 
@@ -301,16 +307,21 @@ If the user runs `/draft:init refresh`:
301
307
  **0. State-Aware Pre-Check** (before any refresh work):
302
308
 
303
309
  **a. Check for interrupted previous run:**
310
+
304
311
  ```bash
305
312
  cat draft/.state/run-memory.json 2>/dev/null
306
313
  ```
314
+
307
315
  If `status` is `"in_progress"`, offer to resume from `resumable_checkpoint` or start fresh.
308
316
 
309
317
  **b. Load freshness state (if available):**
318
+
310
319
  ```bash
311
320
  cat draft/.state/freshness.json 2>/dev/null
312
321
  ```
322
+
313
323
  If `freshness.json` exists, compute current file hashes and diff against stored hashes:
324
+
314
325
  - **Changed files**: Hash differs from stored → these files need re-analysis
315
326
  - **New files**: Present in current tree but not in stored → new modules/components to document
316
327
  - **Deleted files**: Present in stored but not in current tree → sections to prune
@@ -321,16 +332,20 @@ If the user runs `/draft:init refresh`:
321
332
  Stop here unless the user insists.
322
333
 
323
334
  **c. Load signal state (if available):**
335
+
324
336
  ```bash
325
337
  cat draft/.state/signals.json 2>/dev/null
326
338
  ```
339
+
327
340
  If `signals.json` exists, re-run signal classification (Phase 1 step 5) and diff against stored signals:
341
+
328
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.
329
343
  - **Removed signal categories** (N→0): An architectural concern was removed. Flag for section pruning.
330
344
  - **Signal count changes**: Significant growth (>50% increase) suggests the section needs deeper treatment.
331
345
 
332
346
  Report signal drift:
333
- ```
347
+
348
+ ```text
334
349
  Signal drift detected:
335
350
  NEW: auth_files (0 → 5) — §16 Security Architecture needs generation
336
351
  GROWN: backend_routes (12 → 24) — §12 API Definitions, §14 Cross-Module Integration need expansion
@@ -355,6 +370,7 @@ If the user runs `/draft:init refresh`:
355
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:
356
371
 
357
372
  **a. Read synced commit from metadata:**
373
+
358
374
  ```bash
359
375
  # Extract synced_to_commit from YAML frontmatter
360
376
  SYNCED_SHA=$(grep "synced_to_commit:" draft/architecture.md | head -1 | sed 's/.*synced_to_commit:[[:space:]]*"\{0,1\}\([^"]*\)"\{0,1\}/\1/')
@@ -365,12 +381,15 @@ If the user runs `/draft:init refresh`:
365
381
  # Jump to step (i) — full refresh
366
382
  fi
367
383
  ```
384
+
368
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`.
369
386
 
370
387
  **b. Get changed files since that commit:**
388
+
371
389
  ```bash
372
390
  git diff --name-only <SYNCED_SHA> HEAD -- . ':!draft/'
373
391
  ```
392
+
374
393
  This lists all source files changed since the last architecture sync, excluding the draft/ directory itself.
375
394
 
376
395
  **c. Check if docs were generated with dirty state:**
@@ -411,9 +430,11 @@ If the user runs `/draft:init refresh`:
411
430
 
412
431
  **i. Fallback to full refresh:**
413
432
  If `synced_to_commit` is missing from metadata, or the commit SHA doesn't exist in git history:
433
+
414
434
  ```bash
415
435
  git cat-file -t <SYNCED_SHA> 2>/dev/null || echo "not found"
416
436
  ```
437
+
417
438
  If this returns "not found", run full 5-phase architecture discovery instead.
418
439
 
419
440
  - If `draft/architecture.md` does NOT exist and the project is brownfield, offer to generate it now
@@ -443,7 +464,8 @@ If the user runs `/draft:init refresh`:
443
464
  - **NEW**: Fact not previously recorded — add with full timestamps
444
465
  - **STALE**: Fact's source file was deleted — mark `last_active_at` as stale, reduce confidence
445
466
  3. **Generate Fact Evolution Report** — display summary to user:
446
- ```
467
+
468
+ ```text
447
469
  Fact Evolution Report:
448
470
  CONFIRMED: N facts unchanged
449
471
  UPDATED: N facts superseded (old → new)
@@ -451,6 +473,7 @@ If the user runs `/draft:init refresh`:
451
473
  NEW: N facts discovered
452
474
  STALE: N facts from deleted files
453
475
  ```
476
+
454
477
  4. **Update relationship edges** in `facts.json` knowledge graph
455
478
 
456
479
  3. **Product Refinement**: Ask if product vision/goals in `draft/product.md` need updates.
@@ -476,8 +499,10 @@ Classify and emit **Context Quality Report** (always, even if none found):
476
499
  - Low/None: Standard project.
477
500
 
478
501
  If High or Medium:
502
+
479
503
  - Emit terminal report with file list, sizes/signals, and explicit warning:
480
- ```
504
+
505
+ ```text
481
506
  Context Quality Report:
482
507
  High-quality agent-optimized docs detected:
483
508
  - CLAUDE.md (10k+ lines, purpose-built for AI coding assistants)
@@ -486,6 +511,7 @@ If High or Medium:
486
511
  Duplication risk: Generating a large parallel architecture.md can create divergence in safety-critical systems. Highest risk is inconsistent documentation, not insufficient volume.
487
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.
488
513
  ```
514
+
489
515
  - Set internal flag `EXISTING_CONTEXT_QUALITY=high` (propagate to synthesis, writing, and Completion Verification steps).
490
516
  - Force §30 (Relationship) and §29 (Gaps) as non-skippable in later phases.
491
517
  - In Completion Verification: add explicit check that Relationship section defers appropriately and adds only graph-derived or synthesized value.
@@ -497,11 +523,13 @@ This audit ensures Draft is safe and effective for mature brownfield projects th
497
523
  Analyze the current directory to classify the project:
498
524
 
499
525
  **Brownfield (Existing)** indicators:
526
+
500
527
  - Has `package.json`, `requirements.txt`, `go.mod`, `Cargo.toml`, etc.
501
528
  - Has `src/`, `lib/`, or similar code directories
502
529
  - Has git history with commits
503
530
 
504
531
  **Greenfield (New)** indicators:
532
+
505
533
  - Empty or near-empty directory
506
534
  - Only has README or basic config
507
535
 
@@ -580,6 +608,7 @@ ARCH=$("$DRAFT_TOOLS/graph-arch.sh" --repo .)
580
608
 
581
609
  **Step 1.4.5 — Compute Codebase Tier:**
582
610
  From the live `$ARCH` (above), extract:
611
+
583
612
  - `M = $ARCH | jq '.packages | length'` (modules)
584
613
  - `F = $ARCH | jq '[.node_labels[] | select(.label=="Function" or .label=="Method") | .count] | add // 0'` (functions+methods)
585
614
  - `P = $ARCH | jq '.routes | length'` (routes / RPCs)
@@ -609,11 +638,14 @@ Hold ranked list in memory — it replaces directory scanning for module discove
609
638
  Query for diagram content and write into architecture.md slots using the standard marker format.
610
639
 
611
640
  For Section 4.4 (module-deps slot):
641
+
612
642
  ```bash
613
643
  "$DRAFT_TOOLS/mermaid-from-graph.sh" --repo . --diagram module-deps
614
644
  ```
645
+
615
646
  The tool emits a ready-to-inject ` ```mermaid ``` ` block (or an empty stub on exit 2). Write between the markers:
616
- ```
647
+
648
+ ```text
617
649
  <!-- GRAPH:module-deps:START -->
618
650
  {mermaid block from the tool}
619
651
  <!-- GRAPH:module-deps:END -->
@@ -621,7 +653,8 @@ The tool emits a ready-to-inject ` ```mermaid ``` ` block (or an empty stub on e
621
653
 
622
654
  For Section 20 (hotspots slot):
623
655
  Run `"$DRAFT_TOOLS/hotspot-rank.sh" --repo . --top 10`, take the top 10 by fanIn, build a markdown table:
624
- ```
656
+
657
+ ```text
625
658
  <!-- GRAPH:hotspots:START -->
626
659
  | Symbol | fanIn |
627
660
  |--------|-------|
@@ -631,17 +664,20 @@ Run `"$DRAFT_TOOLS/hotspot-rank.sh" --repo . --top 10`, take the top 10 by fanIn
631
664
  ```
632
665
 
633
666
  For Appendix E (proto-map slot):
667
+
634
668
  ```bash
635
669
  "$DRAFT_TOOLS/mermaid-from-graph.sh" --repo . --diagram proto-map
636
670
  ```
671
+
637
672
  The tool emits a ` ```mermaid ``` ` block from detected routes (empty stub if none). Write:
638
- ```
673
+
674
+ ```text
639
675
  <!-- GRAPH:proto-map:START -->
640
676
  ```mermaid
641
677
  {diagram content}
642
678
  ```
643
679
  <!-- GRAPH:proto-map:END -->
644
- ```
680
+ ```text
645
681
 
646
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.
647
683
 
@@ -726,6 +762,7 @@ Use the modules-per-agent count from the tier table above (4 for tier 4/5; all m
726
762
 
727
763
  For each reader group, prepare a compact summary from graph artifacts:
728
764
  ```
765
+
729
766
  Modules: [execution, fill_processor, order_manager]
730
767
  Hotspot files:
731
768
  execution/engine.go (847 lines, fanIn=12)
@@ -734,7 +771,8 @@ Hotspot files:
734
771
  Module edges (from $ARCH .packages fan-in/out):
735
772
  execution → [risk, data, services]
736
773
  fill_processor → [execution, persistence]
737
- ```
774
+
775
+ ```text
738
776
 
739
777
  **Step 3: Spawn all reader agents in parallel using the Agent tool.**
740
778
 
@@ -750,11 +788,13 @@ Each reader agent:
750
788
 
751
789
  **Critical constraints to include in reader prompts:**
752
790
  ```
791
+
753
792
  MUST output IR JSON array only.
754
793
  MUST NOT write any documentation or architecture sections.
755
794
  MUST NOT read files outside assigned modules.
756
795
  Token budget: max 600 tokens per module in IR output.
757
- ```
796
+
797
+ ```text
758
798
 
759
799
  **Step 4: Collect and validate reader outputs.**
760
800
 
@@ -786,7 +826,9 @@ The synthesis agent:
786
826
 
787
827
  **Source reading policy for synthesis agent (enforce in prompt):**
788
828
  ```
829
+
789
830
  Read source (and aggressively use your full project index) for:
831
+
790
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)
791
833
  - §12 API / Interface surface
792
834
  - §14 Cross-module integration sequences
@@ -794,7 +836,8 @@ Read source (and aggressively use your full project index) for:
794
836
  - §18 Key Design Patterns
795
837
 
796
838
  All other sections: compose primarily from the graph + reader outputs + IR, with light additional reads only where needed for diagram accuracy.
797
- ```
839
+
840
+ ```text
798
841
 
799
842
  #### Phase 3: Parallel Finalization
800
843
 
@@ -996,7 +1039,7 @@ Follow these steps in order. The specific files to look for depend on the langua
996
1039
 
997
1040
  **Build a signal summary** (hold in memory for Phase 5):
998
1041
 
999
- ```
1042
+ ```text
1000
1043
  Signal Classification:
1001
1044
  backend_routes: 12 files → §12, §14 HIGH
1002
1045
  services: 8 files → §5, §7 HIGH
@@ -1060,12 +1103,14 @@ Follow these steps in order. The specific files to look for depend on the langua
1060
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`.
1061
1104
 
1062
1105
  The document is:
1106
+
1063
1107
  - Primarily derived from the deterministic knowledge graph (`draft/graph/`).
1064
1108
  - Explicit about fidelity (frontmatter `graph:` block + Dashboard).
1065
1109
  - Required to carry provenance/fidelity tags on all significant claims.
1066
1110
  - Duplication-aware when high-quality agent docs (CLAUDE.md, INVARIANTS.md, etc.) are detected by the Context Audit.
1067
1111
 
1068
1112
  **Full details, per-section guidance, provenance rules, and examples** live in:
1113
+
1069
1114
  - `core/templates/architecture.md` (the source of truth for the 10 sections + Generation Contract)
1070
1115
  - `references/architecture-spec.md` (deprecated legacy notes — **10-section template wins on any conflict**)
1071
1116
 
@@ -1091,12 +1136,14 @@ Generate `draft/.ai-context.md` — a **machine-optimized** context file for AI/
1091
1136
  ### Design Principles
1092
1137
 
1093
1138
  This file is **NOT for humans**. It is optimized for:
1139
+
1094
1140
  1. **Token efficiency** — minimize tokens while maximizing information density
1095
1141
  2. **Machine parseability** — use consistent, structured formats that LLMs process efficiently
1096
1142
  3. **Self-containment** — complete context without referencing other files
1097
1143
  4. **Action-orientation** — everything an AI needs to make safe, correct code changes
1098
1144
 
1099
1145
  **Format choices**:
1146
+
1100
1147
  - Use YAML-like key-value pairs (not prose paragraphs)
1101
1148
  - Use arrow notation for graphs (not Mermaid)
1102
1149
  - Use compact tables with `|` separators
@@ -1194,33 +1241,40 @@ interface {Name} {
1194
1241
  ```
1195
1242
 
1196
1243
  ## CATALOG:{Category}
1244
+
1197
1245
  {id}|{type}|{file}|{purpose}
1198
1246
  {id}|{type}|{file}|{purpose}
1199
1247
 
1200
1248
  ## CATALOG:{AnotherCategory}
1249
+
1201
1250
  {id}|{type}|{file}|{purpose}
1202
1251
 
1203
1252
  ## THREADS
1253
+
1204
1254
  {pool_name}|{count}|{runs_what}
1205
1255
  {pool_name}|{count}|{runs_what}
1206
1256
 
1207
1257
  ## CONFIG
1258
+
1208
1259
  {param}|{default}|{critical:Y/N}|{purpose}
1209
1260
  {param}|{default}|{critical:Y/N}|{purpose}
1210
1261
 
1211
1262
  ## ERRORS
1263
+
1212
1264
  {scenario}: {recovery}
1213
1265
  {scenario}: {recovery}
1214
1266
  retry_policy: {policy}
1215
1267
  backoff: {strategy}
1216
1268
 
1217
1269
  ## CONCURRENCY
1270
+
1218
1271
  {component}: {rule} -> {violation_consequence}
1219
1272
  {component}: {rule} -> {violation_consequence}
1220
1273
  locks: [{lock1}@{file}, {lock2}@{file}]
1221
1274
  lock_order: {lock1} < {lock2} < {lock3}
1222
1275
 
1223
1276
  ## EXTEND:{ExtensionType}
1277
+
1224
1278
  create: {path/pattern}
1225
1279
  implement: {interface}@{file}
1226
1280
  required: [{method1}, {method2}]
@@ -1230,14 +1284,17 @@ deps: [{dep1}, {dep2}]
1230
1284
  test: {test_pattern}
1231
1285
 
1232
1286
  ## EXTEND:{AnotherType}
1287
+
1233
1288
  ...
1234
1289
 
1235
1290
  ## TEST
1291
+
1236
1292
  unit: {command}
1237
1293
  integration: {command}
1238
1294
  hooks: [{hook1}@{file}, {hook2}@{file}]
1239
1295
 
1240
1296
  ## FILES
1297
+
1241
1298
  entry: {path}
1242
1299
  config: {path}
1243
1300
  routes: {path}
@@ -1247,14 +1304,17 @@ tests: {path}
1247
1304
  build: {path}
1248
1305
 
1249
1306
  ## VOCAB
1307
+
1250
1308
  {term}: {definition}
1251
1309
  {term}: {definition}
1252
1310
 
1253
1311
  ## REFS
1312
+
1254
1313
  tech_stack: draft/tech-stack.md
1255
1314
  workflow: draft/workflow.md
1256
1315
  product: draft/product.md
1257
- ```
1316
+
1317
+ ```text
1258
1318
 
1259
1319
  ### Machine-Readable Graph Notation
1260
1320
 
@@ -1262,34 +1322,42 @@ Use these consistent notations for graphs:
1262
1322
 
1263
1323
  **Component hierarchy** (tree notation):
1264
1324
  ```
1325
+
1265
1326
  Root
1266
1327
  ├─Child1: purpose
1267
1328
  ├─Child2: purpose
1268
1329
  │ ├─Grandchild1: purpose
1269
1330
  │ └─Grandchild2: purpose
1270
1331
  └─Child3: purpose
1271
- ```
1332
+
1333
+ ```text
1272
1334
 
1273
1335
  **Dependency arrows** (directed graph):
1274
1336
  ```
1337
+
1275
1338
  A -[protocol]-> B # A depends on B via protocol
1276
1339
  A --> B # A depends on B (direct call)
1277
1340
  A -.-> B # A optionally depends on B
1278
1341
  A <--> B # bidirectional dependency
1279
- ```
1342
+
1343
+ ```text
1280
1344
 
1281
1345
  **Data flow** (pipeline notation):
1282
1346
  ```
1347
+
1283
1348
  Source --{DataType}--> Transform --{DataType}--> Sink
1284
1349
  |
1285
1350
  +--> Branch --{DataType}--> AlternateSink
1286
- ```
1351
+
1352
+ ```text
1287
1353
 
1288
1354
  **State transitions**:
1289
1355
  ```
1356
+
1290
1357
  State1 --(event)--> State2
1291
1358
  State2 --(event)--> State3 | State4 # conditional
1292
- ```
1359
+
1360
+ ```text
1293
1361
 
1294
1362
  ### Compression Techniques
1295
1363
 
@@ -1360,6 +1428,7 @@ After completing the 5-phase analysis:
1360
1428
  ```
1361
1429
 
1362
1430
  2. **Write `draft/architecture.md`** with this EXACT structure:
1431
+
1363
1432
  ```markdown
1364
1433
  ---
1365
1434
  project: "{PROJECT_NAME from above}"
@@ -1390,7 +1459,7 @@ After completing the 5-phase analysis:
1390
1459
 
1391
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):
1392
1461
 
1393
- ```
1462
+ ```text
1394
1463
  SIGNAL QUALITY & FIDELITY VERIFICATION (replaces volume proxy)
1395
1464
 
1396
1465
  Hard (blocking) checks — all must PASS:
@@ -1435,6 +1504,7 @@ After completing the 5-phase analysis:
1435
1504
  6. **Present for review**: Show the user a summary of what was discovered, including the Completion Verification scores, before proceeding to Step 2.
1436
1505
 
1437
1506
  **CRITICAL**:
1507
+
1438
1508
  - Do NOT skip the YAML frontmatter metadata block — it enables incremental refresh
1439
1509
  - Do NOT skip the Completion Verification — it catches shallow output before it becomes permanent
1440
1510
  - Generate architecture.md FIRST, verify it meets thresholds, then derive .ai-context.md, then .ai-profile.md
@@ -1484,6 +1554,7 @@ Extract atomic architectural facts discovered during Phases 1-5. Each fact is a
1484
1554
  ```
1485
1555
 
1486
1556
  **Fact categories:**
1557
+
1487
1558
  - `data-flow` — How data moves through the system
1488
1559
  - `architecture` — Structural patterns and module organization
1489
1560
  - `invariant` — Rules that must always hold true
@@ -1499,7 +1570,7 @@ Extract atomic architectural facts discovered during Phases 1-5. Each fact is a
1499
1570
 
1500
1571
  ### 1.7.1 Freshness State (`draft/.state/freshness.json`)
1501
1572
 
1502
- 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.
1503
1574
 
1504
1575
  ```bash
1505
1576
  # Generate SHA-256 hashes for all analyzed source files (exclude draft/, node_modules/, .git/, vendor/)
@@ -1593,6 +1664,7 @@ Persist run state for cross-session continuity. If `draft:init` is interrupted m
1593
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.
1594
1665
 
1595
1666
  **On next invocation:** If `run-memory.json` exists with `status: "in_progress"`:
1667
+
1596
1668
  - Announce: "Detected incomplete previous run (started {started_at}, completed phases: {list}). Resume from {last_phase} or start fresh?"
1597
1669
  - If resume: Skip completed phases, continue from `resumable_checkpoint`
1598
1670
  - If fresh: Overwrite run memory and start from Phase 1
@@ -1619,6 +1691,7 @@ Present for approval, iterate if needed, then write to `draft/product.md`.
1619
1691
  ## Step 3: Tech Stack
1620
1692
 
1621
1693
  For Brownfield projects, auto-detect from:
1694
+
1622
1695
  - `package.json` → Node.js/TypeScript
1623
1696
  - `requirements.txt` / `pyproject.toml` → Python
1624
1697
  - `go.mod` → Go
@@ -1637,6 +1710,7 @@ Create `draft/workflow.md` using the template from `core/templates/workflow.md`.
1637
1710
  **Include the Standard File Metadata header at the top of the file.**
1638
1711
 
1639
1712
  Ask about:
1713
+
1640
1714
  - TDD preference (strict/flexible/none)
1641
1715
  - Commit style and frequency
1642
1716
  - Validation settings (auto-validate, blocking behavior)
@@ -1734,6 +1808,7 @@ Keep one-line descriptions accurate to what each file actually contains. This in
1734
1808
  the single committed entry point to the `draft/` bundle.
1735
1809
 
1736
1810
  **Finalize run memory:** Update `draft/.state/run-memory.json`:
1811
+
1737
1812
  - `status`: `"completed"`
1738
1813
  - `completed_at`: current ISO timestamp
1739
1814
  - Preserve `unresolved_questions` — these are displayed in the completion report below
@@ -1742,6 +1817,7 @@ For **Brownfield** projects, announce:
1742
1817
  "Draft initialized successfully with comprehensive analysis!
1743
1818
 
1744
1819
  Created:
1820
+
1745
1821
  - draft/index.md (plain docs index — navigable table of contents for the draft/ bundle)
1746
1822
  - draft/.ai-profile.md (20-50 lines — ultra-compact always-injected profile, Tier 0)
1747
1823
  - draft/.ai-context.md (200-400 lines — token-optimized AI context, self-contained, Tier 1)
@@ -1763,6 +1839,7 @@ Unresolved questions from analysis:
1763
1839
  {list each question — these are areas where the AI couldn't determine the answer with confidence}
1764
1840
 
1765
1841
  Next steps:
1842
+
1766
1843
  1. Review draft/product.md — verify product vision, users, and goals reflect current reality
1767
1844
  2. Review draft/tech-stack.md — verify languages, frameworks, and accepted patterns are accurate
1768
1845
  3. Review draft/workflow.md — verify TDD, commit, and review settings match your team's process
@@ -1777,6 +1854,7 @@ For **Greenfield** projects, announce:
1777
1854
  "Draft initialized successfully!
1778
1855
 
1779
1856
  Created:
1857
+
1780
1858
  - draft/index.md (plain docs index — navigable table of contents for the draft/ bundle)
1781
1859
  - draft/product.md
1782
1860
  - draft/tech-stack.md
@@ -1786,6 +1864,7 @@ Created:
1786
1864
  - draft/.state/run-memory.json (run metadata)
1787
1865
 
1788
1866
  Next steps:
1867
+
1789
1868
  1. Review draft/product.md — verify product vision, users, and goals reflect current reality
1790
1869
  2. Review draft/tech-stack.md — verify languages, frameworks, and accepted patterns are accurate
1791
1870
  3. Review draft/workflow.md — verify TDD, commit, and review settings match your team's process
@@ -1803,7 +1882,6 @@ A self-contained procedure for generating `draft/.ai-context.md` from `draft/arc
1803
1882
 
1804
1883
  After running condensation, also run the **Profile Generation Subroutine** below to regenerate `draft/.ai-profile.md`.
1805
1884
 
1806
-
1807
1885
  ## Profile Generation Subroutine
1808
1886
 
1809
1887
  This is a self-contained procedure for generating `draft/.ai-profile.md` from `draft/.ai-context.md`. Run after every Condensation Subroutine execution.
@@ -1821,6 +1899,7 @@ Read `draft/.ai-context.md`. Extract the YAML frontmatter metadata block.
1821
1899
  #### Step 2: Write YAML Frontmatter
1822
1900
 
1823
1901
  Start `draft/.ai-profile.md` with an updated YAML frontmatter block. Copy all `git.*` and `synced_to_commit` fields. Set:
1902
+
1824
1903
  - `generated_by`: the calling command (e.g., `draft:init`, `draft:implement`)
1825
1904
  - `generated_at`: current ISO 8601 timestamp
1826
1905
 
@@ -1854,7 +1933,7 @@ After initialization completes, suggest relevant follow-up skills based on proje
1854
1933
 
1855
1934
  If during architecture discovery (Step 1.5), anti-patterns or technical debt signals are detected in signal classification:
1856
1935
 
1857
- ```
1936
+ ```text
1858
1937
  "Detected architectural debt patterns in this codebase. Consider running:
1859
1938
  → /draft:tech-debt — Catalog and prioritize existing technical debt"
1860
1939
  ```
@@ -1863,7 +1942,7 @@ If during architecture discovery (Step 1.5), anti-patterns or technical debt sig
1863
1942
 
1864
1943
  At completion (Step 6), after announcing next steps, present categorized follow-up skills:
1865
1944
 
1866
- ```
1945
+ ```text
1867
1946
  What's Next:
1868
1947
  ─────────────────────────────
1869
1948
  Start building: