Skip to content

refactor(opencode): use existing mem0 SDK instead of delegating to MCP, load skills properly instead of dumping them in .opencode - #5323

Merged
blazingretinol merged 14 commits into
mem0ai:mainfrom
ChrisFloofyKitsune:main
Jun 17, 2026

Conversation

@ChrisFloofyKitsune

Copy link
Copy Markdown
Contributor

Linked Issue

Closes # (or: N/A - OpenCode Stability Refactor)

Description

This PR stabilizes, refactors, and optimizes the Mem0 OpenCode plugin (@mem0/opencode-plugin), ensuring full compatibility with OpenCode's runtime environment, enhancing its performance, and adding rich documentation.

Key Improvements:

  1. Local Tool Registrations: Replaced the external CLI/MCP process dependency by moving all ten core Mem0 tools (including memory manipulation, user entity deletion, project switching, etc.) directly into opencode-mem0.ts as standard OpenCode tool registrations.
  2. Prefix-Isolated Skills: Adjusted the skills inside the .opencode-plugin/opencode-skills/ directory to utilize correct, prefix-isolated skill names (e.g., mem0:tour, mem0:remember) in their SKILL.md files, aligning precisely with OpenCode skill loading conventions.
  3. Environment Hygene: Updated the root .gitignore to permanently ignore .weave/ directory tracking to prevent local session/run caches from contaminating git commits.
  4. Enhanced Documentation: Added a comprehensive user guide in docs/integrations/opencode.mdx illustrating configuration, usage patterns, skills discovery, and local execution rules for the OpenCode plugin.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Refactor (no functional changes)
  • Documentation update

Breaking Changes

N/A

Test Coverage

  • I added/updated unit tests
  • I added/updated integration tests
  • I tested manually (describe below)
  • No tests needed (explain why)

Tested locally by compiling the typescript bundle, validating tool schema records, verifying correct parser outputs for skill definitions, and executing mock commands.

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have added tests that prove my fix/feature works
  • New and existing tests pass locally
  • I have updated documentation if needed

@CLAassistant

CLAassistant commented May 30, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@ChrisFloofyKitsune
ChrisFloofyKitsune marked this pull request as ready for review June 1, 2026 23:03
Builds on this PR's native-SDK-tools refactor:
- Telemetry: add telemetry.ts emitting the full shared plugin.* schema
  (session_start, user_prompt, tool_use per native tool, bash_error,
  pre_compact, session_stop) plus project_hash + os_version; tests included.
- Trim skills 16 -> 8 (keep context-loader, dream, forget, health, peek,
  pin, remember, tour); remove import, export, memory-reviewer, mem0,
  list-projects, switch-project, stats, onboard.
- Fix duplicate error-search (single topK:6); de-MCP wording in command
  template / hooks / kept skills; drop /mem0-onboard reference.
- Docs: native tools (not MCP server), 8 skills, config hook,
  experimental.chat.messages.transform name. package.json -> 0.2.0,
  drop mcp keyword, add config hook.
Updates this PR to current main, resolving the pre-integrations/ reorg
divergence. Conflicts were confined to the opencode-plugin and its docs
page; resolved so the plugin lives at integrations/mem0-plugin/.opencode-plugin
with our changes (native SDK tools, 8 skills, telemetry) applied on top of
current main.
Adds the pi-agent plugin's auto-dream feature, adapted to OpenCode's hooks:
- dream.ts: time/session/memory gates, filesystem lock, completion tracking,
  config (~/.mem0/settings.json `dream` block, MEM0_DREAM=false opt-out), and
  an OpenCode-native consolidation protocol (get_memories/add_memory/delete_memory).
- Wired into opencode-mem0.ts: increment session count + evaluate gates at
  session init; inject the protocol when gates pass; mark the consolidation
  done when a write tool runs; record completion + release the lock on exit.
- Emits plugin.dream_triggered / plugin.dream_completed telemetry.
- dream.test.ts: gates, lock exclusivity, completion reset, config loading.
Matches the pi-agent plugin's scope model (a tool parameter, not a stateful
"switch project" command):
- scope.ts: project / session / global resolution, ported from
  pi-agent/src/memory/scoping.ts (project = this repo; session adds run_id;
  global = app_id "*" reads / user-wide writes), plus tests.
