fix(context): preserve ## <Agent>-Specific sections through round-trip#482
Merged
fix(context): preserve ## <Agent>-Specific sections through round-trip#482
## <Agent>-Specific sections through round-trip#482Conversation
`extract_sections_from_agent_file` mapped each agent-override heading (`## Claude-Specific`, `## Cursor-Specific`, …) to its literal heading string, but the generators look for canonical keys (`Claude`, `Cursor`, …). On `mm context init` (extract-existing) followed by `mm context generate`, the override section was silently dropped and `mm context diff` reported `[in sync]` because both sides had the same loss — masking the data loss from the user. Add the five aliases to the reverse-extract map so override sections survive the round-trip. Also fix `CopilotGenerator`, which emitted the override content without any `##` heading; a second round-trip absorbed it into the preceding section. It now writes `## Copilot-Specific` like the other four generators. Regression test parametrizes all five agents; they all assert that a `## <Agent>-Specific` heading + body survive `extract_sections → generate_for_agent`. Co-Authored-By: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mm context init→mm context generateround-trip silently dropped## <Agent>-Specificoverride sections, andmm context diffreported[in sync]because both sides had the same loss — masking the data loss. This fixes the round-trip and adds a regression test.Root cause
extract_sections_from_agent_filemaps headings to canonical section keys via thealiasesdict. The five## <Agent>-Specificheadings (Claude / Cursor / Gemini / Codex / Copilot) had no entries in that dict, so they were stored under their literal heading strings (Claude-Specific, …). Each generator then checks for the canonical key (if "Claude" in sections: …), which was never populated, so the override section was discarded on regeneration.mm context diffcompared the regenerated output against the just-regenerated file (both written by the same code path), so the diff was[in sync]even though both sides were missing the override content.Fix
claude-specific→Claude, etc.) toextract_sections_from_agent_file's alias map so each override heading resolves to the canonical key the generators look for.CopilotGeneratorwas additionally asymmetric: it emitted the override content without any##heading, so a second round-trip extracted it as part of the preceding## Commandssection. Fixed to write## Copilot-Specificlike the other four generators.Test plan
uv run pytest packages/memtomem/tests/test_context.py— 23 passed (5 new parametrized round-trip cases)uv run pytest -m "not ollama"— 2481 passeduv run ruff check packages/memtomem/src packages/memtomem/tests— cleanuv run ruff format --check …— cleanCLAUDE.mdcontaining## Claude-Specific, runextract_sections_from_agent_file+generate_for_agent("claude", …), confirm content survives. (Before this PR: dropped. After: preserved.)🤖 Generated with Claude Code