bmad-module-skill-forge 0.2.0 → 0.3.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 (110) hide show
  1. package/README.md +88 -44
  2. package/docs/agents.md +1 -1
  3. package/docs/architecture.md +49 -20
  4. package/docs/examples.md +13 -2
  5. package/docs/getting-started.md +15 -13
  6. package/docs/index.md +3 -1
  7. package/docs/workflows.md +2 -2
  8. package/package.json +5 -3
  9. package/src/forger/forge-tier.yaml +1 -1
  10. package/src/forger/preferences.yaml +8 -1
  11. package/src/knowledge/doc-fetcher.md +55 -0
  12. package/src/knowledge/overview.md +17 -16
  13. package/src/knowledge/progressive-capability.md +9 -1
  14. package/src/knowledge/provenance-tracking.md +31 -23
  15. package/src/knowledge/qmd-registry.md +132 -0
  16. package/src/knowledge/skf-knowledge-index.csv +2 -0
  17. package/src/workflows/analyze-source/data/skill-brief-schema.md +24 -4
  18. package/src/workflows/analyze-source/steps-c/step-01-init.md +19 -9
  19. package/src/workflows/analyze-source/steps-c/step-01b-continue.md +2 -2
  20. package/src/workflows/analyze-source/steps-c/step-02-scan-project.md +10 -2
  21. package/src/workflows/analyze-source/steps-c/step-04-map-and-detect.md +17 -2
  22. package/src/workflows/analyze-source/steps-c/step-05-recommend.md +2 -1
  23. package/src/workflows/analyze-source/steps-c/step-06-generate-briefs.md +3 -3
  24. package/src/workflows/analyze-source/templates/analysis-report-template.md +1 -1
  25. package/src/workflows/analyze-source/validation-report.md +1 -1
  26. package/src/workflows/analyze-source/workflow-plan-analyze-source.md +1 -1
  27. package/src/workflows/analyze-source/workflow.md +1 -1
  28. package/src/workflows/audit-skill/steps-c/step-01-init.md +8 -5
  29. package/src/workflows/audit-skill/steps-c/step-02-re-index.md +12 -2
  30. package/src/workflows/audit-skill/validation-report.md +2 -2
  31. package/src/workflows/audit-skill/workflow-plan-audit-skill.md +1 -1
  32. package/src/workflows/brief-skill/data/scope-templates.md +60 -0
  33. package/src/workflows/brief-skill/data/skill-brief-schema.md +38 -3
  34. package/src/workflows/brief-skill/steps-c/step-01-gather-intent.md +20 -4
  35. package/src/workflows/brief-skill/steps-c/step-03-scope-definition.md +20 -64
  36. package/src/workflows/brief-skill/steps-c/step-04-confirm-brief.md +1 -1
  37. package/src/workflows/brief-skill/steps-c/step-05-write-brief.md +60 -5
  38. package/src/workflows/brief-skill/workflow.md +2 -1
  39. package/src/workflows/create-skill/data/compile-assembly-rules.md +110 -0
  40. package/src/workflows/create-skill/data/extraction-patterns.md +248 -0
  41. package/src/workflows/create-skill/data/skill-sections.md +79 -25
  42. package/src/workflows/create-skill/data/source-resolution-protocols.md +130 -0
  43. package/src/workflows/create-skill/steps-c/step-01-load-brief.md +7 -4
  44. package/src/workflows/create-skill/steps-c/step-02-ecosystem-check.md +10 -7
  45. package/src/workflows/create-skill/steps-c/step-03-extract.md +49 -9
  46. package/src/workflows/create-skill/steps-c/step-03b-fetch-temporal.md +238 -0
  47. package/src/workflows/create-skill/steps-c/step-03c-fetch-docs.md +220 -0
  48. package/src/workflows/create-skill/steps-c/step-04-enrich.md +40 -10
  49. package/src/workflows/create-skill/steps-c/step-05-compile.md +48 -81
  50. package/src/workflows/create-skill/steps-c/step-06-validate.md +149 -63
  51. package/src/workflows/create-skill/steps-c/step-07-generate-artifacts.md +53 -3
  52. package/src/workflows/create-skill/steps-c/step-08-report.md +1 -1
  53. package/src/workflows/create-skill/workflow-plan-create-skill.md +42 -10
  54. package/src/workflows/create-skill/workflow.md +3 -2
  55. package/src/workflows/create-stack-skill/data/stack-skill-template.md +20 -7
  56. package/src/workflows/create-stack-skill/steps-c/step-01-init.md +2 -2
  57. package/src/workflows/create-stack-skill/steps-c/step-04-parallel-extract.md +14 -0
  58. package/src/workflows/create-stack-skill/steps-c/step-06-compile-stack.md +28 -7
  59. package/src/workflows/create-stack-skill/steps-c/step-07-generate-output.md +10 -7
  60. package/src/workflows/create-stack-skill/steps-c/step-08-validate.md +66 -68
  61. package/src/workflows/create-stack-skill/validation-report.md +1 -1
  62. package/src/workflows/create-stack-skill/workflow-plan-create-stack-skill.md +4 -4
  63. package/src/workflows/export-skill/data/managed-section-format.md +1 -0
  64. package/src/workflows/export-skill/data/snippet-format.md +33 -14
  65. package/src/workflows/export-skill/steps-c/step-01-load-skill.md +16 -2
  66. package/src/workflows/export-skill/steps-c/step-03-generate-snippet.md +29 -22
  67. package/src/workflows/export-skill/steps-c/step-04-update-context.md +1 -1
  68. package/src/workflows/export-skill/steps-c/step-05-token-report.md +1 -1
  69. package/src/workflows/export-skill/validation-report.md +1 -1
  70. package/src/workflows/export-skill/workflow-plan-export-skill.md +8 -8
  71. package/src/workflows/quick-skill/data/skill-template.md +27 -7
  72. package/src/workflows/quick-skill/steps-c/step-04-compile.md +44 -13
  73. package/src/workflows/quick-skill/steps-c/step-05-validate.md +79 -16
  74. package/src/workflows/quick-skill/validation-report.md +4 -4
  75. package/src/workflows/quick-skill/workflow-plan-quick-skill.md +4 -4
  76. package/src/workflows/quick-skill/workflow.md +2 -0
  77. package/src/workflows/setup-forge/steps-c/step-01-detect-and-tier.md +12 -3
  78. package/src/workflows/setup-forge/steps-c/step-02-write-config.md +10 -2
  79. package/src/workflows/setup-forge/steps-c/step-03-auto-index.md +111 -40
  80. package/src/workflows/setup-forge/steps-c/step-04-report.md +13 -0
  81. package/src/workflows/setup-forge/workflow.md +1 -0
  82. package/src/workflows/test-skill/data/scoring-rules.md +14 -6
  83. package/src/workflows/test-skill/data/source-access-protocol.md +37 -0
  84. package/src/workflows/test-skill/steps-c/step-01-init.md +38 -13
  85. package/src/workflows/test-skill/steps-c/step-02-detect-mode.md +2 -3
  86. package/src/workflows/test-skill/steps-c/step-03-coverage-check.md +25 -5
  87. package/src/workflows/test-skill/steps-c/step-04-coherence-check.md +18 -43
  88. package/src/workflows/test-skill/steps-c/step-04b-external-validators.md +213 -0
  89. package/src/workflows/test-skill/steps-c/step-05-score.md +24 -27
  90. package/src/workflows/test-skill/steps-c/step-06-report.md +9 -4
  91. package/src/workflows/test-skill/templates/test-report-template.md +2 -1
  92. package/src/workflows/test-skill/validation-report.md +1 -1
  93. package/src/workflows/test-skill/workflow-plan-test-skill.md +7 -3
  94. package/src/workflows/test-skill/workflow.md +1 -1
  95. package/src/workflows/update-skill/data/remote-source-resolution.md +43 -0
  96. package/src/workflows/update-skill/steps-c/step-01-init.md +13 -7
  97. package/src/workflows/update-skill/steps-c/step-02-detect-changes.md +26 -0
  98. package/src/workflows/update-skill/steps-c/step-03-re-extract.md +37 -9
  99. package/src/workflows/update-skill/steps-c/step-04-merge.md +3 -3
  100. package/src/workflows/update-skill/steps-c/step-05-validate.md +63 -67
  101. package/src/workflows/update-skill/steps-c/step-06-write.md +37 -14
  102. package/src/workflows/update-skill/steps-c/step-07-report.md +1 -1
  103. package/src/workflows/update-skill/validation-report.md +4 -4
  104. package/src/workflows/update-skill/workflow-plan-update-skill.md +4 -4
  105. package/src/workflows/update-skill/workflow.md +1 -1
  106. package/tools/cli/commands/status.js +4 -4
  107. package/tools/cli/commands/uninstall.js +1 -1
  108. package/tools/cli/commands/update.js +2 -2
  109. package/tools/cli/lib/ui.js +60 -16
  110. package/tools/cli/lib/version-check.js +2 -2
@@ -1,8 +1,9 @@
1
1
  ---
2
2
  name: 'step-03-extract'
3
3
  description: 'Tier-dependent source code extraction — AST or source reading for exports, signatures, and types'
4
- nextStepFile: './step-04-enrich.md'
4
+ nextStepFile: './step-03b-fetch-temporal.md'
5
5
  extractionPatternsData: '../data/extraction-patterns.md'
6
+ sourceResolutionData: '../data/source-resolution-protocols.md'
6
7
  ---
7
8
 
8
9
  # Step 3: Extract
@@ -64,9 +65,21 @@ From the brief, apply scope and pattern filters:
64
65
  - `include_patterns` — file globs to include (if specified)
65
66
  - `exclude_patterns` — file globs to exclude (if specified)
66
67
 
67
- Build the filtered file list from the source tree resolved in step-01.
68
+ Build the filtered file list from the source tree resolved in step-01. Record the result: "**Filtered file count: {N} files in scope**" — this count is the input to the AST Extraction Protocol decision tree in the extraction patterns data file.
68
69
 
69
- ### 3. Execute Tier-Dependent Extraction
70
+ ### 3. Check for Docs-Only Mode
71
+
72
+ **If `source_type: "docs-only"` in the brief data:**
73
+
74
+ "**Docs-only mode:** No source code to extract. Documentation content will be fetched from `doc_urls` in step-03c."
75
+
76
+ Build an empty extraction inventory with zero exports. Set `extraction_mode: "docs-only"` in context. Auto-proceed through Gate 2 (section 5) — display the empty inventory and note that T3 content will be produced by the doc-fetcher step.
77
+
78
+ **If `source_type: "source"` (default):** Continue with extraction below.
79
+
80
+ ### 4. Execute Tier-Dependent Extraction
81
+
82
+ Load `{sourceResolutionData}` completely. Follow the **Remote Source Resolution** protocol for Forge/Deep tiers (ephemeral clone, sparse-checkout, cleanup) and the **Version Reconciliation** protocol for all tiers. Apply the protocols before proceeding with the tier-specific extraction strategy below.
70
83
 
71
84
  **Quick Tier (No AST tools):**
72
85
 
@@ -79,8 +92,13 @@ Build the filtered file list from the source tree resolved in step-01.
79
92
 
80
93
  **Forge/Deep Tier (AST available):**
81
94
 
95
+ ⚠️ **CRITICAL:** Before executing AST extraction, load the **AST Extraction Protocol** section from `{extractionPatternsData}`. Follow the decision tree based on the file count from step-01's file tree. This determines whether to use the MCP tool, scoped YAML rules, or CLI streaming. Never use `ast-grep --json` (without `=stream`) — it loads the entire result set into memory and will fail on large codebases.
96
+
82
97
  1. Detect language from brief or file extensions
83
- 2. Use `ast_bridge.scan_definitions(path, language)` for each file in scope
98
+ 2. Follow the AST Extraction Protocol decision tree from `{extractionPatternsData}`:
99
+ - ≤100 files: use `find_code()` MCP tool with `max_results` and `output_format="text"`
100
+ - ≤500 files: use `find_code_by_rule()` MCP tool with scoped YAML rules
101
+ - >500 files: use CLI `--json=stream` with line-by-line streaming Python — **CRITICAL:** inject the brief's `scope.exclude` patterns into the Python filter's `EXCLUDES` list (use `[]` if absent) so excluded files are discarded before consuming `head -N` slots (see template in extraction patterns data)
84
102
  3. For each export: extract function name, full signature, parameter types, return type, line number
85
103
  4. Use `ast_bridge.detect_co_imports(path, libraries[])` to find integration points
86
104
  5. Build extraction rules YAML data for reproducibility
@@ -88,14 +106,35 @@ Build the filtered file list from the source tree resolved in step-01.
88
106
 
89
107
  **If AST tool is unavailable at Forge/Deep tier:**
90
108
 
91
- Degrade to Quick tier extraction silently. Note the degradation in context for the evidence report.
109
+ ⚠️ **Warn the user explicitly:** "AST tools are unavailable — extraction will use source reading (T1-low). Run [SF] Setup Forge to detect and configure AST tools for T1 confidence."
110
+
111
+ Degrade to Quick tier extraction. Note the degradation reason in context for the evidence report.
92
112
 
93
113
  **For each file — handle failures gracefully:**
94
114
 
95
115
  - If a file cannot be read: log warning, skip file, continue with remaining files
96
116
  - If AST parsing fails on a file: fall back to source reading for that file, continue
97
117
 
98
- ### 4. Build Extraction Inventory
118
+ **Re-export tracing (Forge/Deep only):**
119
+
120
+ After the initial AST scan, check for public exports from the entry point (`__init__.py`, `index.ts`, `lib.rs`) that were NOT found by AST extraction. These are likely module-level re-exports. Follow the **Re-Export Tracing** protocol in `{extractionPatternsData}` to resolve them to their actual definition files. This ensures module re-export patterns (common in Python libraries with clean public APIs) do not create gaps in the extraction inventory.
121
+
122
+ ### 4b. Validate Exports Against Package Entry Point
123
+
124
+ After extraction, validate the collected exports against the package's actual public API surface:
125
+
126
+ - **Python:** Read `{source_root}/__init__.py` — extract all import statements to build the actual public export list. Compare against AST-extracted exports:
127
+ - In AST results but not in `__init__.py` → mark as internal (exclude from `metadata.json` exports, keep in provenance-map with a note)
128
+ - In `__init__.py` but not in AST results → flag as extraction gap (add to inventory, trace via re-export protocol)
129
+ - **TypeScript/JavaScript:** Read `index.ts`/`index.js` — extract named exports. Same comparison logic.
130
+ - **Rust:** Read `lib.rs` — extract `pub use` items. Same comparison logic.
131
+ - **Go:** Scan package-level files for exported (capitalized) identifiers.
132
+
133
+ Use the entry point as the authoritative source for `metadata.json`'s `exports[]` array. This prevents internal symbols from inflating the exports list and ensures all public API items are captured.
134
+
135
+ **If entry point is missing or unreadable:** Skip validation with a warning. Use the AST-extracted list as-is.
136
+
137
+ ### 5. Build Extraction Inventory
99
138
 
100
139
  Compile all extracted data into a structured inventory:
101
140
 
@@ -113,12 +152,13 @@ Compile all extracted data into a structured inventory:
113
152
  - Total exports found
114
153
  - Exports by type (functions, types/interfaces, constants)
115
154
  - Confidence breakdown (T1 count, T1-low count)
155
+ - `top_exports[]` — sorted list of the top 10-20 public API function names by prominence (import frequency or documentation position). This named field is consumed by step-03b for targeted temporal fetching and cache fingerprinting.
116
156
 
117
157
  **Co-import patterns (Forge/Deep only):**
118
158
  - Libraries commonly imported alongside extracted exports
119
159
  - Integration point suggestions
120
160
 
121
- ### 5. Present Extraction Summary (Gate 2)
161
+ ### 6. Present Extraction Summary (Gate 2)
122
162
 
123
163
  Display the extraction findings for user confirmation:
124
164
 