- search_memories, get_memories, add_memory, delete_all_memories now accept an
  optional `scope` arg; sessionId is threaded through as run_id for session scope.
- Injects guidance so the agent uses "global" only when the user explicitly
  asks to search across all their projects in the workspace.
…iscovery)

OpenCode has no `skills.paths` config field, so the previous config-hook
approach was a no-op — skills were never discovered. And the `mem0:<skill>`
names were invalid (colon; must match the dir name and ^[a-z0-9]+(-[a-z0-9]+)*$).

- Install bundled skills into OpenCode's global skills dir
  (~/.config/opencode/skills), version-gated so it copies once per plugin
  version, where OpenCode natively discovers and lazy-loads them via its skill tool.
- Rename skills to valid names: mem0-<skill> (matches dir + regex).
- Register /mem0-<skill> slash commands via config.command (the supported field);
  update cross-skill references.
- Drop the dead opencodeConfig.skills.paths push.
The previous commit's /mem0: -> /mem0- pass used a Python one-liner that
truncated each file before reading it, emptying the 6 skills that contained
/mem0: cross-references (dream, forget, health, peek, remember, tour). Restore
their full content from d83d104 with the rename + cross-ref fixes applied
correctly.
OpenCode's global config dir differs by install — current builds use the XDG
dir (~/.config/opencode), older ones use legacy ~/.opencode. The skill
installer only targeted the XDG dir, so on legacy setups skills silently never
appeared. Now installs into both (XDG always; ~/.opencode when it exists),
version-gated per dir. Adds paths.ts (resolveSkillInstallDirs) + tests.
…eek→search)

Renames the two skills whose names diverged from the pi-agent plugin so the
opencode plugin exposes the same 8-skill set as pi-agent: context-loader,
dream, forget, pin, remember, search, status, tour.

- mem0-health -> mem0-status (command /mem0-status, incl. --deep quality scan)
- mem0-peek   -> mem0-search (command /mem0-search)

Updates in-skill titles/headers, the dream skill cross-reference, the README
skill list, and the 0.2.0 CHANGELOG entry. No code or hook changes — the hook
behaviors already mirror pi-agent (auto-dream, scope, auto-capture, context
injection), adapted to OpenCode's hook API.
- Add /mem0-scope skill to view/change the default scope (project/session/
  global), persisted to ~/.mem0/settings.json and read fresh per op (applies
  immediately, no restart). add_memory/search_memories/get_memories honor the
  default; delete_all_memories stays explicit-scope-only for safety.
- Fix project-id (app_id) detection: parse git remote owner/repo (incl. custom
  ssh host aliases) via new tested parseProjectFromRemote; fall back to the git
  repo root dir name instead of cwd/home.
- Auto-dream visibility: log the blocking gate and surface gate readiness in
  /mem0-status; harden session-start memory-count parsing.
- Update mem0-status, README, docs/integrations/opencode.mdx, CHANGELOG (0.2.0).
blazingretinol
blazingretinol previously approved these changes Jun 17, 2026
OpenCode 1.4.10 supports a skills.paths config field, so the config hook now
registers the plugin's own opencode-skills/ directory there. OpenCode discovers
the skills in place (recursive **/SKILL.md scan) and exposes the /mem0-* skill
commands — straight from the linked/installed plugin package.

- Remove installSkills() (copied skills into ~/.config/opencode/skills and the
  legacy ~/.opencode), its version-marker gating, and the now-redundant
  registerCommands custom-command registration. The plugin no longer writes into
  those dirs or creates ~/.opencode.
- Delete paths.ts/paths.test.ts (they only computed the copy-target dirs).
- Update CHANGELOG/README/docs to describe the skills.paths mechanism.
…de skills.paths

skills.paths makes skills discoverable for the agent's skill tool but does NOT
create TUI slash commands — OpenCode's slash menu is built from config.command.
The previous commit over-removed registerCommands, so /mem0-* disappeared from
the slash menu. Restore registerCommands (slash commands) and keep skills.paths
(in-place, no-copy skill discovery). Telemetry untouched. Docs corrected.
@blazingretinol
blazingretinol merged commit 9ed1983 into mem0ai:main Jun 17, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants