---
name: blossom
description: "Run spike-driven exploration to discover and plan work for an unknown or loosely-defined goal. Use when you need to explore a codebase area, create an epic with prioritized tasks, or convert a vague objective into a structured backlog. Keywords: explore, discover, spike, plan, epic, backlog, investigate."
argument-hint: "<goal or area to explore>"
allowed-tools: Read, Grep, Glob, Bash(bd:*), Bash(git:*), Bash(mkdir:*)
context: fork
enabled: false
source: github:supertyrelle/pelley
imported-from: github:supertyrelle/pelley
---

# Blossom: Emergent Spike-Driven Epic Workflow

You are running the **Blossom** workflow -- a recursive spike-driven exploration pattern that converts an unknown or loosely-defined goal into a comprehensive, prioritized backlog. The user wants to explore: **$ARGUMENTS**

## Overview

Blossom works in 6 phases. Spikes are dispatched as isolated subagents. For large explorations (6+ spikes), spikes are organized under a beads epic and dispatched sequentially. For small ones (5 or fewer), they run as lightweight sequential agents.

```
Seed epic (identify spike areas, count determines batch size)
  -> dispatch spike subagents sequentially
    -> orchestrator reviews reports, creates beads
      -> dispatch consolidation subagent
        -> verify DAG, report final backlog
```

---

## Phase 0: Session Health Gate

Before dispatching spikes, check that the session has enough capacity for the work ahead. Do this inline -- do not invoke `/session-health` as a subagent.

**Assess the current session:**
- Roughly how many files have you read this session?
- How many agents have you dispatched?
- How many distinct codebase areas have you touched?

| Load Level | Files Read | Agents Dispatched | Signal |
|------------|-----------|-------------------|--------|
| Light | <10 | 0-1 | Healthy -- proceed |
| Moderate | 10-25 | 2-4 | Proceed, watch quality |
| Heavy | 25-50 | 5+ | Warn user before dispatching |
| Overloaded | 50+ | 8+ | Recommend handoff |

**If load is Heavy or Overloaded:** Warn the user:

> Session context is heavy (~X files read, ~Y agents dispatched). Dispatching additional spike agents risks dropping results mid-workflow due to context compaction. Recommend running `/handoff` to capture current state and re-invoking `/blossom` in a fresh session. Continue anyway? (y/n)

Wait for user confirmation before proceeding. If the user declines, stop here and run `/handoff`.

**If load is Light or Moderate, or the user confirms they want to continue:** Proceed immediately to Phase 1.

---

## Phase 1: Seed the Epic

### 1a. Clarify the Goal

If `$ARGUMENTS` is empty or too vague, ask the user one clarifying question. Otherwise proceed immediately. Do not over-question -- the whole point of blossom is to discover scope through exploration, not upfront specification.

### 1b. Create the Epic

**If `.beads/` exists in the project root:**

```bash
bd create --title="EPIC: [goal description]" --type=epic --priority=2
```

Save the returned epic ID. All subsequent beads will be wired as dependencies of this epic.

**If `.beads/` does not exist:** Skip `bd` commands throughout this workflow. Track the epic and all spike/task beads in `TODO.md` instead, using a flat markdown list. Create or append to `TODO.md` at the project root with the epic title as a heading and each task as a checkbox item.

### 1c. Identify Initial Spike Areas

Decompose the goal into 3-6 bounded spike areas (a **/decompose** -- MECE sub-parts). Each spike targets a specific codebase area or architectural concern (e.g., "Audit domain/agents/ for dead code", "Map trust system integration points").

### 1d. Create Spike Beads

**If `.beads/` exists**, for each spike area create as a child of the epic:

```bash
bd create --title="SPIKE: [specific area to investigate]" --type=task --priority=2 \
  --parent=<epic-id> \
  --description="Discovery spike. Investigate [area] and report: (1) firm tasks found, (2) areas needing deeper spikes, (3) clean areas requiring no work."
```

The `--parent` flag establishes the epic-child hierarchy, enabling `bd children`, `bd epic status`, and `bd epic close-eligible`.

**If `.beads/` does not exist**, add each spike as a checkbox under the epic heading in `TODO.md`:
```
- [ ] SPIKE: [specific area to investigate]
```

---

## Phase 2: Execute Spikes

### Dispatch Spikes

Dispatch each spike sequentially to an isolated subagent. Each spike runs in a separate context with an Explore agent.

