fix(plugin): preserve structure on PreCompact + capture compact summary
Two changes to the compaction flow: PreCompact: agent stores its summary with infer=False on_pre_compact.sh now instructs the agent to call add_memory with infer=False. The agent has full conversation context and writes a structured summary; without infer=False the platform runs a second LLM extraction pass over that summary, losing structure and producing fragmented facts. With it, the structured text is preserved verbatim. Same guidance added to mem0-mcp/SKILL.md so the agent applies it to other already-extracted writes (decisions, anti-patterns, conventions). SessionStart-compact: capture the platform-generated summary PreCompact fires BEFORE Claude Code generates its compact summary, so the summary is unreachable from that hook. SessionStart-compact fires AFTER, so a new background helper (capture_compact_summary.py) reads the transcript at that point, finds the isCompactSummary=true entry, and stores its content as a separate memory tagged metadata.type=compact_summary. The post-compaction bootstrap text now tells the agent to layer its recall queries across session_state (its own pre-compact summary), compact_summary (the platform's condensed view), and topical types like decision / anti_pattern. Net effect: three complementary memory types from one session boundary, none of which used to be filterable or even captured correctly.
This commit is contained in:
@@ -99,6 +99,21 @@ Extract key learnings and store them using the `add_memory` tool:
|
||||
|
||||
Memories can be as detailed as needed -- include full context, reasoning, code snippets, file paths, and examples. Longer, searchable memories are more valuable than vague one-liners.
|
||||
|
||||
### Use `infer=False` for already-structured content
|
||||
|
||||
When you've done the extraction work yourself — pre-compaction summaries, decisions, anti-patterns, conventions you've explicitly identified — pass `infer=False` so the platform stores your text verbatim instead of running a second extraction pass over it.
|
||||
|
||||
```python
|
||||
add_memory(
|
||||
messages=[{"role": "user", "content": "<your structured fact>"}],
|
||||
user_id="<active user_id>",
|
||||
metadata={"type": "decision"},
|
||||
infer=False,
|
||||
)
|
||||
```
|
||||
|
||||
Stick to one mode per distinct piece of content — don't mix `infer=True` (default) and `infer=False` for the same fact, you'll get duplicates. Default (`infer=True`) is right for raw conversational signal you want extracted; `infer=False` is right for pre-extracted structure.
|
||||
|
||||
## Before losing context
|
||||
|
||||
If context is about to be compacted or the session is ending, store a comprehensive session summary:
|
||||
|
||||
Reference in New Issue
Block a user