Reworks @mem0/opencode-plugin to expose memory operations as native OpenCode tools (via the @opencode-ai/plugin `tool()` helper, backed by the mem0ai SDK) instead of delegating to the remote MCP server. Skills load via the `config` hook (`skills.paths`) instead of being copied into the project `.opencode/`. - Drop MCP: remove the regex-based MCP tool interception, the bundled opencode.json MCP registration, and the cli.ts installer (mem0-opencode bin). - Native tools: add_memory, search_memories, get_memories, get_memory, update_memory, delete_memory, delete_all_memories, delete_entities, list_entities, get_event_status. - Trim skills 16 -> 8 (context-loader, dream, forget, health, peek, pin, remember, tour); remove import, export, memory-reviewer, mem0, list-projects, switch-project, stats, onboard. De-MCP/onboard wording in kept skills. - Telemetry: emit the full shared plugin.* schema (adds user_prompt, bash_error, pre_compact, session_stop alongside session_start, tool_use); tool_use now fires from inside each native tool; add project_hash + os_version props. - Fix duplicate error-search (single topK:6); correct the documented experimental.chat.messages.transform hook name. - Bump to 0.2.0.
5.0 KiB
name, description
| name | description |
|---|---|
| health | Diagnoses mem0 connectivity, API key validity, and memory read/write functionality. Use when memory operations fail, searches return empty, add_memory errors occur, or to verify the plugin is working correctly. |
Mem0 Health Check
Run a diagnostic check on the mem0 plugin. Useful for troubleshooting.
Execution
Run ALL checks, then display a single summary. Do not stop on the first failure.
Check 1: API key
_KEY="${MEM0_API_KEY:-}"
[ -n "$_KEY" ] && echo "${_KEY:0:6}..." || echo "NOT_SET"
- If
NOT_SET: FAIL — "No API key configured" - If set: PASS — the command already prints only the first 6 chars
Check 2: Identity resolution
Resolve identity from environment variables set by the plugin's shell.env hook:
echo "user_id=${MEM0_USER_ID:-${USER:-}}"
echo "project_id=${MEM0_APP_ID:-}"
echo "branch=$(git branch --show-current 2>/dev/null || echo '')"
user_id: fromMEM0_USER_ID, falling back to$USERproject_id: fromMEM0_APP_IDbranch: fromgit branch --show-current
PASS if all three are non-empty. WARN if any falls back to defaults.
Check 3: Memory tool connectivity
Call search_memories with:
-
query="health check" -
filters={"AND": [{"user_id": "<active_user_id>"}, {"app_id": "<active_project_id>"}]} -
top_k=1 -
If returns successfully (even empty): PASS
-
If errors: FAIL — show the error message
Check 4: Memory write capability
Call add_memory with:
text="Health check probe — safe to delete."user_id=<active_user_id>app_id=<active_project_id>metadata={"type": "health_check", "probe": true}infer=False
The response returns event_id (v3 writes are async). Call get_event_status(event_id=<event_id>) to check processing.
- If status is
SUCCEEDED: PASS — extract the memory ID from the event result, then calldelete_memorywith that ID to clean up. - If status is
PENDINGafter 5 seconds: PASS (write accepted, processing delayed) - If errors: FAIL — show the error.
Check 5: Session context
Check that the plugin's shell.env hook has injected session context into the environment:
echo "session_id=${MEM0_SESSION_ID:-}"
echo "app_id=${MEM0_APP_ID:-}"
echo "branch=${MEM0_BRANCH:-}"
- If all three are non-empty: PASS — "Session active"
- If any are missing: WARN — "Plugin env vars not set; shell.env hook may not have fired"
Display
## mem0 health
PASS API Key m0-dVe...
PASS Identity user=kartik, project=mem0, branch=main
PASS Memory Tools 142ms
PASS Write/Read write + delete OK
PASS Session session_id=abc123, app_id=mem0, branch=main
All checks passed.
If any check fails, add a ## Troubleshooting section with specific fix steps for each failure.
Extended mode: Memory Quality Analysis
When invoked with --deep (e.g., /mem0:health --deep), run the standard 5 checks above plus a memory quality scan.
Quality Check 1: Duplicates
Call get_memories with filters={"AND": [{"user_id": "<active_user_id>"}, {"app_id": "<active_project_id>"}]}, page_size=200. Compare all pairs within the same metadata.type group for high textual overlap (shared nouns/keywords > 60%). Report:
Potential duplicates: <N> pairs
[mem0:<id1>] ≈ [mem0:<id2>] — both about "<shared topic>"
Quality Check 2: Stale memories
Flag memories where:
metadata.typeissession_stateorcompact_summaryAND older than 90 daysmetadata.confidence< 0.3 AND older than 30 days
Stale candidates: <N>
[mem0:<id>] — session_state, 142d old
Quality Check 2b: Low-confidence memories
Flag memories where metadata.confidence < 0.5 (regardless of age). Report separately from stale:
Low-confidence memories: <N>
[mem0:<id>] — confidence=0.3, "<content preview>"
Quality Check 3: Contradictions
Within each metadata.type group, flag pairs that assert opposing facts about the same topic. Use semantic judgment — look for negation patterns, conflicting tool/framework choices, or reversed decisions.
Possible contradictions: <N>
[mem0:<idA>] vs [mem0:<idB>] — conflicting on "<topic>"
Quality Check 4: Orphan memories
Memories with no metadata.type set, or with metadata.type not in the 17 known coding categories. These were likely written without proper tagging.
Untagged/orphan memories: <N>
Quality summary
## Memory Quality
Duplicates: <N> · Stale: <N> · Contradictions: <N> · Orphans: <N>
If all counts are 0: Memory quality: clean.
If any non-zero: append Run /mem0:dream to fix.
To fix issues found by --deep, run /mem0:dream for automated consolidation (merges, prunes, conflict resolution).
Output formatting
IMPORTANT: Do NOT use markdown in your output. OpenCode TUI renders text verbatim — markdown like bold, ## headers, and | table | syntax appears as raw characters. Use plain text with indentation for structure. Use dashes for lists. Use spaces to align columns instead of markdown tables.