```
dispatch(agent="explorer", task="<spike instructions>", taskId="<spike-bead-id>")
```

Process each spike's results as it completes before dispatching the next. If new spikes are created from findings, add them to the queue and dispatch after the current batch.

### Spike Instructions

Each spike agent receives these instructions. The spike report uses **pipe format** (see `/rules/pipe-format.md`) so downstream primitives can consume spike output directly.

> You are executing a discovery spike for the Blossom workflow. This is an investigation using the **/gather** pattern -- collect findings with sources and confidence levels.
>
> **Your area:** [spike description]
>
> **Your job:** Thoroughly investigate this area and produce a structured report. Do NOT implement fixes -- only discover and document.
>
> Follow the investigation protocol and report requirements from the Agent Preamble (fan-out-protocol rule).
>
> **Spike-specific requirements:**
>
> 1. Use Glob to find all relevant files in the area
> 2. When you find something that looks like an issue, verify by reading surrounding code:
>    - Check who calls this code (callers)
>    - Check if tests cover it
>    - Check if it's wired in bootstrap/DI
>    - Check if the interface layer exposes it
> 3. For each finding, state your confidence level:
>    - **CONFIRMED**: You read the code and verified the issue exists
>    - **LIKELY**: Strong evidence from multiple signals but couldn't fully trace the chain
>    - **POSSIBLE**: Suspicious pattern that needs a deeper spike to verify
>
> **Report format (pipe format -- you MUST follow this exactly):**
>
> ```
> ## Spike findings for [area]
>
> **Source**: /blossom (spike)
> **Input**: [spike description]
>
> ### Items
>
> 1. **[action verb] [specific thing]** -- [what you found and how you verified]
>    - source: [file path:line number]
>    - confidence: CONFIRMED | LIKELY | POSSIBLE
>    - priority: P0-P4
>    - scope: [estimated files to change]
>
> 2. ...
>
> ### Deeper Spikes Needed
>
> For each area needing more investigation:
> - **[specific sub-area]** -- [what suggests work here but could not confirm]
>   - look-for: [specific questions the deeper spike should answer]
>
> ### Clean Areas
> - [area]: No issues found. [brief evidence -- what you read and why you're confident]
>
> ### Summary
>
> [One paragraph: N firm tasks (X CONFIRMED, Y LIKELY), M deeper spikes needed, K clean areas.]
> ```

### After Each Spike Completes

1. **Review the spike report** for quality. Run through these explicit checks before accepting the report:

   - [ ] Response contains pipe-format structure: a `##` heading, a `**Source**:` line, and a `### Items` section
   - [ ] At least one `CONFIRMED`, `LIKELY`, or `POSSIBLE` confidence tag is present in the Items section
   - [ ] At least one `file:line` citation is present (evidence from actual code reading, not speculation)

   **If any check fails:** Flag via `bd update <spike-id> --notes="QUALITY ISSUE: [which checks failed]"` (or note in TODO.md). Do not create firm tasks from low-quality reports.

2. **Create firm task beads** as children of the epic:

   **If `.beads/` exists:**
   ```bash
   bd create --title="[title from spike report]" --type=task --priority=[P level as 0-4] \
     --parent=<epic-id> \
     --description="[confidence level]. [evidence and scope from spike report]"
   ```
   **If `.beads/` does not exist:** Add to `TODO.md` under the epic heading as `- [ ] [title from spike report]`.

3. **Create new spike beads** as children of the epic:

   **If `.beads/` exists:**
   ```bash
   bd create --title="SPIKE: [deeper area]" --type=task --priority=2 \
     --parent=<epic-id> \
     --description="Deeper discovery spike spawned from SPIKE: [parent spike]. Reason: [why from report]. Look for: [specific questions]"
   ```
   **If `.beads/` does not exist:** Add to `TODO.md` as `- [ ] SPIKE: [deeper area]`.

4. **Close the completed spike** with findings summary:

   **If `.beads/` exists:**
   ```bash
   bd close <spike-id>
   bd update <spike-id> --notes="Completed. Found N firm tasks (X confirmed, Y likely), M deeper spikes needed. Key findings: [1-2 sentence summary]"
   ```
   **If `.beads/` does not exist:** Mark the spike as done in `TODO.md` by checking its checkbox (`- [x] SPIKE: ...`) and appending a findings note inline.

### Recursion

If new spikes were created, dispatch them as subagents. Continue until no new spikes are generated.

