feat(plugin): holistic import of on-disk Claude state into mem0
When a user installs mem0-plugin, mem0 starts empty even though Claude Code has been quietly accumulating their CLAUDE.md instructions, auto-memory, and subagent learnings on disk for months. The existing hooks capture live state going forward but cannot backfill what already exists. This commit adds a one-shot importer that walks every Claude state surface and backfills it into mem0: - `mem0-plugin/scripts/import_claude_state.py` (new, ~575 lines): discovers CLAUDE.md hierarchy (+ @imports), .claude/rules, ~/.claude/projects/*/memory, and ~/.claude/agent-memory; chunks each file at markdown headings (H2 default, H3 for oversize sections, small-sibling merge, code-fence safe); tags chunks with metadata matching the existing mem0-mcp skill vocabulary (convention / user_preference / task_learning / anti_pattern / decision); POSTs sequentially to /v1/memories/ with infer=True (server-side dedup). Marker file at ~/.mem0/imports/claude-state.json tracks content-hash per chunk for idempotent re-runs and crash-resume safety. Flags: --dry-run, --reset, --no-infer, --source <type>. - `mem0-plugin/scripts/on_session_start.sh`: adds a one-time nudge block after the existing bootstrap output. Emits the holistic-import prompt only when ~/.mem0/imports/claude-state.json doesn't exist and the SOURCE isn't "compact". Propagates to Cursor and Codex for free (shared bash entry point). - README, CHANGELOG, plugin.json bumped to 0.2.0. Patterned exactly on the existing on_pre_compact.py: stdlib only (urllib, hashlib, pathlib, argparse), reuses _identity.resolve_user_id, same logging setup, same ~/.mem0/ storage convention. Zero new packages, zero new deps. Smoke-tested locally: --help renders, missing MEM0_API_KEY exits 1 with helpful message, hook emits nudge when marker absent and stays silent when marker present. Research and design context: https://www.notion.so/Claude-State-Holistic-Import-Research-Findings-366f22c70c9081d7abdcc6b94a80e8d9
This commit is contained in:
@@ -84,4 +84,23 @@ is being captured to mem0 in the background as `metadata.type=compact_summary`.
|
||||
EOF
|
||||
fi
|
||||
|
||||
# ── Holistic import nudge ────────────────────────────────────────────────
|
||||
# One-time nudge to backfill existing CLAUDE.md / MEMORY.md / agent-memory
|
||||
# into mem0. Silent after the marker file appears (i.e., after first run).
|
||||
# Only emit on startup or resume -- during compact the user is mid-conversation.
|
||||
if [ "$SOURCE" != "compact" ] && [ ! -f "$HOME/.mem0/imports/claude-state.json" ]; then
|
||||
cat <<EOF
|
||||
|
||||
## Holistic import available
|
||||
|
||||
On-disk Claude state (CLAUDE.md, ~/.claude/projects/*/memory, ~/.claude/agent-memory)
|
||||
has never been imported into mem0. To preview what would be imported, run:
|
||||
|
||||
python3 "$SCRIPT_DIR/import_claude_state.py" --dry-run
|
||||
|
||||
Then drop \`--dry-run\` to import. This nudge disappears after the first
|
||||
successful run. Pass \`--reset\` to re-import from scratch.
|
||||
EOF
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user