source dump of claude code
at main 65 lines 3.2 kB view raw
1// Extracted from dream.ts so auto-dream ships independently of KAIROS 2// feature flags (dream.ts is behind a feature()-gated require). 3 4import { 5 DIR_EXISTS_GUIDANCE, 6 ENTRYPOINT_NAME, 7 MAX_ENTRYPOINT_LINES, 8} from '../../memdir/memdir.js' 9 10export function buildConsolidationPrompt( 11 memoryRoot: string, 12 transcriptDir: string, 13 extra: string, 14): string { 15 return `# Dream: Memory Consolidation 16 17You are performing a dream — a reflective pass over your memory files. Synthesize what you've learned recently into durable, well-organized memories so that future sessions can orient quickly. 18 19Memory directory: \`${memoryRoot}\` 20${DIR_EXISTS_GUIDANCE} 21 22Session transcripts: \`${transcriptDir}\` (large JSONL files — grep narrowly, don't read whole files) 23 24--- 25 26## Phase 1 — Orient 27 28- \`ls\` the memory directory to see what already exists 29- Read \`${ENTRYPOINT_NAME}\` to understand the current index 30- Skim existing topic files so you improve them rather than creating duplicates 31- If \`logs/\` or \`sessions/\` subdirectories exist (assistant-mode layout), review recent entries there 32 33## Phase 2 — Gather recent signal 34 35Look for new information worth persisting. Sources in rough priority order: 36 371. **Daily logs** (\`logs/YYYY/MM/YYYY-MM-DD.md\`) if present — these are the append-only stream 382. **Existing memories that drifted** — facts that contradict something you see in the codebase now 393. **Transcript search** — if you need specific context (e.g., "what was the error message from yesterday's build failure?"), grep the JSONL transcripts for narrow terms: 40 \`grep -rn "<narrow term>" ${transcriptDir}/ --include="*.jsonl" | tail -50\` 41 42Don't exhaustively read transcripts. Look only for things you already suspect matter. 43 44## Phase 3 — Consolidate 45 46For each thing worth remembering, write or update a memory file at the top level of the memory directory. Use the memory file format and type conventions from your system prompt's auto-memory section — it's the source of truth for what to save, how to structure it, and what NOT to save. 47 48Focus on: 49- Merging new signal into existing topic files rather than creating near-duplicates 50- Converting relative dates ("yesterday", "last week") to absolute dates so they remain interpretable after time passes 51- Deleting contradicted facts — if today's investigation disproves an old memory, fix it at the source 52 53## Phase 4 — Prune and index 54 55Update \`${ENTRYPOINT_NAME}\` so it stays under ${MAX_ENTRYPOINT_LINES} lines AND under ~25KB. It's an **index**, not a dump — each entry should be one line under ~150 characters: \`- [Title](file.md) — one-line hook\`. Never write memory content directly into it. 56 57- Remove pointers to memories that are now stale, wrong, or superseded 58- Demote verbose entries: if an index line is over ~200 chars, it's carrying content that belongs in the topic file — shorten the line, move the detail 59- Add pointers to newly important memories 60- Resolve contradictions — if two files disagree, fix the wrong one 61 62--- 63 64Return a brief summary of what you consolidated, updated, or pruned. If nothing changed (memories are already tight), say so.${extra ? `\n\n## Additional context\n\n${extra}` : ''}` 65}