**Safety limit:** If total spikes executed exceeds 20, stop and report to the user. The goal may be too broad.

---

## Phase 3: Consolidate

After all spikes are complete and all firm tasks created, run consolidation to clean up the backlog before wiring dependencies. Consolidation applies **/filter** logic (dedup, stale detection -- binary keep/drop per item) and **/assess** logic (completeness audit -- categorical verdict per architectural slice).

### Dispatch Consolidator

**If `.beads/` exists**, dispatch a consolidator agent:

```
dispatch(agent="consolidator", task="<consolidation instructions>")
```

**Consolidation instructions:**

> You are the consolidation agent for the Blossom workflow. Your job is to review the backlog under epic [epic-id] and tighten it before final dependency wiring.
>
> Run these steps in order:
>
> **1. Survey:**
> ```bash
> bd stats
> bd list --status=open
> bd blocked
> ```
>
> **2. Dedup:** Within each cluster of tasks, find exact duplicates, subset tasks, and convergent tasks. Close duplicates with `bd close <id> --reason="Duplicate of <other-id>"`. Merge subsets into their parent with `bd update <parent> --notes="Absorbed <subset>: [details]"`.
>
> **3. Vertical slice audit:** Read the project structure to discover its architectural layers. For each task touching an inner layer, verify companion tasks exist across layer boundaries (persistence, wiring, exposure, tests). Create missing companions with `bd create`.
>
> **4. Stale detection:** Check for tasks created more than 2 weeks ago with no progress, tasks whose target code has been refactored, or tasks describing work already done (check git log). Close stale tasks with `bd close <id> --reason="Stale: [explanation]"`.
>
> **5. Dependency cleanup:** Remove redundant transitive dependencies. Run `bd dep cycles` to check for cycles. Run `bd swarm validate <epic-id>` to validate the full epic structure (cycles, orphans, disconnected subgraphs). Run `bd children <epic-id>` to verify all tasks are proper children of the epic.
>
> **6. Report:** Provide consolidation report with these counts: tasks closed (dedup), tasks closed (stale), tasks created (gap fill), dependencies modified.
>
> Be conservative with closures -- when in doubt, keep a task open and add a note. Always check the code before declaring something stale.

**If `.beads/` does not exist**, skip consolidation and proceed directly to Phase 3b. The TODO.md list serves as the backlog -- dedup and stale detection must be done manually by reviewing the file.

### 3b. Agent Assignment Hints

After consolidation, tag each firm task with grounded agent assignment notes. The sharpening gate: name specific files the agent will touch (from spike findings), state concrete skills/knowledge needed (not just a role), and make it dispatchable.

**If `.beads/` exists:**
```bash
bd update <task-id> --notes="Recommended agent: <role> -- touches <file-list>. Requires: <specific-skills>"
```

**If `.beads/` does not exist:** Add agent hints as inline notes in `TODO.md` next to each task item.

**Before:** `bd update abc1 --notes="Recommended agent: refactorer"`
**After:** `bd update abc1 --notes="Recommended agent: refactorer -- touches src/domain/auth/User.ts + src/domain/auth/Session.ts. Requires: DDD pattern knowledge, extract-interface refactoring"`

This gives /sprint enough context to make good dispatch decisions without reading every spike report.

---

## Phase 4: Prioritize and Wire Dependencies

### Cross-Task Dependencies

**If `.beads/` exists**, wire dependencies where order matters:
```bash
bd dep add <downstream> <upstream>
```
Inner layers before outer layers, interfaces before implementations, shared files sequenced. Think bottom-up through the dependency graph.

**If `.beads/` does not exist**, note ordering constraints in `TODO.md` as inline comments next to each task item (e.g., `<!-- depends on: [task name] -->`).

### Priority Review

Adjust priorities now that the full picture is visible. Upgrade tasks that block many others, downgrade inflated P1s, and bump quick wins (small scope + high value).

**If `.beads/` exists:** Use `bd update <task-id> --priority=<N>` to adjust. **If `.beads/` does not exist:** Reorder items in `TODO.md` to reflect execution order.

---

## Phase 5: Verify

**If `.beads/` exists**, run `bd swarm validate <epic-id>` to check the epic structure. This validates:
- Dependency cycles (and reports them)
- Orphaned tasks (children with no dependencies wired)
- Disconnected subgraphs
- Ready fronts (waves of parallelizable work)

```bash
bd swarm validate <epic-id>
```

If validation reports issues, fix them before proceeding.

