Skip to content

feat: pi-dream — memory consolidation (memory_dream tool + /pi-dream command) - #34

Open
KrissTos wants to merge 4 commits into
jayzeng:mainfrom
KrissTos:feat/pi-dream-consolidation
Open

feat: pi-dream — memory consolidation (memory_dream tool + /pi-dream command)#34
KrissTos wants to merge 4 commits into
jayzeng:mainfrom
KrissTos:feat/pi-dream-consolidation

Conversation

@KrissTos

Copy link
Copy Markdown

Summary

Adds memory_dream, a memory consolidation pass for long-term memory (MEMORY.md), exposed both as a tool and a read-only /pi-dream command.

After many sessions, MEMORY.md accumulates near-duplicate entries and older entries that are superseded by newer ones about the same topic. Bloat here is injected into every session start — wasted context tokens plus stale-recall risk.

What it does

  • Detection (pure, exported functions): parses entries using the same block unit as forgetBlocks, then:
    • groups near-duplicate entries via Jaccard similarity over word tokens (default threshold 0.75)
    • flags superseded entries: similar (default ≥0.6) older/newer pairs with ≥7 days age gap
  • Two modes:
    • mode:'report' (default) — analyzes without touching files; returns grouped findings with previews
    • mode:'apply' — removes redundant older copies through the existing recovery-record pipeline: writes a complete recovery/ record before mutating the file (undoable via memory_restore), marks snapshot dirty, schedules qmd update

Design notes

  • Reuses the established write pipeline instead of a parallel one: recovery records, snapshotDirty, and debounced qmd updates behave exactly like memory_forget
  • Thresholds tunable per call via duplicateSimilarity / supersedeSimilarity parameters
  • /pi-dream command gives an instant health-check notification without any file mutation
  • Detection is intentionally heuristic-only (no LLM call); contradiction-style merges needing semantic judgment stay out of scope for now

Testing

  • 10 new unit tests covering parsing, similarity, duplicate grouping, supersede age-gap rules, apply/recovery round-trip, report-mode file safety
  • Full suite: 192 tests pass, tsc clean, biome clean

Command example

```
/pi-dream → notification: "12 entries, 2 duplicate group(s), 3 superseded → 4 removable"
memory_dream {} → full findings report with previews
memory_dream { mode: "apply" } → consolidation with recovery ID
```

…command)

- parseMemoryBlocks/dreamSimilarity/dreamAnalyze/dreamDropIndices/dreamApply pure functions
- memory_dream tool: report mode (read-only findings) + apply mode (removes duplicate
  older copies and superseded entries via existing recovery-record pipeline, undoable
  with memory_restore; refreshes snapshot + qmd index)
- /pi-dream command: quick read-only health check with notification summary
- 10 new unit tests (192 total pass), tsc + biome clean

Signed-off-by: KrissTos <cristiano.tosoni@gmail.com>
- /pi-dream (or /pi-dream report) → sends user message asking agent to run
  memory_dream report mode and show full findings in conversation
- /pi-dream apply → runs apply mode, shows removed entries + recovery ID
- replaces cramped notify-only health check

Signed-off-by: KrissTos <cristiano.tosoni@gmail.com>
…ded)

Signed-off-by: KrissTos <cristiano.tosoni@gmail.com>
Signed-off-by: KrissTos <cristiano.tosoni@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant