---
name: support-dream
description: "Use when the wiki needs consolidation — triggered by phrases like 'consolidate the wiki', 'clean up aiwiki', 'merge duplicate notes', 'prune stale gotchas', 'tidy the knowledge base', 'refine the session notes', or by the user invoking /dream or /forge-evolve. Merges aiwiki duplicates, resolves contradictions, and refines the active session file; output lands in aiwiki/proposed/ for user review — input is never modified. Skip for routine note capture (use /note for raw thoughts); skip when aiwiki/ has had no writes since the last dream — there is nothing to consolidate."
---

# Support: Dream (Wiki Consolidation)

## Overview

The `aiwiki/` accumulates noise: raw notes that need to be classified, gotcha files that overlap, conventions that drift, session files that need to be summarized before context is lost. Dream consolidates all of it.

**Core principle:** input store is never modified. Dream produces a NEW reviewable state in `aiwiki/proposed/{dream_id}/`; the user accepts (atomic swap) or rejects (discard).

**Announce at start:** "I'm using the support-dream skill to consolidate `aiwiki/` for [trigger]."

This skill orchestrates wiki consolidation. It dispatches the `dreamer` subagent to do the actual LLM consolidation work. Different providers (forge-local default, anthropic-managed optional) supply different consolidation backends behind the same skill interface.

## When to Use

Three triggers, distinct intents:

| Trigger | Intent | Scope |
|---|---|---|
| **Phase close** (Phase 4 (iterate) lock, Phase 5 (codify) lock, Phase 6 (production-build) per-slice close, Phase 7 (deliver) retrospective) | Promote phase outputs into curated wiki state | Subfolders touched by the phase |
| **PreCompact hook fire** (~85% context utilization) | Consolidate signal into durable form before lossy compaction | `aiwiki/raw/` + recently-touched typed pages. Also refines the active session file (`aiwiki/sessions/{date}-{session_id_short}.md`) — pre-compact creates it lazily on first fire; dream consolidates its `## Checkpoints` event log if it grows beyond ~10 entries. |
| **Manual `/dream`** | User-driven cleanup (after major refactor, branch merge, accumulated noise) | User-specified |

**Do NOT skip when:**
- Phase close — the next phase's work depends on consolidated state
- PreCompact — fires once before compaction; missing it means session signal is lost on compact

**Do NOT run when:**
- The wiki has no recent changes (no raw entries, no recent typed-page writes, no session events) — there's nothing to consolidate; the cycle would no-op

## What Dream Does NOT Do

- Does NOT modify `aiwiki/` directly (writes only to `aiwiki/proposed/{dream_id}/`)
- Does NOT modify `.forge/work/` (manifest is operational state, not knowledge)
- Does NOT delete or archive accepted typed pages (only the user does, via `forge wiki accept` / `reject`)
- Does NOT enforce schemas (LINT does that — runs on the proposed output before marking the dream complete)
- Does NOT promote raw entries on its own judgment if they fail their target schema (flags them in the manifest; user reviews)

## Index maintenance

Each dream cycle refreshes `aiwiki/{subfolder}/INDEX.md` for every folder it touches (plus the top-level `aiwiki/INDEX.md`). Without this, the first few entries in a folder stay visible but later ones become invisible to future sessions — by entry 50, nobody can find it without grepping. The `dreamer` subagent rewrites each touched folder's INDEX during its Step 4; the canonical procedure (file walk, frontmatter extraction, sortable date/title/status table) lives in `agents/dreamer.md`. Full-scope dreams (`/dream` with no scope arg) refresh every folder; targeted dreams refresh only the folders in scope.

## Trigger Flow

### Phase-close trigger

Fired by phase-close hooks (after user emits the phase-lock signal):

1. Skill detects phase-close event (e.g. Phase 4 lock)
2. Determines scope based on which phase closed (e.g. Phase 4 → `aiwiki/raw/` written during Phase 4 + Phase 4 gotchas/conventions)
3. Dispatches `dreamer` subagent with scope + provider config
4. Dreamer produces `aiwiki/proposed/{dream_id}/` + `.dream-manifest.json`
5. LINT runs on proposed output; results recorded in manifest
6. Phase-close gate **blocks the next phase** until the user reviews this dream — the next phase reads consolidated wiki state, so it cannot proceed against pending unreviewed proposals

### PreCompact trigger

Fired indirectly via the pre-compact hook (`hooks/scripts/pre-compact.sh`). The hook itself cannot dispatch a subagent — instead it writes a `**Dream directive (unconsumed)**` block to the active session file's `## Checkpoints` section. The post-compact agent reads the session file, finds the unconsumed directive, and invokes this skill.

