Skip to content

fix(store): keep hand-written MEMORY.md index lines - #51

Merged
kuitos merged 1 commit into
mainfrom
fix/keep-hand-written-index-lines
Oct 7, 2026
Merged

kuitos merged 1 commit into
mainfrom
fix/keep-hand-written-index-lines

Conversation

@kuitos

@kuitos kuitos commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner

Problem

MemoryStore.save() rewrote a memory's MEMORY.md line on every save, even when someone had written that line by hand. The line was rebuilt as - [<name>](<file>) — <description>, and a re-save by the main agent, an extraction fork or auto-dream replaced the user's own title and hook with it (#49: "it also rewrote … the whole MEMORY.md, which replaced our hand-written index lines").

Reproduced with MemoryStore on main (ef15ddb). The test seeds a memory, writes its index line by hand, then re-saves it with a new description:

# main@ef15ddb, after the re-save
## Working with me
- [terse-answers](terse-answers.md) — User wants terse answers without trailing summaries

# this branch, after the re-save
## Working with me
- [Terse please](terse-answers.md) — no recaps at the end

Fix

  • save() adds a pointer line only when the index has none for the file.
  • An existing line is replaced only when it is exactly the line the plugin would have generated from the memory's previous name and description, i.e. the plugin wrote it and nobody edited it. Any other line is kept verbatim.
  • findIndexPointerLine() (store/indexFile.ts) finds the line that points at a file. All edits still go through upsertIndexLine / removeIndexLine.
  • A save whose content is unchanged still adds a pointer when the index has none.
  • AGENTS.md (anti-patterns) and the README compatibility row document the rule.

Tests

  • test/store/MemoryStore.test.ts ("MemoryStore index lines written by hand (Memories deleted or rewritten without being asked (read-only questions, extraction, auto-dream) #49)"):
    • a hand-written line survives an identical re-save, a new description and a new body;
    • a line still exactly as the plugin generated it follows a new name or description;
    • a memory without a pointer gains one without its file being rewritten;
    • a pointer written before the memory exists is kept;
    • re-saving every memory, as a consolidation pass does, leaves a hand-written index (with headings) byte-identical.
  • test/store/indexFile.test.ts: findIndexPointerLine.
  • bun run lint, bun run typecheck, bun test and bun run build pass.

Real-environment verification (OpenCode 2.0.22, isolated DB/config, memory agents on opencode/gpt-6-luna)

Auto-dream run over 5 seeded memories, with a hand-written MEMORY.md under ## headings, a duplicate pair and an expired sprint goal. Measured on the top of this stack, since the dream prompt changes in #53:

  • main@ef15ddb, 2/2 runs: every surviving index line was replaced with a [slug] — description line. [Terse please] and [Real DB in tests] were lost.
  • Stack, 3/3 runs:
    • the hand-written lines of all 3 surviving memories were kept byte for byte;
    • only the lines of the deleted memories were removed (a merged duplicate and the expired sprint goal);
    • this held even when the dream re-saved the merged memory with a new description.

Refs #49

🤖 Generated with Claude Code

MemoryStore.save() replaced any existing pointer for the saved file with
the generated `- [name](file) — description` line, and an identical
re-save only counted as unchanged when that exact generated line was in
the index. A hand-written line (Claude Code's `- [Title](file.md) — hook`)
was therefore overwritten on every save, and auto-dream re-saving its
memories replaced all of them.

An existing pointer is now kept unless it is still exactly the line
generated from the memory's previous name and description; a memory
without a pointer gains one, and an otherwise identical re-save only
adds that missing pointer without rewriting the file.

Refs #49
@kuitos
kuitos force-pushed the fix/keep-hand-written-index-lines branch from 31c2b38 to fe329ba Compare October 7, 2026 15:19
@kuitos
kuitos merged commit 04fe1f3 into main Oct 7, 2026
6 checks passed
@kuitos
kuitos deleted the fix/keep-hand-written-index-lines branch October 7, 2026 15:23
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 2.1.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant