Distillator: A Document Distillation Engine
Overview
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.
This is a compression task, not a summarization task. Summaries are lossy. Distillates are lossless compression optimized for LLM consumption.
On Activation
Validate inputs. The caller must provide:
- source_documents (required) — One or more file paths, folder paths, or glob patterns to distill
- 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.
- token_budget (optional) — Approximate target size. When provided and the distillate would exceed it, trigger semantic splitting.
- output_path (optional) — Where to save. When omitted, save adjacent to the primary source document with
-distillate.md suffix.
- --validate (flag) — Run round-trip reconstruction test after producing the distillate.
Route — proceed to Stage 1.
Stages
| # |
Stage |
Purpose |
| 1 |
Analyze |
Run analysis script, determine routing and splitting |
| 2 |
Compress |
Spawn compressor agent(s) to produce the distillate |
| 3 |
Verify & Output |
Completeness check, format check, save output |
| 4 |
Round-Trip Validate |
(--validate only) Reconstruct and diff against originals |
Stage 1: Analyze
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.
Stage 2: Compress
Single mode (routing = "single", ≤3 files, ≤15K estimated tokens):
Spawn one subagent using agents/distillate-compressor.md with all source file paths.
Fan-out mode (routing = "fan-out"):
Spawn one compressor subagent per group from the analysis output. Each compressor receives only its group's file paths and produces an intermediate distillate.
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.
Clean up intermediate distillate content (it exists only in memory, not saved to disk).
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.
The compressor returns a structured JSON result containing the distillate content, source headings, named entities, and token estimate.
Stage 3: Verify & Output
After the compressor (or merge compressor) returns:
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.
Format check. Verify the output follows distillate format rules:
- No prose paragraphs (only bullets)
- No decorative formatting
- No repeated information
- Each bullet is self-contained
- Themes are clearly delineated with
## headings
Determine output format. Using the split prediction from Stage 1 and actual distillate size:
Single distillate (≤~5,000 tokens or token_budget not exceeded):
Save as a single file with frontmatter:
---
type: bmad-distillate
sources:
- "{relative path to source file 1}"
- "{relative path to source file 2}"
downstream_consumer: "{consumer or 'general'}"
created: "{date}"
token_estimate: {approximate token count}
parts: 1
---
Split distillate (>~5,000 tokens, or token_budget requires it):
Create a folder {base-name}-distillate/ containing:
{base-name}-distillate/
├── _index.md # Orientation, cross-cutting items, section manifest
├── 01-{topic-slug}.md # Self-contained section
├── 02-{topic-slug}.md
└── 03-{topic-slug}.md
The _index.md contains:
- Frontmatter with sources (relative paths from the distillate folder to the originals)
- 3-5 bullet orientation (what was distilled, from what)
- Section manifest: each section's filename + 1-line description
- Cross-cutting items that span multiple sections
Each section file is self-contained — loadable independently. Include a 1-line context header: "This section covers [topic]. Part N of M."
Source paths in frontmatter must be relative to the distillate's location.
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.
Report results. Always return structured JSON output:
{
"status": "complete",
"distillate": "{path or folder path}",
"section_distillates": ["{path1}", "{path2}"] or null,
"source_total_tokens": N,
"distillate_total_tokens": N,
"compression_ratio": "X:1",
"source_documents": ["{path1}", "{path2}"],
"completeness_check": "pass" or "pass_with_additions"
}
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").
If --validate flag was set, proceed to Stage 4. Otherwise, done.
Stage 4: Round-Trip Validation (--validate only)
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.
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.
For split distillates, spawn one reconstructor per section in parallel. Each receives its section file plus the _index.md for cross-cutting context.
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.
Receive reconstructions. The reconstructor returns reconstruction file paths saved adjacent to the distillate.
Perform semantic diff. Read both the original source documents and the reconstructions. For each section of the original, assess:
- Is the core information present in the reconstruction?
- Are specific details preserved (numbers, names, decisions)?
- Are relationships and rationale intact?
- Did the reconstruction add anything not in the original? (indicates hallucination filling gaps)
Produce validation report saved adjacent to the distillate as -validation-report.md:
---
type: distillate-validation
distillate: "{distillate path}"
sources: ["{source paths}"]
created: "{date}"
---
## Validation Summary
- Status: PASS | PASS_WITH_WARNINGS | FAIL
- Information preserved: {percentage estimate}
- Gaps found: {count}
- Hallucinations detected: {count}
## Gaps (information in originals but missing from reconstruction)
- {gap description} — Source: {which original}, Section: {where}
## Hallucinations (information in reconstruction not traceable to originals)
- {hallucination description} — appears to fill gap in: {section}
## Possible Gap Markers (flagged by reconstructor)
- {marker description}
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.
Clean up — delete the temporary reconstruction files after the report is generated.
1---2name: bmad-distillator3description: 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
10This 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
12This is a compression task, not a summarization task. Summaries are lossy. Distillates are lossless compression optimized for LLM consumption.
13
14## On Activation
15
161. **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
232. **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
36Run `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
42Spawn one subagent using `agents/distillate-compressor.md` with all source file paths.
43
44**Fan-out mode** (routing = `"fan-out"`):
45
461. 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
482. 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
503. 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
54The compressor returns a structured JSON result containing the distillate content, source headings, named entities, and token estimate.
55
56### Stage 3: Verify & Output
57
58After the compressor (or merge compressor) returns:
59
601. **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
622. **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
693. **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
1104. **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
1125. **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
1296. If `--validate` flag was set, proceed to Stage 4. Otherwise, done.
130
131### Stage 4: Round-Trip Validation (--validate only)
132
133This 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
1351. **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
1412. **Receive reconstructions.** The reconstructor returns reconstruction file paths saved adjacent to the distillate.
142
1433. **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
1494. **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
1755. **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
1776. **Clean up** — delete the temporary reconstruction files after the report is generated.