1. Skill is invoked by the post-compact agent acting on the directive. Scope from directive: `aiwiki/raw/` + recently-touched typed pages, plus the active session file itself (`aiwiki/sessions/{date}-{session_id_short}.md`).
2. **Session file is always present at PreCompact time** — pre-compact.sh creates it lazily on first fire and appends the checkpoint. Dream refines the session file's `## Checkpoints` section if it has grown unwieldy (>10 entries) and may pre-populate the index sections (`## Files touched`, etc.) from git diff and aiwiki writes, leaving `/wrap` to finalize.
3. Dispatches `dreamer` subagent
4. Output to `aiwiki/proposed/{dream_id}/`
5. LINT runs on proposed output
6. Native compaction does not wait for user review — the consolidated raw/typed pages and session-file proposal are already on disk
7. **Mark the directive consumed** — after dispatch returns, the agent changes the originating entry's header from `**Dream directive (unconsumed):**` to `**Dream directive (consumed at {ISO-timestamp}):**`. Header-flip is what `session-start.sh` counts. Appending a separate "Status: consumed" line leaves the original unconsumed-marked header in place and the next session-start will still surface it as a HARD-INTERRUPT (dogfood-validated 2026-05-18).

### Manual /dream trigger

User invokes `/dream [scope]`:

1. Skill parses scope (default: full `aiwiki/`; alternatives: `aiwiki/raw/`, `aiwiki/gotchas/`, etc.)
2. Dispatches `dreamer` subagent
3. Output to `aiwiki/proposed/{dream_id}/`
4. LINT runs on proposed output
5. User reviews via `forge wiki review {dream_id}`

## Inputs (per trigger)

| Source | Always | Phase-close | PreCompact | Manual |
|---|---|---|---|---|
| Current `aiwiki/` (typed pages) | ✓ | ✓ | ✓ | ✓ |
| Page schemas (`aiwiki/schemas/`) | ✓ | ✓ | ✓ | ✓ |
| `aiwiki/raw/` | ✓ | ✓ | ✓ | ✓ |
| `aiwiki/sessions/{current}.md` | — | — | ✓ | optional |
| Recent commits (since last dream) | — | ✓ (since phase start) | ✓ (since session start) | optional |
| Phase 4 prototype iteration logs | — | ✓ (Phase 4 close only) | — | — |
| Anthropic Managed Agents session IDs | — | — | — | — (only with `anthropic-managed` provider) |

The dispatch prompt carries the scope; the dreamer subagent reads from disk.

## Outputs

Dream produces a directory `aiwiki/proposed/{dream_id}/` mirroring `aiwiki/` structure, plus a manifest:

`aiwiki/proposed/{dream_id}/.dream-manifest.json`:

```json
{
  "dream_id": "2026-05-10-1042-phase4-close",
  "trigger": "phase-close",
  "trigger_detail": "Phase 4 lock (feature/auth-refactor)",
  "scope": ["aiwiki/raw/", "aiwiki/gotchas/2026-05/", "aiwiki/conventions/"],
  "base_aiwiki_hash": "sha256:a3f2bc1...",
  "created_at": "2026-05-10T10:42:00Z",
  "provider": "forge-local",
  "changed_pages": 3,
  "new_pages": 1,
  "deleted_pages": 0,
  "lint_status": "passed",
  "lint_warnings": [],
  "review_status": "pending",
  "reviewed_at": null,
  "operations": [
    {"op": "merge", "files": ["aiwiki/gotchas/2026-05-08-x.md", "aiwiki/gotchas/2026-05-09-x-recur.md"], "into": "aiwiki/gotchas/2026-05-10-x-merged.md", "reason": "duplicate root cause"},
    {"op": "promote", "from": "aiwiki/raw/2026-05-09-handler-naming.md", "into": "aiwiki/conventions/handler-naming.md", "reason": "matches convention schema"},
    {"op": "prune", "file": "aiwiki/raw/2026-05-01-investigate-cache.md", "reason": "investigation completed; ADR 0042 captures outcome"}
  ]
}
```

The `operations` log lets the user understand the diff at a glance without reading every file.

## Consolidation pipeline

The actual consolidation work — read aiwiki, identify merges/promotions/prunes, write proposed output, build the manifest — runs in the `dreamer` subagent. The pipeline is canonical in `agents/dreamer.md`; do not duplicate it here. This skill's job is dispatch (decide provider, scope, trigger detail) and post-dispatch handling (run LINT on the proposed output, update the manifest, surface to the user).

## Provider model

The skill dispatches different consolidation backends based on configuration:

### `forge-local` (default)

- Dispatches `dreamer` subagent locally (Claude Code subagent dispatch)
- Reads from local filesystem (`aiwiki/`, schemas, session events)
- Writes proposed output locally
- No cloud dependency; free with subscription

