Skip to content

Nightmare Healing (IRT)

This section explains DreamStream's Imagery Rehearsal Therapy (IRT) feature, which helps users transform nightmares into sources of strength.


πŸ›‘οΈ The IRT Approach

Imagery Rehearsal Therapy (IRT) is a clinically-proven method for reducing nightmare frequency. DreamStream automates this via a guided wizard.

Recall and record the nightmare in detail. Identifying the core "trigger" is the first step toward resolution.

The AI helps you rewrite the ending. We don't just "fix" it; we empower you with a new, peaceful, or dominant narrative.

Visualize the new ending daily. Generating a "Healing Image" provides a concrete visual anchor for your new narrative. Imagine the new ending before sleep.


Where IRT appears in DreamStream

Entry point When it appears
Dream Detail β†’ Healing tab Always available for nightmares
Nightmare Healing card (β€œStart Nightmare Healing”) On nightmare dreams

The IRT Wizard

The IRT experience is delivered through a step-by-step wizard modal with 3 phases:

Step 1: Identify

What users see:

  • The original nightmare title and description
  • An explanation of how IRT works
  • "Why This Works" callout explaining the clinical basis

Clinically proven

IRT is a well-researched technique that has been shown to significantly reduce nightmare frequency and distress in clinical studies.

Purpose: Acknowledge the nightmare and prepare for transformation.

Step 2: Rescript

What users see:

  • A text area with an AI-generated positive ending
  • "Get a new AI suggestion" button to regenerate
  • Tips for making the ending personally meaningful

User actions:

  • Edit the AI-generated text to customize it
  • Request regeneration if the suggestion doesn't resonate
  • Save the ending when satisfied

AI generation:

  • The AI creates a structured response with:
  • Explanation – Why this rescript approach works for this nightmare
  • Rescripted Ending – The new, positive narrative
  • Practice Instructions – How to use this ending

Step 3: Rehearse

What users see:

  • Confirmation that the healing ending is saved
  • Collapsible preview of the rescripted ending
  • Read Aloud button (TTS) to hear the ending spoken
  • Practice instructions for bedtime rehearsal
  • Generate Healing Image button

Practice Instructions (if not provided by AI):

  1. Close your eyes and briefly recall your original nightmare
  2. Vividly imagine your new, positive ending for 10-20 minutes
  3. Focus on how it feels to experience this resolution

Healing Image Generation

After completing the rescript, users can generate a Healing Image:

  • An AI visualization of the rescripted, positive ending
  • Appears in Dream Detail β†’ Healing tab
  • Requires a saved rescripted ending before it can be generated
  • When both the original nightmare image and healed image exist, a before/after slider lets users compare the two
  • Provides a visual anchor for the rehearsal practice

Read Aloud (TTS)

In the Rehearse step, users can tap a speaker icon to have the rescripted ending read aloud:

  • Uses native Text-to-Speech on device
  • Falls back to Web Speech API on web
  • Tapping again stops playback

Rehearsal before sleep

Listen to the rescripted ending while relaxing before bed. This strengthens the new narrative in your mind.

This supports the rehearsal practice – users can listen to their new ending while relaxing before sleep.


User flow (complete)

flowchart TD
    A[User opens nightmare dream] --> B[Tap 'Healing' or 'Transform Nightmare']
    B --> C[IRT Wizard opens]
    C --> D[Step 1: Identify nightmare]
    D --> E[Step 2: AI generates rescripted ending]
    E --> F[User edits/approves ending]
    F --> G[Save rescripted ending]
    G --> H[Step 3: Rehearse]
    H --> I{Optional actions}
    I --> J[Read Aloud via TTS]
    I --> K[Generate Healing Image]
    I --> L[Practice before bed]

Data storage

  • Rescripted ending is stored on the dream record as rescriptedEnding
  • Can be a string or structured object with explanation, rescriptedEnding, and instructions
  • Healing image is stored as rescriptedImagePath + rescriptedImageUrl

Edge cases & safeguards

  • User can go back and edit the rescript at any time
  • If they close the wizard and return, the saved rescript is preserved
  • Regeneration doesn't override until user explicitly saves
  • Healing image generation is blocked until a rescripted ending exists
  • TTS stops automatically when wizard closes

Implementation map (for accuracy checks)

Component files
  • IRT Wizard: components/NightmareRescriptWizard.tsx
  • AI rescript generation: services/geminiService.ts (rescriptNightmare)
  • Healing image generation: DreamDetail.tsx β†’ job queue
  • TTS playback: src/services/nativeService.ts (speak, stopSpeaking)


← Home Β· Profile & Settings β†’