Repository navigation
refactor(opencode): use existing mem0 SDK instead of delegating to MCP, load skills properly instead of dumping them in .opencode - #5323
Merged
Conversation
…register commands
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
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
approved these changes
Jun 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
opencode-mem0.tsas standard OpenCode tool registrations..opencode-plugin/opencode-skills/directory to utilize correct, prefix-isolated skill names (e.g.,mem0:tour,mem0:remember) in theirSKILL.mdfiles, aligning precisely with OpenCode skill loading conventions..gitignoreto permanently ignore.weave/directory tracking to prevent local session/run caches from contaminating git commits.docs/integrations/opencode.mdxillustrating configuration, usage patterns, skills discovery, and local execution rules for the OpenCode plugin.Type of Change
Breaking Changes
N/A
Test Coverage
Tested locally by compiling the typescript bundle, validating tool schema records, verifying correct parser outputs for skill definitions, and executing mock commands.
Checklist