### `anthropic-managed` (optional)

Enabled by `forge config set wiki.dream.provider anthropic-managed` or `FORGE_DREAM_PROVIDER=anthropic-managed`.

- Adapts accepted `aiwiki/` pages into Anthropic memory-store format
- Calls Anthropic Dreams API with optional Managed Agents session IDs
- Maps the output store back into typed markdown in `aiwiki/proposed/{dream_id}/`
- Runs forge LINT on the result (Anthropic output may not match forge schemas; LINT catches drift)

The skill detects the provider from config and dispatches accordingly. The `dreamer` subagent's instructions are provider-aware (see `agents/dreamer.md`).

## CLI Surface

This skill operates the dream side; the user-facing CLI is separate but documented here for completeness:

| Command | Purpose |
|---|---|
| `forge wiki status` | List pending dreams (sorted by `created_at`, oldest first) |
| `forge wiki review [dream_id]` | Open per-page review flow (`$EDITOR` opens diff for each changed file) |
| `forge wiki accept [dream_id]` | Atomic swap: `aiwiki/proposed/{dream_id}/` contents replace `aiwiki/` per-file. Old contents archived to `.forge/wiki-history/{timestamp}/`. |
| `forge wiki reject [dream_id] --reason "..."` | Discard. Logged in `.forge/dream-history.jsonl` with reason. |

## Invariants

**Never:**
- Write to `aiwiki/` directly (only `aiwiki/proposed/{dream_id}/`)
- Write to `.forge/work/` (operational state, not knowledge)
- Skip LINT on proposed output
- Promote a raw entry that fails its target schema without flagging it in the manifest's `lint_warnings`
- Run a new dream while the current one's `aiwiki/proposed/{dream_id}/` is still pending review (queue them; do not overwrite)

**Always:**
- Record the `base_aiwiki_hash` so the user can detect if `aiwiki/` changed mid-dream (rare, but possible if a session writes during dream)
- Include the `operations` log in the manifest so review is one-glance, not file-by-file fishing
- Keep the proposed output's structure mirroring `aiwiki/` exactly (so atomic swap is per-file safe)

## Common Mistakes

| Mistake | Fix |
|---|---|
| Modifying `aiwiki/` directly during consolidation | All writes go to `aiwiki/proposed/{dream_id}/`; the swap is the user's action |
| Writing a new file in `aiwiki/sessions/` instead of refining the active session file | The active session file is `aiwiki/sessions/{date}-{session_id_short}.md` — created by pre-compact, /wrap, /dream, or harden. Dream refines that file in place (via the proposed-output path); it does not produce a separate sessions file. |
| Running dream when there's no signal to consolidate | Skip the dream entirely; record nothing |
| Skipping LINT on proposed output | LINT MUST run; lint warnings go into the manifest, surface during review |
| Promoting raw entries without reading the target schema | Read `aiwiki/schemas/{type}.md` first; the raw entry must satisfy required sections + frontmatter |
| Overwriting a previous proposed dream | New dreams create new `{dream_id}` directories; queue accumulates; the user reviews in order |

## I/O Contract

| Field | Value |
|---|---|
| **Requires** | `aiwiki/` (or empty), `aiwiki/schemas/` (the typed-page schemas), provider config (`forge-local` default) |
| **Produces** | `aiwiki/proposed/{dream_id}/` (mirror structure), `aiwiki/proposed/{dream_id}/.dream-manifest.json` |
| **Triggers** | Phase-close hooks, pre-compact hook, manual `/dream` |
| **Updates manifest** | `.forge/dream-history.jsonl` (one append per dream cycle, regardless of accept/reject) |

## Integration

**Called by:**
- Phase-close hooks (Phase 4 (iterate) lock, Phase 5 (codify) lock, Phase 6 (production-build) per-slice close, Phase 7 (deliver) retrospective)
- Pre-compact hook (forge's existing context-monitor at ~85%)
- `/dream` slash command

**Dispatches:**
- `dreamer` subagent (forge-local provider) — see `agents/dreamer.md`
- Anthropic Dreams API (anthropic-managed provider) — via the `support-dream` skill's provider adapter

**Pairs with:**
- `support-wiki-lint` — LINT runs on dream's proposed output
- `support-context-monitor` — fires the pre-compact trigger
- `support-gotcha` — provides the gotcha files dream may merge
- Phase-close hooks for Phase 4 (`iterate-prototype`), Phase 5 (`harden`), Phase 6 (per-slice gates), Phase 7 (deliver) (`support-gotcha` retrospective)

**Forbidden integrations:**
- Cannot be called from inside another dream (no nested dreams)
- Cannot be called as a write target by other skills (other skills write to `aiwiki/raw/` or typed pages directly; dream consolidates separately)
