---
name: prompt-distiller
description: Distill a folder of past prompts (or a saved conversation export) into reusable templates with `{placeholder}` variables. Heuristic detector — no LLM call needed. Finds high-frequency phrases, common openers, recurring task structures, and emits a `prompts.yaml` of named templates plus a frequency report. Pure Python stdlib + regex. Use when the user has a graveyard of past prompts and wants to extract a reusable library, or to find what they keep typing over and over.
---


# prompt-distiller

Heuristic prompt-pattern miner. Scans a folder of `.txt`/`.md` prompts (or a single conversation export) and emits a `prompts.yaml` of reusable templates with `{placeholder}` variables, plus a frequency report.

No LLM call. Pure Python stdlib + regex. Token-frequency, regex shape detection, and line-level diff to find the variable bit between near-duplicates.

## Usage

```bash
python3 scripts/distill.py --input <folder-or-file> [--output prompts.yaml] [--top 10] [--min-uses 3]
```

## Flags

- `--input` — folder of `.txt`/`.md`, or a single file (conversation export). Required.
- `--output` — path to write the templates YAML. Default `prompts.yaml`.
- `--top` — emit at most N templates (highest-frequency first). Default `10`.
- `--min-uses` — minimum occurrences for a cluster to become a template. Default `3`.

## How it works

1. Parse all input texts. Split into "prompts" by:
   - blank-line-separated paragraphs, or
   - lines starting with `human:` / `user:` / `you:` (chat exports).
2. Normalize whitespace and collect token sequences.
3. Find recurring 3-7 word openers (e.g. `"write me a"`, `"fix the bug in"`).
4. Bucket prompts by fuzzy structure (token-edit similarity). Within each bucket, line-diff identifies the variable spans and replaces them with `{var1}`, `{var2}`, ...
5. Rank by uses. Emit YAML + stdout summary.

## Output

```yaml
templates:
  - id: bug-fix
    body: "Fix the bug in {file} where {issue}"
    uses: 14
    examples: ["Fix the bug in agent.js where it loops forever", ...]
  - id: explain
    body: "Explain how {thing} works"
    uses: 9
```

## When to use

- You have a graveyard of past prompts and want a reusable library.
- You want to know what you keep typing over and over.
- You want to seed snippet/expander tools (TextExpander, Raycast, etc).
