Four-Phase Consolidation Prompt

Description

The Four-Phase Consolidation Prompt is the system prompt injected into the auto-dream subagent, built by buildConsolidationPrompt() in src/services/autoDream/consolidationPrompt.ts. It defines a four-phase workflow -- Orient, Gather Signal, Consolidate, Prune & Index -- that transforms raw session data into durable, organized memory files.

The prompt is parameterized with three arguments: memoryRoot (the auto-memory directory path), transcriptDir (the project-level session transcript directory), and extra (optional context appended at the end, such as tool constraints and session lists). The function is invoked in two contexts: the automatic background dream cycle (autoDream.ts, where extra includes read-only Bash constraints and a list of session IDs) and the manual /dream slash command (where extra is typically empty, granting normal tool permissions).

The prompt opens with a framing line: "You are performing a dream -- a reflective pass over your memory files." It then instructs the agent to synthesize recent learnings into well-organized memories so future sessions can orient quickly. The four phases are sequential by design -- each builds on the output of the previous.

Phase 1 -- Orient

The agent surveys the current state of memory before making any changes:

This phase is read-only. Its purpose is to prevent the most common consolidation failure: creating near-duplicate topic files because the agent didn't know what already existed.

Phase 2 -- Gather Signal

Targeted search for new information worth persisting. The prompt specifies three sources in priority order:

  1. Daily logs (logs/YYYY/MM/YYYY-MM-DD.md) -- the append-only stream written by KAIROS sessions
  2. Drifted memories -- existing memory facts that now contradict what the codebase shows
  3. Transcript search -- narrow grep against JSONL transcript files for specific context (e.g., an error message from a prior session)

The prompt explicitly warns: "Don't exhaustively read transcripts. Look only for things you already suspect matter." This is consistent with the grep-over-rag philosophy -- the dream agent greps narrowly rather than reading entire files. The transcript files are large JSONL, and the prompt tells the agent to grep -rn "<narrow term>" ... | tail -50 rather than catting them.

Phase 3 -- Consolidate

The core write phase. The agent writes or updates memory files at the top level of the memory directory, following the memory file format and type conventions from the system prompt's auto-memory section. The prompt specifies three focus areas:

The prompt delegates format decisions to the system prompt's auto-memory section rather than duplicating those rules, keeping the consolidation prompt focused on the workflow.

Phase 4 -- Prune and Index

The final phase maintains MEMORY.md as a compact index:

Tool Constraints

When invoked by the automatic background dream (autoDream.ts), the extra parameter appends a tool constraint notice: Bash is restricted to read-only commands (ls, find, grep, cat, stat, wc, head, tail). Writes to memory files use FileEdit and FileWrite tools, scoped to the memory directory by createAutoMemCanUseTool() from extractMemories.ts. When invoked manually via /dream, these Bash restrictions are absent -- the agent runs with normal permissions.

Completion

The prompt ends with: "Return a brief summary of what you consolidated, updated, or pruned. If nothing changed (memories are already tight), say so." This summary is captured by makeDreamProgressWatcher() in autoDream.ts and, if files were touched, surfaced to the user as an inline "Improved N memories" system message via appendSystemMessage().

Key claims

Relations

Sources