magpie icon indicating copy to clipboard operation
magpie copied to clipboard

Memory digest: option to omit (why: …) from injected instructions

Open laweit-lxy opened this issue 1 week ago • 3 comments

Current behavior

On v0.1.4823, digestOf in internal/memory/digest.go (around L64–67) appends (why: …) to every entry that has a stored rationale, and that length counts against the digest budget. The only way to drop the suffix today is to clear the entry's why, which also deletes the rationale from the Memory library.

In one setup with about 35 active memories, the rationale suffixes make up roughly 38% of the injected memory section, about 1.7k tokens loaded at the start of every session.

Requested behavior

An option to omit the (why: …) suffix from the injected digest while keeping why in the stored entries, so it can still be reviewed in the Memory tab. Since the suffix counts against the budget, omitting it would also leave room for more entries.

Acceptance check

With the option on, the memory section of the generated CLAUDE.md / AGENTS.md contains no (why: suffixes, the stored entries still show their rationale in the Memory tab, and turning the option off restores the current output.

Per-project scoping of the digest is tracked in #7653.

laweit-lxy avatar Nov 26 '26 02:11 laweit-lxy

Fix branch: https://github.com/qq01-hub/magpie/tree/fix/memory-digest-omit-why (d7c663182) Compare: https://github.com/yetone/magpie/compare/main...qq01-hub:magpie:fix/memory-digest-omit-why

Changes:

  • internal/memory (memory.go, store.go, digest.go): persist digestNoWhy in meta.json, apply it in render before counting line lengths against the digest budget (so omitting (why: ...) frees budget room for more entries), keep every memory's stored Why untouched, and add DigestOmitWhy / SetDigestOmitWhy.
  • internal/library/instructions.go: extract syncPublishedMemory and add SetMemoryDigestOmitWhy so toggling the option immediately updates ticked agents' CLAUDE.md / AGENTS.md.
  • internal/gui/memory.go, internal/gui/assets/plugins/library/client.js, internal/gui/assets/plugins/library/i18n.js: expose digestOmitWhy in GET /api/memory, accept {"omitWhy": true|false} on POST /api/memory/digest (keeping {"on": ...} compatible), add the "Include reasons in summary" toggle below "In the agents' instructions" when digest injection is on, and add translations for zh, zh-TW, ja, and de.
  • Tests: TestDigestOmitWhy (internal/memory/digest_test.go), TestMemoryDigestOmitWhyInInstructions (internal/library/memory_digest_test.go), TestMemoryDigestOmitWhyRoute (internal/gui/memory_test.go), plus mock route update in internal/gui/tests/library-memory.test.cjs.

Verification (Windows 11 amd64, Go 1.26.8, Node):

  • go test -count=1 ./internal/memory (54/54), go test -count=5 ./internal/memory -run 'TestDigest' (20/20), go test -count=5 ./internal/library -run 'TestMemoryDigest' (10/10), go test -count=5 ./internal/gui -run 'TestMemory' (15/15) all passed.
  • node --test internal/gui/tests/i18n-keys.test.cjs internal/gui/tests/i18n-en-no-cjk.test.cjs (8/8) and node --check on edited JS files passed. (Playwright browser test library-memory.test.cjs was not run locally.)
  • go vet passed on Windows (./internal/memory ./internal/library ./internal/gui), Linux (-tags nogui on all 3), and macOS (-tags nogui on ./internal/memory ./internal/library).

qq01-hub avatar Nov 26 '26 05:11 qq01-hub

@laweit-lxy this is in v0.1.4845 (88222ca34), from @qq01-hub's branch, thanks to both!

Library → Memory → Advanced (below the Memory card, shown while the summary is in the instructions) has Include reasons in summary. Turn it off and the summary written into your agents' instructions leaves out each memory's (why: …), so the room goes to more memories; the why stays in the memory itself. It's on by default, so nobody's summary changes unless they turn it off.

Leaving this open until you've tried it.

yetone avatar Nov 26 '26 10:11 yetone

Thanks for adding this! I tested Include reasons in summary on Windows with Magpie v0.1.4866.

Turning it off immediately updated both Claude’s CLAUDE.md and Codex’s AGENTS.md. Each file lost exactly 41 (why: …) suffixes and shrank by 5,290 bytes. Everything else was byte-for-byte unchanged.

Turning it back on restored both files byte-for-byte to their original contents. I checked the files on disk, so the switch works as expected for me. Feel free to close the issue.

laweit-lxy avatar Nov 26 '26 14:11 laweit-lxy