bmad-method 6.7.1-next.1 → 6.7.1-next.3

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.
@@ -20,7 +20,7 @@
20
20
  "skills": [
21
21
  "./src/core-skills/bmad-help",
22
22
  "./src/core-skills/bmad-brainstorming",
23
- "./src/core-skills/bmad-distillator",
23
+ "./src/core-skills/bmad-spec",
24
24
  "./src/core-skills/bmad-party-mode",
25
25
  "./src/core-skills/bmad-shard-doc",
26
26
  "./src/core-skills/bmad-advanced-elicitation",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "bmad-method",
4
- "version": "6.7.1-next.1",
4
+ "version": "6.7.1-next.3",
5
5
  "description": "Breakthrough Method of Agile AI-driven Development",
6
6
  "keywords": [
7
7
  "agile",
package/removals.txt CHANGED
@@ -52,3 +52,8 @@ bmad-bmm-sprint-planning
52
52
  bmad-bmm-sprint-status
53
53
  bmad-bmm-technical-research
54
54
  bmad-bmm-validate-prd
55
+
56
+ # Removed skills (post-v6.7.x)
57
+ # bmad-distillator: superseded by bmad-spec (universal intent distiller with
58
+ # preservation-validated contract for downstream skills).
59
+ bmad-distillator
@@ -0,0 +1,126 @@
1
+ ---
2
+ name: bmad-spec
3
+ description: Distill any intent input into the SPEC kernel + companions — the canonical, preservation-validated machine contract for downstream work. Use when the user says "create a spec", "distill this into a spec", "validate this spec", or "update the spec".
4
+ ---
5
+
6
+ # BMad Spec
7
+ ## Overview
8
+
9
+ Canonical transformer for the BMad spec-kernel ecosystem. Takes any intent input — vague idea, brain dump, PRD, GDD, RFC, brief, Slack thread, customer email, meeting transcript, mockups, mixed multi-source — and produces **SPEC.md** carrying the five-field kernel (Why, Capabilities, Constraints, Non-goals, Success signal) plus companion files for load-bearing content that does not fit or would bloat the kernel with expansive line-item detail. Together they are the machine contract every downstream BMad skill consumes.
10
+
11
+ Multiple skills may call to update the same spec over time.
12
+
13
+ ## Conventions
14
+
15
+ - Bare paths (e.g. `assets/spec-template.md`) resolve from the skill root.
16
+ - `{skill-root}` is this skill's install dir; `{project-root}` is the working dir.
17
+ - `{workflow.<name>}` resolves to fields in `customize.toml`.
18
+
19
+ ## On Activation
20
+
21
+ 1. Resolve customization: `python3 {project-root}/_bmad/scripts/resolve_customization.py --skill {skill-root} --key workflow`. On failure, read `{skill-root}/customize.toml` directly.
22
+ 2. Run `{workflow.activation_steps_prepend}`. Treat `{workflow.persistent_facts}` as foundational context (`file:` entries are loaded).
23
+ 3. Load `{project-root}/_bmad/core/config.yaml` (and `config.user.yaml` if present), root level and `bmm` section. Resolve `{user_name}`, `{communication_language}`, `{document_output_language}`, `{planning_artifacts}`, `{project_name}`, `{date}`.
24
+ 4. Detect mode. **Headless** when any of: no TTY, programmatic caller (another skill or non-interactive runner), or the first message pre-supplies all inputs and asks for an artifact path back. **Interactive** otherwise. In interactive mode, greet by `{user_name}` in `{communication_language}`, stay in that language, and mention that `bmad-party-mode` and `bmad-advanced-elicitation` are available for deeper exploration on any field.
25
+ 5. Run `{workflow.activation_steps_append}`.
26
+
27
+ ## Workspace
28
+
29
+ The spec is **always a folder** named `{workflow.spec_output_path}/{workflow.run_folder_pattern}`, resolving by default to `{output_folder}/specs/spec-{slug}/`.
30
+
31
+ `{slug}` describes the thing being specced, not the input shape:
32
+
33
+ - Source artifact already carries a slug (e.g., `prd-foo-bar-2026-05-23/`): inherit (`foo-bar`).
34
+ - Sparse, in-chat, or multi-source input: interactive asks; headless caller provides it as part of the input. If absent and underivable, headless blocks with `error_code: "missing_slug"`.
35
+ - Same slug = same folder. A second invocation with the same `{slug}` lands at the existing spec folder and updates in place, preserving capability IDs.
36
+
37
+ **No input.** Interactive: ask the user to share a file path, paste content, explain the idea in detail, or point to a source. Headless: respond with JSON containing `error_code: "insufficient_intent"`.
38
+
39
+ Inside the spec folder:
40
+
41
+ ```
42
+ <spec-folder>/
43
+ SPEC.md ← uppercase, the kernel
44
+ <companion-1>.md ← optional, content-typed (e.g. glossary.md)
45
+ <companion-2>.md
46
+ .decision-log.md ← canonical memory for this spec
47
+ ```
48
+
49
+ ## The Operation
50
+
51
+ Read the input and its ancillary linked materials. If there is no input, follow the no-input branch in **Workspace** (ask or block). If a prior `SPEC.md` exists at the target folder, read it too — the operation becomes an update. Preserve capability IDs; new capabilities get the next unused `CAP-N`; never reuse retired IDs. Otherwise this is a create.
52
+
53
+ When the input is structured and pre-sorted (a PRD with an addendum, a GDD, a brief produced by an upstream BMad skill), trust the authored separation: lift kernel-fitting content into SPEC.md, lift overflow into appropriately-named companions. When the input is mixed (a brain dump, a transcript, an RFC, a customer email), do the sorting yourself: walk each claim, apply the three-lens load-bearing test (Spec Law rule 7), and route to the kernel field or a companion.
54
+
55
+ Distill the input into the five-field kernel using `{workflow.spec_template}` as the skeleton. When input is rich, extract directly — no elicitation. When input is sparse, choose: **express** (best-effort distill, every gap becomes an `open_questions[]` entry) or **guided** (walk the five fields with the user one at a time). Headless defaults to express and logs the choice. Interactive asks.
56
+
57
+ Write lean from the first pass: every sentence must earn its place. Decoration costs tokens and dilutes downstream readers.
58
+
59
+ If the input is genuinely too thin to distill (e.g. "an app for hikers" with no surrounding context), stop and suggest `bmad-prd` (or sibling ceremony skill). This skill distills; it does not coach.
60
+
61
+ ## Load-bearing
62
+
63
+ A claim is **load-bearing** if any consumer (downstream skill, implementing agent, verification pass) would change a decision without it.
64
+
65
+ ## Companions
66
+
67
+ When load-bearing content does not fit the five-field kernel, it lives in a companion. The kernel cites it; the companion holds it. Companions are part of the contract; every consumer reads `companions:` in SPEC.md frontmatter to discover them. Companions follow the same lean discipline as SPEC.md (Spec Law rule 8).
68
+
69
+ **Spawn a companion when the content needs more than one kernel-shape line:** multi-item catalogs (per-entity matrices like archetypes, drinks, modes, routes), tables, diagrams (always), editorial voice rules, long-form reference material the kernel cites by name (glossary, brownfield notes, project conventions). Single-line decision-benders stay in Constraints; intent+success pairs stay in Capabilities. If a kernel field is starting to bullet into sub-bullets, the content has outgrown the kernel and wants a companion.
70
+
71
+ Companions are either:
72
+
73
+ - **Spec-authored** companions are written by bmad-spec and live as **siblings of SPEC.md** (e.g., `glossary.md`, `patron-archetypes.md`). bmad-spec owns them and may edit them on update operations.
74
+ - **Adopted** companions are load-bearing artifacts written by an upstream skill that downstream still needs to read. bmad-spec references them into `companions:` by relative path but does NOT edit them (e.g., a `DESIGN.md` or `EXPERIENCE.md` from a UX run, an integration partner's API spec). The originating skill owns them.
75
+
76
+ Two rules govern companions:
77
+
78
+ 1. **Name spec-authored companions for the content type they hold.** `glossary.md`, `<entity-class>.md` (e.g. `patron-archetypes.md`, `medication-routes.md`, `flight-modes.md`), `stack.md`, `conventions.md`, `brownfield.md`, `architecture-diagrams.md`, `state-machines.md`, `failure-modes.md`, `compliance-references.md`. The principle: "a reader should know what is inside before opening it." Adopted companions keep whatever name their originating skill gave them.
79
+ 2. **Diagrams always land in a companion**, regardless of size. SPEC.md kernel holds prose only. Mermaid blocks, ASCII diagrams, and image references all live in a companion (e.g. `architecture-diagrams.md`), with sibling image files referenced from there.
80
+
81
+ Pre-existing project-wide docs (e.g. `project-context.md`) that downstream needs are listed as **adopted companions**, never duplicated into SPEC.md or a spec-authored companion.
82
+
83
+ ## Spec Law
84
+
85
+ Every spec must satisfy these eight rules. The operation aims for them; the self-validate sweep enforces them.
86
+
87
+ 1. **Each capability has both `intent` and `success`.** Missing either = not a capability.
88
+ 2. **Intents describe WHAT, not HOW.** Implementation prescription belongs in a companion (stack, conventions).
89
+ 3. **Constraints actually bend design decisions.** A "constraint" that rules nothing out is decoration.
90
+ 4. **Non-goals are explicit.** At least one. Absence means downstream skills fill the vacuum.
91
+ 5. **Success signal is concrete enough to test or demonstrate against.** "Users love it" doesn't qualify.
92
+ 6. **Capability IDs are stable and unique.** Never reused, never renumbered.
93
+ 7. **Preservation.** Every load-bearing source claim lands in SPEC.md or a companion. Wrapper ceremony does not.
94
+ 8. **Lean prose.** Every sentence carries load-bearing content. Cut decoration, hedges, backstory, throat-clearing. Applies to SPEC.md, companions, and `.decision-log.md`.
95
+
96
+ ## Self-Validate
97
+
98
+ After every create or update, sweep the resulting artifact in **two passes** before presenting.
99
+
100
+ **Pass 1 — Coherence.** Judge the spec against Spec Law rules 1–6 and 8. For anything that fails or feels weak, attempt to fix it without inventing content the input did not support. Calls made without direct confirmation become `assumptions[]`; gaps that could not be filled become `open_questions[]`.
101
+
102
+ **Pass 2 — Preservation.** Walk the source claim by claim. Confirm each load-bearing claim landed in SPEC.md or a companion. Wrapper-ceremony drops are logged under "Wrapper-only content" so the drop is on the record, not silent.
103
+
104
+ Append a one-paragraph verdict to `.decision-log.md` covering both passes. In interactive mode, review the verdict with the user. In headless mode, `.decision-log.md` is one of the files returned, so the caller (or its downstream LLM) reads the verdict there.
105
+
106
+ ## Spec with no change signal
107
+
108
+ When the user points the skill at an existing spec folder (or its SPEC.md) with no change signal, offer to review assumptions or open questions, or determine what they want to do.
109
+
110
+ ## Output
111
+
112
+ **Interactive** — share the spec folder path conversationally. Name the capability count, the companions produced, and the verdict in one or two sentences. If `assumptions[]` or `open_questions[]` are non-empty, list them (short — one line each) and invite the user to walk through them. Make clear that addressing them can update the source input (if it was a file), the spec, or both — whichever combination the user prefers. Do not dump JSON or present a wall of output.
113
+
114
+ **Headless** — return JSON per `assets/headless-schemas.md`.
115
+
116
+ Run `{workflow.on_complete}` if set.
117
+
118
+ ## After Spec is Output
119
+
120
+ Any update to spec regarding assumptions, open questions, or other changes should be appended to that source's decision log also and offer to update the source.
121
+
122
+ ## Frontmatter conventions
123
+
124
+ - `companions:` array of `.md` files downstream MUST read alongside SPEC.md to have the full contract. Paths may point inside the spec folder (spec-authored companions like `glossary.md`) or outside it (adopted companions like `../planning-artifacts/ux-designs/ux-foo-bar-2026-05-23/DESIGN.md`). The split between spec-authored and adopted is implicit by path; downstream treats both the same.
125
+ - `sources:` array of paths to files that were **fully absorbed** into the SPEC, with no remaining downstream value (e.g., a PRD whose every load-bearing claim is now in the kernel). Listed for audit and for bmad-spec to re-read on update. Downstream does NOT read these. Files that downstream still needs to read belong in `companions:`, not here.
126
+ - **Do not list** decision logs, README files, organizational artifacts, or any operational record of how upstream skills produced their artifacts. Those are not source content; they are process metadata that downstream consumers don't need.
@@ -0,0 +1,33 @@
1
+ # Headless JSON Response
2
+
3
+ The default invocation is headless: input goes in, JSON comes out. The contract is intentionally tiny — return the outcome and the files touched. Anything else a caller needs is inside those files (SPEC.md, companions, `.decision-log.md`).
4
+
5
+ ## Success
6
+
7
+ ```json
8
+ {
9
+ "status": "complete",
10
+ "files": [
11
+ "_bmad-output/specs/spec-quarter-drop/SPEC.md",
12
+ "_bmad-output/specs/spec-quarter-drop/glossary.md",
13
+ "_bmad-output/specs/spec-quarter-drop/.decision-log.md"
14
+ ]
15
+ }
16
+ ```
17
+
18
+ `files` lists every file written or modified in this run, in any order. The spec folder, kernel filename, decision log location, capabilities, companions, and verdict are all readable from those files; no need to re-encode them in the response.
19
+
20
+ ## Blocked
21
+
22
+ ```json
23
+ {
24
+ "status": "blocked",
25
+ "error_code": "insufficient_intent",
26
+ "reason": "Input was a one-line idea with no surrounding context; too thin to distill. Suggest bmad-prd to draw the vision out first."
27
+ }
28
+ ```
29
+
30
+ Defined `error_code` values:
31
+
32
+ - `insufficient_intent` — input too thin to distill into a kernel.
33
+ - `missing_slug` — input is sparse or multi-source and no slug was provided by the caller or derivable from a source path.
@@ -0,0 +1,49 @@
1
+ ---
2
+ id: SPEC-{slug}
3
+ companions: [] # files downstream MUST read alongside SPEC.md. Paths may point inside the spec folder (spec-authored) or outside it (adopted from an upstream skill).
4
+ sources: [] # files fully absorbed into the SPEC (audit only; downstream does NOT read these). Never decision logs.
5
+ ---
6
+
7
+ > **Canonical contract.** This SPEC and the files in `companions:` are the complete, preservation-validated contract for what to build, test, and validate. Source documents listed in frontmatter are for traceability only — consult them only if you need narrative rationale or prose color this contract intentionally omits.
8
+
9
+ # {Spec Title}
10
+
11
+ ## Why
12
+
13
+ {One paragraph naming the force behind this work. A spec can exist for any of:
14
+ - **a pain to solve** — a user or operator is stuck on a specific gap;
15
+ - **an opportunity to capture** — something newly possible we want to claim;
16
+ - **a vision to realize** — a thing we want to make exist because we want it to exist;
17
+ - **a mandate to meet** — a regulation, deprecation, deadline, or contractual obligation.
18
+
19
+ Name which (or which combination) applies, who is affected, and the backdrop that makes it matter now. This is the anchor every downstream trade-off resolves against.}
20
+
21
+ ## Capabilities
22
+
23
+ - id: CAP-1
24
+ intent: {One sentence. "User or system can do X to achieve Y." WHAT, not HOW.}
25
+ success: {Testable or demonstrable criterion. Something a test or a real demonstration can decide.}
26
+
27
+ ## Constraints
28
+
29
+ - {A non-negotiable that bends design. If it doesn't rule anything out, it doesn't belong.}
30
+
31
+ ## Non-goals
32
+
33
+ - {Explicit out-of-scope item. At least one. Stops downstream from filling the vacuum.}
34
+
35
+ ## Success signal
36
+
37
+ - {One or two sentences. World-change moment, not dashboard. Concrete enough to write a test or run a demonstration against.}
38
+
39
+ ## Assumptions
40
+
41
+ <!-- Optional. Omit this section entirely if empty. Inferred calls made without direct confirmation from the input. -->
42
+
43
+ - {Statement of fact the Spec proceeded under, e.g. "Assumed mobile-first since input mentioned GPS but no platform."}
44
+
45
+ ## Open Questions
46
+
47
+ <!-- Optional. Omit this section entirely if empty. Gaps the input did not resolve that need a human decision before downstream skills consume the Spec. -->
48
+
49
+ - {Question phrased so a human can answer it, e.g. "Is offline playback in scope for CAP-2?"}
@@ -0,0 +1,53 @@
1
+ # DO NOT EDIT -- overwritten on every update.
2
+ #
3
+ # Workflow customization surface for bmad-spec.
4
+ #
5
+ # Override files (not edited here):
6
+ # {project-root}/_bmad/custom/bmad-spec.toml (team)
7
+ # {project-root}/_bmad/custom/bmad-spec.user.toml (personal)
8
+
9
+ [workflow]
10
+
11
+ # --- Configurable below. Overrides merge per BMad structural rules: ---
12
+ # scalars: override wins • arrays: append
13
+
14
+ # Steps to run before the standard activation (config load, greet).
15
+ activation_steps_prepend = []
16
+
17
+ # Steps to run after greet but before the operation begins.
18
+ activation_steps_append = []
19
+
20
+ # Persistent facts the workflow keeps in mind for the whole run.
21
+ # Each entry is either a literal sentence, a skill prefixed with `skill:`,
22
+ # or a `file:`-prefixed path/glob whose contents are loaded as facts.
23
+ # Default points to a single top-level file; override in team/user TOML
24
+ # to widen the scope (e.g. `_bmad/**/project-context.md`) if needed.
25
+ persistent_facts = [
26
+ "file:{project-root}/project-context.md",
27
+ ]
28
+
29
+ # Executed when the workflow completes. Scalar or array of instructions.
30
+ on_complete = ""
31
+
32
+ # Spec template. The five-field kernel skeleton. Override the path in
33
+ # team/user TOML to enforce a different shape (e.g. a hypothesis field
34
+ # for research initiatives, or a mechanics field for games).
35
+ spec_template = "assets/spec-template.md"
36
+
37
+ # Canonical filename for the kernel artifact inside the spec folder.
38
+ # Uppercase by convention to signal "the central source of truth."
39
+ spec_filename = "SPEC.md"
40
+
41
+ # Output path for spec folders. Lands directly under {output_folder}
42
+ # so bmad-spec works in core-only installs and matches the
43
+ # long-term BMad direction of grouping artifacts as siblings under
44
+ # {output_folder}/<type>/ rather than nested inside planning vs
45
+ # implementation folders.
46
+ spec_output_path = "{output_folder}/specs"
47
+
48
+ # Run-folder pattern inside spec_output_path. Resolved against the
49
+ # input-derived slug at activation. Same slug = same folder, so a
50
+ # second invocation updates the existing spec in place (capability
51
+ # IDs preserved). Override to add {date} or other components if a
52
+ # fresh dated history is preferred.
53
+ run_folder_pattern = "spec-{slug}"
@@ -9,5 +9,5 @@ Core,bmad-editorial-review-prose,Editorial Review - Prose,EP,Use after drafting
9
9
  Core,bmad-editorial-review-structure,Editorial Review - Structure,ES,Use when doc produced from multiple subprocesses or needs structural improvement.,,[path],anytime,,,false,report located with target document,
10
10
  Core,bmad-review-adversarial-general,Adversarial Review,AR,"Use for quality assurance or before finalizing deliverables. Code Review in other modules runs this automatically, but also useful for document reviews.",,[path],anytime,,,false,,
11
11
  Core,bmad-review-edge-case-hunter,Edge Case Hunter Review,ECH,Use alongside adversarial review for orthogonal coverage — method-driven not attitude-driven.,,[path],anytime,,,false,,
12
- Core,bmad-distillator,Distillator,DG,Use when you need token-efficient distillates that preserve all information for downstream LLM consumption.,,[path],anytime,,,false,adjacent to source document or specified output_path,distillate markdown file(s)
12
+ Core,bmad-spec,Spec,SP,"Use to distill any intent input (brief, PRD, transcript, brain dump, design folder, mixed multi-source) into a succinct, no-fluff SPEC.md contract + companions that downstream work derives from. Locks the WHAT before the HOW. Works for software, game design, research, editorial, policy, business, anything intent-bearing. Validation mode also available.",,[path],anytime,,,false,{output_folder}/specs/spec-{slug},SPEC.md + companion files
13
13
  Core,bmad-customize,BMad Customize,BC,"Use when you want to change how an agent or workflow behaves — add persistent facts, swap templates, insert activation hooks, or customize menus. Scans what's customizable, picks the right scope (agent vs workflow), writes the override to _bmad/custom/, and verifies the merge. No TOML hand-authoring required.",,,anytime,,,false,{project-root}/_bmad/custom,TOML override files
@@ -177,6 +177,14 @@ def extract_key(data, dotted_key: str):
177
177
  return current
178
178
 
179
179
 
180
+ def write_json_stdout(output):
181
+ """Write JSON as UTF-8 so Windows cp1252 stdout can carry emoji icons."""
182
+ reconfigure = getattr(sys.stdout, "reconfigure", None)
183
+ if reconfigure is not None:
184
+ reconfigure(encoding="utf-8")
185
+ sys.stdout.write(json.dumps(output, indent=2, ensure_ascii=False) + "\n")
186
+
187
+
180
188
  def main():
181
189
  parser = argparse.ArgumentParser(
182
190
  description="Resolve customization for a BMad skill using three-layer TOML merge.",
@@ -223,7 +231,7 @@ def main():
223
231
  else:
224
232
  output = merged
225
233
 
226
- sys.stdout.write(json.dumps(output, indent=2, ensure_ascii=False) + "\n")
234
+ write_json_stdout(output)
227
235
 
228
236
 
229
237
  if __name__ == "__main__":
@@ -0,0 +1,50 @@
1
+ import json
2
+ import os
3
+ import subprocess
4
+ import sys
5
+ import tempfile
6
+ import unittest
7
+ from pathlib import Path
8
+
9
+
10
+ SCRIPT = Path(__file__).resolve().parents[1] / "resolve_customization.py"
11
+
12
+
13
+ class ResolveCustomizationStdoutTests(unittest.TestCase):
14
+ def test_writes_emoji_json_when_stdout_encoding_is_cp1252(self):
15
+ with tempfile.TemporaryDirectory() as temp_dir:
16
+ skill_dir = Path(temp_dir) / "emoji-agent"
17
+ skill_dir.mkdir()
18
+ (skill_dir / "customize.toml").write_text(
19
+ '[agent]\nname = "Emoji Agent"\nicon = "🧭"\n',
20
+ encoding="utf-8",
21
+ )
22
+
23
+ env = os.environ.copy()
24
+ env["PYTHONIOENCODING"] = "cp1252"
25
+ result = subprocess.run(
26
+ [
27
+ sys.executable,
28
+ str(SCRIPT),
29
+ "--skill",
30
+ str(skill_dir),
31
+ "--key",
32
+ "agent",
33
+ ],
34
+ stdout=subprocess.PIPE,
35
+ stderr=subprocess.PIPE,
36
+ env=env,
37
+ check=False,
38
+ )
39
+
40
+ stderr = result.stderr.decode("utf-8", errors="replace")
41
+ self.assertEqual(result.returncode, 0, msg=stderr)
42
+
43
+ output = result.stdout.decode("utf-8")
44
+ self.assertIn("🧭", output)
45
+ resolved = json.loads(output)
46
+ self.assertEqual(resolved["agent"]["icon"], "🧭")
47
+
48
+
49
+ if __name__ == "__main__":
50
+ unittest.main()
@@ -1,177 +0,0 @@
1
- ---
2
- name: bmad-distillator
3
- description: Lossless LLM-optimized compression of source documents. Use when the user requests to 'distill documents' or 'create a distillate'.
4
- ---
5
-
6
- # Distillator: A Document Distillation Engine
7
-
8
- ## Overview
9
-
10
- This skill produces hyper-compressed, token-efficient documents (distillates) from any set of source documents. A distillate preserves every fact, decision, constraint, and relationship from the sources while stripping all overhead that humans need and LLMs don't. Act as an information extraction and compression specialist. The output is a single dense document (or semantically-split set) that a downstream LLM workflow can consume as sole context input without information loss.
11
-
12
- This is a compression task, not a summarization task. Summaries are lossy. Distillates are lossless compression optimized for LLM consumption.
13
-
14
- ## On Activation
15
-
16
- 1. **Validate inputs.** The caller must provide:
17
- - **source_documents** (required) — One or more file paths, folder paths, or glob patterns to distill
18
- - **downstream_consumer** (optional) — What workflow/agent consumes this distillate (e.g., "PRD creation", "architecture design"). When provided, use it to judge signal vs noise. When omitted, preserve everything.
19
- - **token_budget** (optional) — Approximate target size. When provided and the distillate would exceed it, trigger semantic splitting.
20
- - **output_path** (optional) — Where to save. When omitted, save adjacent to the primary source document with `-distillate.md` suffix.
21
- - **--validate** (flag) — Run round-trip reconstruction test after producing the distillate.
22
-
23
- 2. **Route** — proceed to Stage 1.
24
-
25
- ## Stages
26
-
27
- | # | Stage | Purpose |
28
- |---|-------|---------|
29
- | 1 | Analyze | Run analysis script, determine routing and splitting |
30
- | 2 | Compress | Spawn compressor agent(s) to produce the distillate |
31
- | 3 | Verify & Output | Completeness check, format check, save output |
32
- | 4 | Round-Trip Validate | (--validate only) Reconstruct and diff against originals |
33
-
34
- ### Stage 1: Analyze
35
-
36
- Run `scripts/analyze_sources.py --help` then run it with the source paths. Use its routing recommendation and grouping output to drive Stage 2. Do NOT read the source documents yourself.
37
-
38
- ### Stage 2: Compress
39
-
40
- **Single mode** (routing = `"single"`, ≤3 files, ≤15K estimated tokens):
41
-
42
- Spawn one subagent using `agents/distillate-compressor.md` with all source file paths.
43
-
44
- **Fan-out mode** (routing = `"fan-out"`):
45
-
46
- 1. Spawn one compressor subagent per group from the analysis output. Each compressor receives only its group's file paths and produces an intermediate distillate.
47
-
48
- 2. After all compressors return, spawn one final **merge compressor** subagent using `agents/distillate-compressor.md`. Pass it the intermediate distillate contents as its input (not the original files). Its job is cross-group deduplication, thematic regrouping, and final compression.
49
-
50
- 3. Clean up intermediate distillate content (it exists only in memory, not saved to disk).
51
-
52
- **Graceful degradation:** If subagent spawning is unavailable, read the source documents and perform the compression work directly using the same instructions from `agents/distillate-compressor.md`. For fan-out, process groups sequentially then merge.
53
-
54
- The compressor returns a structured JSON result containing the distillate content, source headings, named entities, and token estimate.
55
-
56
- ### Stage 3: Verify & Output
57
-
58
- After the compressor (or merge compressor) returns:
59
-
60
- 1. **Completeness check.** Using the headings and named entities list returned by the compressor, verify each appears in the distillate content. If gaps are found, send them back to the compressor for a targeted fix pass — not a full recompression. Limit to 2 fix passes maximum.
61
-
62
- 2. **Format check.** Verify the output follows distillate format rules:
63
- - No prose paragraphs (only bullets)
64
- - No decorative formatting
65
- - No repeated information
66
- - Each bullet is self-contained
67
- - Themes are clearly delineated with `##` headings
68
-
69
- 3. **Determine output format.** Using the split prediction from Stage 1 and actual distillate size:
70
-
71
- **Single distillate** (≤~5,000 tokens or token_budget not exceeded):
72
-
73
- Save as a single file with frontmatter:
74
-
75
- ```yaml
76
- ---
77
- type: bmad-distillate
78
- sources:
79
- - "{relative path to source file 1}"
80
- - "{relative path to source file 2}"
81
- downstream_consumer: "{consumer or 'general'}"
82
- created: "{date}"
83
- token_estimate: {approximate token count}
84
- parts: 1
85
- ---
86
- ```
87
-
88
- **Split distillate** (>~5,000 tokens, or token_budget requires it):
89
-
90
- Create a folder `{base-name}-distillate/` containing:
91
-
92
- ```
93
- {base-name}-distillate/
94
- ├── _index.md # Orientation, cross-cutting items, section manifest
95
- ├── 01-{topic-slug}.md # Self-contained section
96
- ├── 02-{topic-slug}.md
97
- └── 03-{topic-slug}.md
98
- ```
99
-
100
- The `_index.md` contains:
101
- - Frontmatter with sources (relative paths from the distillate folder to the originals)
102
- - 3-5 bullet orientation (what was distilled, from what)
103
- - Section manifest: each section's filename + 1-line description
104
- - Cross-cutting items that span multiple sections
105
-
106
- Each section file is self-contained — loadable independently. Include a 1-line context header: "This section covers [topic]. Part N of M."
107
-
108
- Source paths in frontmatter must be relative to the distillate's location.
109
-
110
- 4. **Measure distillate.** Run `scripts/analyze_sources.py` on the final distillate file(s) to get accurate token counts for the output. Use the `total_estimated_tokens` from this analysis as `distillate_total_tokens`.
111
-
112
- 5. **Report results.** Always return structured JSON output:
113
-
114
- ```json
115
- {
116
- "status": "complete",
117
- "distillate": "{path or folder path}",
118
- "section_distillates": ["{path1}", "{path2}"] or null,
119
- "source_total_tokens": N,
120
- "distillate_total_tokens": N,
121
- "compression_ratio": "X:1",
122
- "source_documents": ["{path1}", "{path2}"],
123
- "completeness_check": "pass" or "pass_with_additions"
124
- }
125
- ```
126
-
127
- Where `source_total_tokens` is from the Stage 1 analysis and `distillate_total_tokens` is from step 4. The `compression_ratio` is `source_total_tokens / distillate_total_tokens` formatted as "X:1" (e.g., "3.2:1").
128
-
129
- 6. If `--validate` flag was set, proceed to Stage 4. Otherwise, done.
130
-
131
- ### Stage 4: Round-Trip Validation (--validate only)
132
-
133
- This stage proves the distillate is lossless by reconstructing source documents from the distillate alone. Use for critical documents where information loss is unacceptable, or as a quality gate for high-stakes downstream workflows. Not for routine use — it adds significant token cost.
134
-
135
- 1. **Spawn the reconstructor agent** using `agents/round-trip-reconstructor.md`. Pass it ONLY the distillate file path (or `_index.md` path for split distillates) — it must NOT have access to the original source documents.
136
-
137
- For split distillates, spawn one reconstructor per section in parallel. Each receives its section file plus the `_index.md` for cross-cutting context.
138
-
139
- **Graceful degradation:** If subagent spawning is unavailable, this stage cannot be performed by the main agent (it has already seen the originals). Report that round-trip validation requires subagent support and skip.
140
-
141
- 2. **Receive reconstructions.** The reconstructor returns reconstruction file paths saved adjacent to the distillate.
142
-
143
- 3. **Perform semantic diff.** Read both the original source documents and the reconstructions. For each section of the original, assess:
144
- - Is the core information present in the reconstruction?
145
- - Are specific details preserved (numbers, names, decisions)?
146
- - Are relationships and rationale intact?
147
- - Did the reconstruction add anything not in the original? (indicates hallucination filling gaps)
148
-
149
- 4. **Produce validation report** saved adjacent to the distillate as `-validation-report.md`:
150
-
151
- ```markdown
152
- ---
153
- type: distillate-validation
154
- distillate: "{distillate path}"
155
- sources: ["{source paths}"]
156
- created: "{date}"
157
- ---
158
-
159
- ## Validation Summary
160
- - Status: PASS | PASS_WITH_WARNINGS | FAIL
161
- - Information preserved: {percentage estimate}
162
- - Gaps found: {count}
163
- - Hallucinations detected: {count}
164
-
165
- ## Gaps (information in originals but missing from reconstruction)
166
- - {gap description} — Source: {which original}, Section: {where}
167
-
168
- ## Hallucinations (information in reconstruction not traceable to originals)
169
- - {hallucination description} — appears to fill gap in: {section}
170
-
171
- ## Possible Gap Markers (flagged by reconstructor)
172
- - {marker description}
173
- ```
174
-
175
- 5. **If gaps are found**, offer to run a targeted fix pass on the distillate — adding the missing information without full recompression. Limit to 2 fix passes maximum.
176
-
177
- 6. **Clean up** — delete the temporary reconstruction files after the report is generated.