## ADDED Requirements ### Requirement: Three-tier memory architecture The system SHALL maintain three tiers of memory: Context (short-term/ephemeral), Daily (medium-term/file-based), and Core (long-term/distilled). #### Scenario: Context tier stores active session - **WHEN** an agent conversation is in progress - **THEN** the context tier SHALL track messages, token usage, and running summary - **WHEN** the session ends or context is trimmed - **THEN** the context SHALL be flushed to the daily tier #### Scenario: Daily tier persists as Markdown files - **WHEN** context is flushed - **THEN** the daily tier SHALL append summarized records to `memory/YYYY-MM-DD.md` - **THEN** each session block SHALL have a timestamped header (e.g., `## Trimmed Context (14:30)`) - **THEN** daily files SHALL be created lazily (only when first write occurs) #### Scenario: Core tier stores distilled long-term knowledge - **WHEN** Deep Dream consolidation runs - **THEN** the core tier SHALL be updated by rewriting `MEMORY.md` - **THEN** `MEMORY.md` SHALL be formatted as Markdown with `- ` bullet items, optionally grouped under `## headings` ### Requirement: Daily memory file management The system SHALL manage daily memory files with automatic creation and lazy initialization. #### Scenario: Lazy file creation - **WHEN** the first memory write occurs for a given day - **THEN** a file SHALL be created at `memory/YYYY-MM-DD.md` with a header `# Daily Memory: YYYY-MM-DD` #### Scenario: Append-only writes - **WHEN** subsequent memory writes occur on the same day - **THEN** new entries SHALL be appended to the existing daily file ### Requirement: Deep Dream consolidation The system SHALL periodically consolidate daily memories into the core memory using LLM-based distillation. #### Scenario: Deep Dream triggered - **WHEN** `deep_dream(lookback_days=N)` is called - **THEN** the system SHALL read current `MEMORY.md` and the last N daily files - **THEN** the LLM SHALL receive both the current memory and daily records - **THEN** the LLM SHALL return `[MEMORY]` and `[DREAM]` sections - **THEN** `MEMORY.md` SHALL be overwritten with the `[MEMORY]` content - **THEN** a dream diary SHALL be written to `memory/dreams/YYYY-MM-DD.md` #### Scenario: Dedup prevents redundant runs - **WHEN** Deep Dream is called but daily content hash matches the last processed hash - **THEN** the operation SHALL be skipped #### Scenario: No daily content skips gracefully - **WHEN** Deep Dream is called but no recent daily files have content - **THEN** the operation SHALL be skipped and existing `MEMORY.md` SHALL be preserved #### Scenario: No-fabrication constraint - **WHEN** the LLM produces the `[MEMORY]` section - **THEN** it SHALL ONLY use information present in the source materials (current MEMORY.md + daily files) - **THEN** it SHALL NOT fabricate, infer, or add information not present in the source ### Requirement: Context summary injection The system SHALL support injecting daily summary text into the active message list for context continuity. #### Scenario: Context summary callback - **WHEN** a daily memory flush completes - **THEN** an optional callback SHALL be invoked with the daily summary text - **THEN** the caller MAY inject the summary into the message list for continued context awareness