**If `.beads/` does not exist**, manually review `TODO.md` to verify: no duplicate items, all noted ordering constraints are consistent (no circular dependencies), and execution order is clear.

Then manually verify: priority consistency (P0/P1 tasks must not depend on P3/P4 -- upgrade blockers), every task has testable acceptance criteria, and trace the critical path (longest dependency chain = minimum time to completion).

---

## Phase 6: Report

Present the final blossom report in **pipe format** so downstream primitives (/rank, /filter, /assess) can consume the backlog directly:

```markdown
## Explored backlog for [epic title]

**Source**: /blossom
**Input**: [original $ARGUMENTS]

### Items

1. **[task title]** -- [evidence summary]
   - source: [primary file:line or area]
   - confidence: CONFIRMED | LIKELY
   - priority: P0-P4
   - depends-on: [task IDs or "none"]
   - agent: [recommended agent type]

2. ...

### Exploration

- **Epic ID:** [epic-id]
- **Total spikes:** N executed across M depth levels
- **Spike quality:** [brief assessment -- did agents confirm or hedge?]
- **Areas explored:** [list of top-level spike areas]
- **Clean areas:** [areas confirmed as needing no work]
- **Consolidation:** [dedup N, stale N, gap-fill N, deps modified N]

### Critical Path

[Longest dependency chain with task IDs and titles]

### Parallel Opportunities

[Tasks with no dependencies on each other that can be worked simultaneously]

### Summary

[One paragraph synthesizing the exploration: total tasks, priority distribution (P0: N, P1: N, P2: N, P3: N, P4: N), confidence distribution (CONFIRMED: N, LIKELY: N), recommended execution order, and any open questions from exploration.]
```

---

## Key Principles

1. **Explore, don't implement.** Spikes discover work; they never do it.
2. **Verify, don't speculate.** Read the actual code. CONFIRMED findings over hedged guesses.
3. **Sequential dispatch.** Spikes dispatch to subagents one at a time. Each spike's findings inform the next.
4. **Consolidate before reporting.** Run consolidation (via a subagent) to dedup, fill slice gaps, and resolve orphans before wiring final dependencies.
5. **Use `--parent` for epic hierarchy.** Always create children with `bd create --parent=<epic-id>`. This establishes the hierarchy that enables `bd children`, `bd epic status`, and `bd epic close-eligible`. Use `bd dep add` only for cross-task ordering (task A blocks task B).
6. **Quality gate.** The orchestrator reviews every spike report before creating beads. Spike agents never create beads directly.
7. **Structured reports.** Spike agents must follow the exact report format for consistent processing.
8. **Depth limit.** Stop at 20 total spikes and reassess with the user if the goal is too broad.
9. **Confidence levels.** Every finding is CONFIRMED, LIKELY, or POSSIBLE. Possible triggers a deeper spike.

10. **Persist epic state.** After reporting, write `memory/epics/<epic-id>/epic.md` so downstream skills (/sprint) can load context across sessions.

## Phase 7: Persist Epic State

After the Phase 6 report, write epic state to `memory/epics/<epic-id>/epic.md` so that `/sprint` and other downstream skills can load blossom findings in a later session without re-exploring.

**Create the directory and file:**

```bash
mkdir -p memory/epics/<epic-id>
```

Write `memory/epics/<epic-id>/epic.md` with this structure:

```markdown
# Epic: [epic title]

**Epic ID**: [epic-id]
**Created**: [date]
**Source**: /blossom
**Goal**: [original $ARGUMENTS]

## Spike Findings

[Copy the Phase 6 pipe-format Items section here verbatim -- numbered list with source, confidence, priority, depends-on, and agent fields per item.]

## Priority Order

[Ordered list of task IDs/titles from highest to lowest priority, reflecting final Phase 4 ordering.]

## Task IDs

| BD ID | Title | Priority | Status | Assigned Agent |
|-------|-------|----------|--------|----------------|
| [id]  | [title] | P[N]  | open   | [agent hint]   |
| ...   | ...   | ...      | ...    | ...            |

## Critical Path

[Copy the Phase 6 Critical Path section.]

## Parallel Opportunities

[Copy the Phase 6 Parallel Opportunities section.]
```

**If `.beads/` does not exist**, write the same file but use TODO.md task names instead of BD IDs in the Task IDs table.

See also: /meeting (discuss blossom findings with multiple perspectives before committing to a direction); /review (evaluate the implementations that result from executing blossom tasks).
