Add OpenCode plugin to match Claude Code hooks behavior#5
Draft
madisonbullard wants to merge 27 commits intoglommer:mainfrom
Draft
Add OpenCode plugin to match Claude Code hooks behavior#5madisonbullard wants to merge 27 commits intoglommer:mainfrom
madisonbullard wants to merge 27 commits intoglommer:mainfrom
Conversation
Replaces the short-lived ADR 0005 optional-SDK-dep approach. createEmbedder now lives exclusively in packages/embedder (memelord-embedder), which has @huggingface/transformers as its sole hard dependency. The SDK (memelord) no longer knows about or depends on transformers. The CLI re-exports createEmbedder from memelord-embedder; the OpenCode plugin template imports it from memelord-embedder directly. ADR 0005 and OPENCODE_PLUGIN_PLAN.md updated to reflect the new layout.
Copy the OpenCode plugin template into dist during build so the bundled CLI can generate .opencode/plugins/memelord.ts. Add an init regression test and mark Phase 6.5 complete in the plan.
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.
This PR adds an OpenCode plugin to
memelordthat replicates the behavior of the existing Claude Code hooks, implemented as a standalone integration that shares no runtime code with the CC side. (Sharing code could happen in a future PR). The plugin is authored as a TypeScript file (packages/cli/src/opencode/plugin-template.ts) and installed by memelord init.The four Claude Code hook behaviors are mapped to OpenCode primitives: memory injection on
session.created, tool failure recording ontool.execute.after, per-turn transcript analysis onsession.idle, and embed/decay/cleanup in a detached background process spawned fromsession.idle(ADR 0003). Because OpenCode exposes no reliable session-end event (akin to CC'sStophook), the embed/decay work runs in a detached Node process with a 90-second delay and a latest-wins schedule token to avoid redundant or concurrent work (ADR 0004).Tool failure detection uses the canonical
ToolPart.statediscriminated union — looking up the tool part bycallIDafter eachtool.execute.aftercall — rather than heuristic string scanning, handling both status: "error" (read,webfetch) and status: "completed" with non-zerometadata.exit(bash) (ADR 0008). Transcript analysis onsession.idleruns fresh on every turn with no idempotency guard, mirroring CC's Stop hook behavior (ADR 0007).The
createEmbedderfunction is extracted into a dedicatedmemelord-embedderpackage so the SDK remains free of the@huggingface/transformersdependency, and the plugin imports it directly (ADR 0005).memelord initis updated to write the generated plugin file and a corresponding.opencode/package.jsonalongside the existing Claude Code and MCP setup steps.Merging this will close #2.