mem0-plugin/.opencode-plugin/opencode-skills/stats/SKILL.md
Show session and lifetime memory statistics.
Read the session identity from env vars set by the plugin's shell.env hook:
MEM0_USER_ID (falls back to $USER if unset)MEM0_APP_ID — the active project identifierMEM0_SESSION_ID — current session identifierMEM0_BRANCH — current git branchIf MEM0_USER_ID is unset, use $USER. If MEM0_APP_ID is unset, note "No project configured" and stop.
Call get_memories MCP tool to get the total count for this project:
filters={"AND": [{"user_id": "<MEM0_USER_ID>"}, {"app_id": "<MEM0_APP_ID>"}]}, page_size=1
Read the count field from the response — this is the total number of memories for the project regardless of page size.
Call get_memories MCP tool to retrieve memories for grouping:
filters={"AND": [{"user_id": "<MEM0_USER_ID>"}, {"app_id": "<MEM0_APP_ID>"}]}, page_size=200
Group each memory by:
categories[0] (platform-assigned) — primary groupingmetadata.type (agent-assigned) — secondary if categories is empty or absentcreated_at date — for age analysisCategory normalization: Merge auto_capture and uncategorized into a single uncategorized row. Do NOT show auto_capture as its own row.
Also run a search_memories MCP tool call with query="project", filters={"AND": [{"user_id": "<MEM0_USER_ID>"}, {"app_id": "<MEM0_APP_ID>"}]}, top_k=1 to measure round-trip latency. Note the time before and after the MCP call — do NOT attempt raw HTTP calls to the API.
Print a minimal plain-text dashboard. No markdown formatting — OpenCode TUI renders text verbatim.
Example output shape:
mem0 stats
Session (<first 12 chars of MEM0_SESSION_ID>) branch: main
Project: my-project — 55 memories — API: 84ms
Category Count
-------------------- -----
decision 24
convention 15
anti_pattern 6
task_learning 5
user_preference 3
session_state 2
Age — oldest: 2026-02-15 newest: 2026-05-23
< 7 days: 5 | 7-30d: 12 | 30-90d: 10 | > 90d: 8
Identity — user: kartik project: my-project branch: main
Display rules:
created_atWhen invoked with --weekly (e.g., /mem0:stats --weekly), append a weekly
activity digest after the standard stats dashboard.
Call search_memories in parallel with time-scoped queries:
query="decisions made this week", filters={"AND": [{"user_id": "<MEM0_USER_ID>"}, {"app_id": "<MEM0_APP_ID>"}, {"created_at": {"gte": "<7 days ago YYYY-MM-DD>"}}]}, top_k=20query="bugs errors fixes", same time filter, top_k=20query="patterns conventions learnings", same time filter, top_k=20Merge by ID. Group into "New this week" by categories[0] or metadata.type.
Calculate: memories added last 7 days, most active categories, most active day.
Append after the standard stats in plain text (no markdown):
This week (May 16 - May 23)
+12 memories — most active: Wednesday (5)
Category New
-------------- ---
decision 5
task_learning 4
bug_fix 3
Highlights
- <2-3 sentence summary of most important decisions/learnings this week>
Write to ~/.mem0/weekly-digest.txt (overwrite). Append one line to
~/.mem0/digest-history.log:
<YYYY-MM-DD> | <MEM0_APP_ID> | +<new_count> memories | top: <top_category>
If no new memories in 7 days, output:
No new memories in the past week. Total: <N> memories in <MEM0_APP_ID>.
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.