@@ -137,7 +177,7 @@ Display the extraction findings for user confirmation:
137
177
 
138
178
  Review the extraction summary above. Select an option to continue."
139
179
 
140
- ### 6. Present MENU OPTIONS
180
+ ### 7. Present MENU OPTIONS
141
181
 
142
182
  Display: "**Extraction Summary — Select an Option:** [C] Continue to compilation"
143
183
 
@@ -154,7 +194,7 @@ Display: "**Extraction Summary — Select an Option:** [C] Continue to compilati
154
194
 
155
195
  ## CRITICAL STEP COMPLETION NOTE
156
196
 
157
- ONLY WHEN the extraction inventory is built with provenance citations and the user has confirmed the extraction summary will you proceed to load `{nextStepFile}` for QMD enrichment.
197
+ ONLY WHEN the extraction inventory is built with provenance citations and the user has confirmed the extraction summary will you proceed to load `{nextStepFile}` for temporal context fetching.
158
198
 
159
199
  ---
160
200
 
@@ -0,0 +1,238 @@
1
+ ---
2
+ name: 'step-03b-fetch-temporal'
3
+ description: 'Fetch temporal context (issues, PRs, changelogs) and index into QMD — Deep tier only'
4
+ nextStepFile: './step-03c-fetch-docs.md'
5
+ ---
6
+
7
+ # Step 3b: Fetch Temporal Context
8
+
9
+ ## STEP GOAL:
10
+
11
+ To fetch temporal context (issues, PRs, changelogs, release notes) from the source repository and index it into a QMD collection for Deep tier enrichment. This ensures step-04 has historical data to search when annotating extracted functions with T2 provenance.
12
+
13
+ ## MANDATORY EXECUTION RULES (READ FIRST):
14
+
15
+ ### Universal Rules:
16
+
17
+ - 📖 CRITICAL: Read the complete step file before taking any action
18
+ - 🎯 ALWAYS follow the exact instructions in the step file
19
+ - ⚙️ TOOL/SUBPROCESS FALLBACK: If any instruction references a tool you do not have access to, you MUST still achieve the outcome in your main context thread
20
+ - ✅ YOU MUST ALWAYS SPEAK OUTPUT in your Agent communication style with the config `{communication_language}`
21
+
22
+ ### Role Reinforcement:
23
+
24
+ - ✅ You are a skill compilation engine fetching temporal data for QMD enrichment
25
+ - ✅ Temporal context is best-effort — failures never block the workflow
26
+ - ✅ Graceful degradation is paramount — non-GitHub repos or missing tools are silent skips, not errors
27
+
28
+ ### Step-Specific Rules:
29
+
30
+ - 🎯 Deep tier only — Quick and Forge tiers skip this step entirely and silently
31
+ - 🎯 GitHub repositories only — other source types degrade gracefully
32
+ - 🚫 FORBIDDEN to halt the workflow if fetching or indexing fails
33
+ - 🚫 FORBIDDEN to modify extraction data from step-03 — this step only creates QMD collections
34
+ - 💾 Write fetched content to a staging directory, index into QMD, then clean up
35
+
36
+ ## EXECUTION PROTOCOLS:
37
+
38
+ - 🎯 Follow MANDATORY SEQUENCE exactly
39
+ - 💾 Write fetched markdown files to a staging directory: `_bmad-output/{skill-name}-temporal/`
40
+ - 📖 Index the staging directory into QMD and register in `forge-tier.yaml`
41
+ - 🚫 Never leave staging files on disk after indexing — always clean up
42
+
43
+ ## CONTEXT BOUNDARIES:
44
+
45
+ - Available: brief_data, tier, source_location from step-01; extraction_inventory from step-03
46
+ - **Used from extraction_inventory:** `top_exports[]` — the list of top-level public API function names (typically 10-20). Used for targeted GitHub searches (section 3b).
47
+ - Focus: Creating a QMD temporal collection for the source repository
48
+ - Limits: Do NOT modify extraction data, begin enrichment, or compile content
49
+ - Dependencies: Extraction must be complete from step-03
50
+
51
+ ## MANDATORY SEQUENCE
52
+
53
+ **CRITICAL:** Follow this sequence exactly. Do not skip, reorder, or improvise.
54
+
55
+ ### 1. Check Eligibility
56
+
57
+ Evaluate the following conditions sequentially. **If ANY condition fails, skip silently to section 5 (auto-proceed) with no output:**
58
+
59
+ 1. **Tier is Deep:** If tier is Quick or Forge, skip silently.
60
+ 2. **Source is GitHub:** Verify `source_repo` is a GitHub URL (`https://github.com/...`) or `owner/repo` format. If the source is a local path, a non-GitHub URL, or any other format, skip silently.
61
+ 3. **`gh` CLI is available:** Run `gh auth status` to verify the CLI is installed and authenticated. If it fails, skip silently.
62
+
63
+ All three conditions must pass to proceed to section 2.
64
+
65
+ ### 2. Check Cache (Skip If Fresh)
66
+
67
+ Read `forge-tier.yaml` from the sidecar path.
68
+
69
+ - Look for a `qmd_collections` entry where `skill_name` matches the current brief AND `type` is `"temporal"`.
70
+ - If found AND `created_at` is within the last **7 days**: the temporal collection is fresh. Display:
71
+
72
+ "**Temporal context: cached.** Collection `{skill-name}-temporal` is fresh ({days} days old). Skipping re-fetch."
73
+
74
+ Skip to section 5 (auto-proceed).
75
+
76
+ - If not found OR `created_at` is older than 7 days: continue to section 3.
77
+
78
+ ### 3. Fetch Temporal Context
79
+
80
+ Create a staging directory: `_bmad-output/{skill-name}-temporal/`
81
+
82
+ Resolve the `owner` and `repo` from `source_repo` (e.g., `acme/toolkit` from `https://github.com/acme/toolkit`).
83
+
84
+ Execute the following fetches, writing output as markdown files to the staging directory. **If any individual fetch fails, log a warning and continue with the others:**
85
+
86
+ 1. **Issues (last 100):**
87
+
88
+ ```bash
89
+ gh issue list -R {owner}/{repo} --state all --limit 100 --json number,title,state,labels,createdAt,closedAt,body | ...
90
+ ```
91
+
92
+ Write to `{staging}/issues.md` — format as a markdown document with one section per issue (number, title, state, labels, body summary).
93
+
94
+ 2. **Merged PRs (last 100):**
95
+
96
+ ```bash
97
+ gh pr list -R {owner}/{repo} --state merged --limit 100 --json number,title,mergedAt,labels,body | ...
98
+ ```
99
+
100
+ Write to `{staging}/prs.md` — format as a markdown document with one section per PR.
101
+
102
+ 3. **Releases (last 10):**
103
+
104
+ **Note:** `gh release list --json` does **not** support the `body` field. Use a two-step approach: list tags first, then fetch each release individually with `--json` (which IS supported on `gh release view`).
105
+
106
+ ```bash
107
+ # Step 1: Get release tags (body NOT available here)
108
+ gh release list -R {owner}/{repo} --limit 10 --json tagName,name,publishedAt
109
+ ```
110
+
111
+ If Step 1 returns an empty array (no releases), skip Step 2 and omit the releases section entirely.
112
+
113
+ ```bash
114
+ # Step 2: For EACH tagName from Step 1, fetch the full release
115
+ gh release view {tagName} -R {owner}/{repo} --json tagName,name,publishedAt,body
116
+ ```
117
+
118
+ Iterate over every `tagName` from Step 1's JSON array. If `gh release view` fails for a specific tag, log a warning and skip that release — continue with remaining tags. If a rate limit (HTTP 429) is hit, stop the release loop, keep results collected so far, and log: "Release fetch stopped at tag {N}/{total} due to rate limiting."
119
+
120
+ Write to `{staging}/releases.md` — format as a markdown document with one section per release (tag, name, date, body).
121
+
122
+ 4. **Changelog (if exists):**
123
+
124
+ Check if `CHANGELOG.md` or `RELEASES.md` exists in the repository root:
125
+
126
+ ```bash
127
+ gh api repos/{owner}/{repo}/contents/CHANGELOG.md --jq '.content' | base64 -d
128
+ ```
129
+
130
+ If found, write to `{staging}/changelog.md`. If not found (404), skip silently.
131
+
132
+ #### 3b. Targeted Function Searches (Uses Extraction Inventory)
133
+
134
+ After the generic fetches above, perform **targeted searches** using the top-level public API function names from `extraction_inventory.top_exports[]`. This produces high-signal results that generic list fetches miss.
135
+
136
+ **Limit:** Search the top **10 function names** maximum to control API call volume and avoid `gh` rate limiting.
137
+
138
+ For each function name in `top_exports[]` (up to 10):
139
+
140
+ ```bash
141
+ gh search issues --repo {owner}/{repo} "{function_name}" --limit 5 --json number,title,state,body
142
+ ```
143
+
144
+ Aggregate all targeted search results into a single file: `{staging}/targeted-issues.md`. Format as a markdown document with one section per function name, listing the matching issues/PRs found.
145
+
146
+ **If `gh search` is unavailable** (older `gh` CLI versions): skip targeted searches silently. The generic fetches from section 3 still provide baseline temporal context.
147
+
148
+ **If rate limiting occurs** (HTTP 429 or similar): stop targeted searches immediately, keep results collected so far. Log: "Targeted search stopped at function {N}/{total} due to rate limiting."
149
+
150
+ **After all fetching,** verify at least one file was written to the staging directory. If the staging directory is empty (all fetches failed), log a warning and skip to section 5.
151
+
152
+ ### 4. Index Into QMD & Register
153
+
154
+ **Index the staging directory:**
155
+
156
+ If a `{skill-name}-temporal` collection already exists, remove and recreate for atomic replace:
157
+
158
+ ```bash
159
+ qmd collection remove {skill-name}-temporal
160
+ qmd collection add _bmad-output/{skill-name}-temporal/ --name {skill-name}-temporal --mask "*.md"
161
+ qmd embed
162
+ ```
163
+
164
+ **Note:** `qmd embed` generates vector embeddings required for `vector_search` and `deep_search`. Without it, only BM25 keyword `search` works. Run it after every `qmd collection add`.
165
+
166
+ **Update the registry** in `forge-tier.yaml`:
167
+
168
+ If an entry with `name: "{skill-name}-temporal"` already exists in `qmd_collections`, replace it. Otherwise, append:
169
+
170
+ ```yaml
171
+ - name: "{skill-name}-temporal"
172
+ type: "temporal"
173
+ source_workflow: "create-skill"
174
+ skill_name: "{skill-name}"
175
+ created_at: "{current ISO date}"
176
+ ```
177
+
178
+ **Clean up** the staging directory after successful indexing:
179
+
180
+ ```bash
181
+ rm -rf _bmad-output/{skill-name}-temporal/
182
+ ```
183
+
184
+ **Error handling:**
185
+
186
+ - If QMD indexing fails: log the error, note that temporal enrichment will be unavailable. Do NOT fail the workflow.
187
+ - If registry update fails: log the error, continue. The collection may exist in QMD even if the registry entry failed.
188
+ - If cleanup fails: log a warning and continue.
189
+
190
+ Display brief confirmation:
191
+
192
+ "**Temporal context indexed.** Collection `{skill-name}-temporal` created ({file_count} files: {list files}). Proceeding to enrichment..."
193
+
194
+ ### 5. Menu Handling Logic
195
+
196
+ **Auto-proceed step — no user interaction.**
197
+
198
+ After temporal context is fetched and indexed (or skipped for any reason), immediately load, read entire file, then execute `{nextStepFile}`.
199
+
200
+ #### EXECUTION RULES:
201
+
202
+ - This is an auto-proceed step with no user choices
203
+ - Quick/Forge tiers skip directly to next step with no output
204
+ - Non-GitHub sources skip directly to next step with no output
205
+ - Cached collections (< 7 days old) skip with brief cache-hit message
206
+ - Deep tier with fresh fetch displays brief confirmation then auto-proceeds
207
+ - All failures degrade gracefully — skip and auto-proceed
208
+
209
+ ## CRITICAL STEP COMPLETION NOTE
210
+
211
+ ONLY WHEN temporal context is indexed into QMD (or the step is skipped due to eligibility, cache, or failure) will you proceed to load `{nextStepFile}` for QMD enrichment.
212
+
213
+ ---
214
+
215
+ ## 🚨 SYSTEM SUCCESS/FAILURE METRICS
216
+
217
+ ### ✅ SUCCESS:
218
+
219
+ - Non-eligible scenarios (Quick/Forge tier, non-GitHub source, no `gh` CLI) skipped silently
220
+ - Cached collections (< 7 days old) detected and re-fetch skipped
221
+ - Temporal data fetched via `gh` CLI into staging directory (generic + targeted)
222
+ - Targeted searches performed for up to 10 top_exports function names
223
+ - At least one temporal file written (issues, PRs, releases, changelog, or targeted-issues)
224
+ - Collection `{skill-name}-temporal` indexed into QMD
225
+ - Registry entry added/updated in forge-tier.yaml with type `"temporal"`
226
+ - Staging directory cleaned up after indexing
227
+ - Auto-proceeded to step-04
228
+
229
+ ### ❌ SYSTEM FAILURE:
230
+
231
+ - Halting the workflow due to a `gh` CLI, QMD, or network failure
232
+ - Leaving staging files on disk after indexing (must clean up)
233
+ - Overwriting or modifying extraction data from step-03
234
+ - Displaying skip messages for Quick/Forge tiers (should be silent)
235
+ - Attempting to fetch temporal data from non-GitHub sources
236
+ - Not registering the collection in forge-tier.yaml after successful indexing
237
+
238
+ **Master Rule:** Temporal context is best-effort enrichment data. Fetch what you can, index it, clean up, and move on. Failures degrade gracefully — they never block the skill compilation pipeline.
@@ -0,0 +1,220 @@
1
+ ---
2
+ name: 'step-03c-fetch-docs'
3
+ description: 'Fetch remote documentation from URLs for T3-confidence content — all tiers, tool-agnostic'
4
+ nextStepFile: './step-04-enrich.md'
5
+ ---
6
+
7
+ # Step 3c: Fetch Remote Documentation
8
+
9
+ ## STEP GOAL:
10
+
11
+ Fetch remote documentation from brief-specified URLs using whatever web fetching capability is available in the agent's environment, extract API information, and add T3-confidence content to the extraction inventory. Tool-agnostic — the agent uses Firecrawl, WebFetch, web-reader, curl, or any available web tool.
12
+
13
+ ## MANDATORY EXECUTION RULES (READ FIRST):
14
+
15
+ ### Universal Rules:
16
+
17
+ - CRITICAL: Read the complete step file before taking any action
18
+ - ALWAYS follow the exact instructions in the step file
19
+ - TOOL/SUBPROCESS FALLBACK: If any instruction references a tool you do not have access to, you MUST still achieve the outcome in your main context thread
20
+ - YOU MUST ALWAYS SPEAK OUTPUT in your Agent communication style with the config `{communication_language}`
21
+
22
+ ### Role Reinforcement:
23
+
24
+ - You are a skill compilation engine fetching external documentation for T3 enrichment
25
+ - Doc fetching is best-effort — individual URL failures never block the workflow
26
+ - Graceful degradation is paramount — if no web fetching tools are available, skip with a warning and proceed
27
+
28
+ ### Step-Specific Rules:
29
+
30
+ - No tier gate — this step runs at any tier when `doc_urls` are present in the brief
31
+ - Tool-agnostic — use whatever web fetching capability is available (Firecrawl, WebFetch, web-reader, curl, browser tools, etc.)
32
+ - FORBIDDEN to halt the workflow if web fetching is unavailable or fails
33
+ - FORBIDDEN to override existing T1, T1-low, or T2 extraction data with T3 content
34
+ - FORBIDDEN to begin compilation — that is step-05
35
+
36
+ ## EXECUTION PROTOCOLS:
37
+
38
+ - Follow MANDATORY SEQUENCE exactly
39
+ - Every extracted item receives a T3 confidence citation: `[EXT:{url}]`
40
+ - Merge doc-fetch results into the extraction inventory per the conflict rule in section 5
41
+ - Do NOT hallucinate content — if information is not in the fetched text, exclude it
42
+
43
+ ## CONTEXT BOUNDARIES:
44
+
45
+ - Available: brief_data (including `doc_urls`, `source_type`), tier, extraction_inventory from step-03
46
+ - Focus: Fetching external documentation and producing T3-confidence extraction items
47
+ - Limits: Do NOT modify existing T1/T1-low/T2 items, begin enrichment, or compile content
48
+ - Dependencies: Step-03 extraction must be complete (even if inventory is empty for docs-only briefs)
49
+
50
+ ## MANDATORY SEQUENCE
51
+
52
+ **CRITICAL:** Follow this sequence exactly. Do not skip, reorder, or improvise.
53
+
54
+ ### 1. Check Eligibility
55
+
56
+ Evaluate the following conditions. **If the condition fails, skip silently to section 7 (auto-proceed) with no output:**
57
+
58
+ 1. **`doc_urls` is present in the brief data:** Check that `doc_urls` contains at least one URL entry from step-01 context. If `doc_urls` is absent or empty, skip silently.
59
+
60
+ No tier gate — if `doc_urls` are present, this step runs at Quick, Forge, and Deep tiers alike.
61
+
62
+ ### 2. Security Notice
63
+
64
+ Display an informational notice (not a gate — the user already approved these URLs in the brief):
65
+
66
+ "**Documentation fetch:** The following external URLs will be fetched:
67
+ {for each URL: `- {label}: {url}`}
68
+
69
+ Content fetched from external URLs is classified as **T3** (external, untrusted) and cited as `[EXT:{url}]`."
70
+
71
+ ### 3. Fetch Documentation
72
+
73
+ **Discover available web fetching capability.** Try tools in any order — use whatever is accessible in the current environment (e.g., Firecrawl scrape, WebFetch, web-reader, MCP fetch, curl, browser tools). If no web fetching capability can be found:
74
+
75
+ - Log warning: "No web fetching capability available in this environment. Skipping documentation fetch."
76
+ - Skip to section 7 (auto-proceed).
77
+
78
+ **For each URL in `doc_urls`:**
79
+
80
+ - Fetch the content at `{url}` as clean markdown using the discovered web tool.
81
+ - **If fetch succeeds:** Store the markdown content with the URL as provenance source.
82
+ - **If fetch fails:** Log warning: "Failed to fetch {url}: {reason}. Skipping." Continue with remaining URLs.
83
+
84
+ **Subpage discovery (root URL detection):**
85
+
86
+ After fetching a URL, apply the following heuristic to detect documentation root pages that contain no useful API content. This is common with modern documentation sites (Mintlify, Docusaurus, ReadTheDocs, GitBook) that render API content on subpages.
87
+
88
+ **Root page detection heuristic — a page is a root if BOTH conditions are true:**
89
+
90
+ 1. **Zero API content indicators:** The fetched markdown contains none of: fenced code blocks (`` ``` ``), parameter tables (`|---|`), or function signature patterns (`def `, `function `, `fn `, `func `, `export `).
91
+ 2. **High link density:** More than 70% of non-empty lines are markdown links (matching `[text](url)` with no other substantive content on the line).
92
+
93
+ If only one condition is true, treat the page as having partial content — keep it as-is and do NOT trigger subpage discovery.
94
+
95
+ **If a root URL with minimal content is detected:**
96
+
97
+ 1. **Attempt sitemap/map discovery:** Use whatever discovery tool is available:
98
+ - Firecrawl: `firecrawl_map({url})` to discover all subpages
99
+ - Manual: try fetching `{url}/sitemap.xml` and parsing URLs from it
100
+ - Crawl: if a crawl tool is available, use it with depth=1 on the root URL
101
+ - If no discovery tool is available, keep the root page content as-is and continue
102
+
103
+ 2. **Filter discovered URLs by relevance:** From the discovered subpage list, select the most relevant pages by searching for API-related terms in the URL path or title (e.g., `api`, `reference`, `quickstart`, `setup`, `config`, `getting-started`, `guide`, `sdk`, `methods`, `functions`). Exclude pages that are clearly non-API content (e.g., `blog`, `changelog`, `pricing`, `about`, `careers`).
104
+
105
+ 3. **Fetch top subpages:** Fetch up to **10** of the most relevant subpages. For each:
106
+ - Use the same web fetching tool as the root URL
107
+ - Store with the subpage URL as provenance: `[EXT:{subpage-url}]`
108
+ - If a subpage fetch fails, skip it and continue
109
+
110
+ 4. **Rate limiting:** If rate limiting (HTTP 429) is encountered during subpage fetching, stop discovery for this root URL. Keep results collected so far. Log: "Subpage discovery stopped due to rate limiting."
111
+
112
+ **If ALL URLs fail (including any subpage fetches):** Log warning: "No documentation could be fetched. Proceeding without T3 content." Skip to section 7 (auto-proceed).
113
+
114
+ ### 4. Extract API Information from Fetched Content
115
+
116
+ Parse the successfully fetched markdown for:
117
+
118
+ - **Function/method signatures** and their parameters
119
+ - **Return types** and data structures
120
+ - **Configuration options** and their defaults
121
+ - **Usage examples** and code snippets
122
+
123
+ **Citation rule:** Every extracted item gets a T3 confidence citation: `[EXT:{url}]` where `{url}` is the source URL the item was extracted from.
124
+
125
+ **No hallucination:** If information cannot be found in the fetched content, exclude it. Do not infer or fabricate API details.
126
+
127
+ ### 5. Build Doc-Fetch Inventory
128
+
129
+ **Mode determines merge behavior:**
130
+
131
+ - **`source_type: "docs-only"`** — The doc-fetch inventory IS the extraction inventory. It replaces the empty inventory from step-03, since there was no source code to extract from.
132
+ - **`source_type: "source"` (supplemental mode)** — Merge T3 items into the existing extraction inventory from step-03.
133
+
134
+ **Conflict rule:** T3 items NEVER override existing T1, T1-low, or T2 items for the same export. When an export already has a higher-confidence entry, the T3 item is discarded. T3 has the lowest priority.
135
+
136
+ **Aggregate totals for reporting:**
137
+ - URLs fetched successfully vs. total
138
+ - URLs that failed
139
+ - T3 items extracted
140
+
141
+ ### 5b. Index into QMD (Deep Tier Only)
142
+
143
+ **If tier is not Deep:** Skip this section silently.
144
+
145
+ **If tier is Deep and at least one URL was fetched successfully:**
146
+
147
+ 1. Write fetched markdown files to a staging directory: `_bmad-output/{skill-name}-docs/`
148
+ 2. Index into QMD: `qmd collection add _bmad-output/{skill-name}-docs/ --name {skill-name}-docs --mask "*.md"`
149
+ 3. Generate embeddings: `qmd embed` (required for `vector_search` and `deep_search`)
150
+ 4. Register in forge-tier.yaml `qmd_collections` array:
151
+
152
+ ```yaml
153
+ - name: "{skill-name}-docs"
154
+ type: "docs"
155
+ source_workflow: "create-skill"
156
+ skill_name: "{skill-name}"
157
+ created_at: "{current ISO date}"
158
+ ```
159
+
160
+ 5. Clean up staging directory after indexing: `rm -rf _bmad-output/{skill-name}-docs/`
161
+
162
+ **If QMD indexing fails:** Warn: "QMD indexing of fetched docs failed. T3 items are still in the extraction inventory — enrichment will proceed without QMD-indexed docs." Continue.
163
+
164
+ ### 6. Report
165
+
166
+ Display:
167
+
168
+ "**Documentation fetch complete.**
169
+ **URLs processed:** {fetched}/{total}
170
+ **T3 items extracted:** {count}
171
+ **Confidence:** All doc-fetched items are T3 — `[EXT:{url}]` citations applied.
172
+ {If docs-only mode: '**Mode:** Docs-only — all skill content is T3. source_authority: community'}
173
+
174
+ Proceeding to enrichment..."
175
+
176
+ ### 7. Menu Handling Logic
177
+
178
+ **Auto-proceed step — no user interaction.**
179
+
180
+ After documentation fetch is complete (or skipped for any reason), immediately load, read entire file, then execute `{nextStepFile}`.
181
+
182
+ #### EXECUTION RULES:
183
+
184
+ - This is an auto-proceed step with no user choices
185
+ - No `doc_urls` in brief: skip directly to next step with no output
186
+ - No web fetching available: skip with warning then auto-proceed
187
+ - All URLs failed: skip with warning then auto-proceed
188
+ - Successful fetch: display report then auto-proceed
189
+ - All failures degrade gracefully — skip and auto-proceed
190
+
191
+ ## CRITICAL STEP COMPLETION NOTE
192
+
193
+ ONLY WHEN documentation is fetched and T3 items are merged into the extraction inventory (or the step is skipped due to no `doc_urls`, no web tools, or fetch failures) will you proceed to load `{nextStepFile}` for enrichment.
194
+
195
+ ---
196
+
197
+ ## SYSTEM SUCCESS/FAILURE METRICS
198
+
199
+ ### SUCCESS:
200
+
201
+ - No `doc_urls` in brief: skipped silently, auto-proceeded
202
+ - `doc_urls` present: each URL fetched using whatever web tool is available
203
+ - Root URLs with minimal content: subpage discovery attempted, relevant subpages fetched
204
+ - Individual fetch failures handled gracefully (skip and continue)
205
+ - All extracted content cited as T3 with `[EXT:{url}]` provenance
206
+ - Existing T1/T1-low/T2 items never overridden by T3 data
207
+ - Docs-only mode: doc-fetch inventory correctly replaces empty extraction inventory
208
+ - Supplemental mode: T3 items merged into existing inventory respecting conflict rule
209
+ - Auto-proceeded to step-04
210
+
211
+ ### SYSTEM FAILURE:
212
+
213
+ - Halting the workflow because web fetching is unavailable or a URL fails
214
+ - Including fetched content without `[EXT:{url}]` citations
215
+ - Overriding existing higher-confidence extractions (T1, T1-low, T2) with T3 data
216
+ - Hardcoding a specific fetching tool instead of being tool-agnostic
217
+ - Hallucinating API details not found in the fetched content
218
+ - Beginning compilation in this step (that is step-05)
219
+
220
+ **Master Rule:** Documentation fetching is best-effort T3 enrichment. Fetch what you can, cite everything as `[EXT:{url}]`, never override higher-confidence data, and move on. Failures degrade gracefully — they never block the skill compilation pipeline.