Generate a concise, narrative reflection summary from recent session history and write it to memory/context/reflection.md.
-
Discover session files
Read all .md files from memory/sessions/. Each session file has YAML frontmatter with (at minimum) a startedAt field (ISO 8601 timestamp). Also note endedAt, threadId, and messageCount fields.
-
Filter by 7-day window
Parse the startedAt frontmatter from each session. Keep only sessions where startedAt is within the last 7 days from the current time. Exclude any session files that lack a valid startedAt field.
-
Sort by recency
Sort the filtered sessions by startedAt in descending order so the most recent session appears first.
-
Generate the narrative summary
Read each session's JSON messages (the body after frontmatter). For each session, produce a brief paragraph that captures:
- The mood, energy, or emotional tone the user brought to the conversation
- The nature of the interaction (e.g., playful, focused, exploratory, frustrated, collaborative)
- High-level context about what was being worked on (but NOT technical details, code, or step-by-step procedures)
Combine all paragraphs into a single flowing narrative. Connect sessions chronologically so the reader can follow how the relationship evolved over the past week.
Keep the output in the range of 200-400 words. Prioritize recent sessions: give more detail to the newest ones, summarize older ones sparingly.
-
Write memory/context/reflection.md
Write the result as a Markdown file with frontmatter:
---
updatedDate: "<current ISO 8601 timestamp>"
timestamp: "<same as updatedDate>"
---
Follow the frontmatter with the narrative body. Always write the file, even if there is nothing to report.
-
Ensure size constraints
The total file size (frontmatter + body) MUST NOT exceed 5 kB (approximately 20k tokens). If the generated summary would exceed this limit, trim oldest sessions first until the file fits. Never write a file larger than 5 kB.