Export OpenCode plugin module with id so the UI shows its name - #2171
Open
svarlamov-git-ai wants to merge 1 commit into
Open
Export OpenCode plugin module with id so the UI shows its name#2171svarlamov-git-ai wants to merge 1 commit into
svarlamov-git-ai wants to merge 1 commit into
Conversation
OpenCode resolves a file-based plugin's display name from the `id` of a
default-exported plugin module ({ id, server }); without one the UI falls
back to the plugin's file:// path. Add that default export with
id "git-ai" while keeping the named GitAiPlugin function export, which
older OpenCode loaders (that call every export as a function) still
register through.
A full migration to the @opencode-ai/plugin v2 API suggested in the issue
is not possible yet: the shipped v2 plugin context has no tool.execute.*
hooks (they are only on OpenCode's v2 roadmap), so a pure v2 plugin would
lose all checkpointing.
Also add an integration test proving Markdown files written through
OpenCode's write tool get AI attribution (#2162), and recognize
"opencode" as an AI author in the test blame helper.
Fixes #2153
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Fixes #2153
Problem
The OpenCode plugin only exported a plain plugin function (what OpenCode now calls the legacy format), so OpenCode had no
idto display and fell back to showing the plugin asfile:///.../.config/opencode/plugins/git-ai.tsin its UI.Why not the v2 plugin API
The issue suggests migrating to
define({ id, setup })from@opencode-ai/plugin/v2/promise. I verified against OpenCode's source that the shipped v2 plugin context only exposes domain transforms (agent,catalog,command,integration,reference,skill) andaisdkhooks — it has notool.execute.before/afterhooks. Those are only on OpenCode's v2 roadmap (packages/plugin/src/v2/effect/PLAN.md, "Migrate Runtime Hooks → Tool execution hooks"). A pure v2 plugin would therefore lose all checkpointing, which is the plugin's entire purpose.Fix
Use OpenCode's supported module format instead, which is exactly where its loader reads a plugin's display name from (
resolvePluginId/readPluginIdinpackages/opencode/src/plugin/shared.ts— file-based plugins are expected to export anid):The named
GitAiPluginexport is kept for backwards compatibility: OpenCode versions predating the module format iterate a plugin module's exports and call each one as a function, and module namespace ordering putsGitAiPluginbeforedefault, so the plugin still registers there. Current OpenCode detects the default-exported module, uses itsid, and registersserver()exactly once (no double registration; verified the loader history — server-object unwrapping and module detection shipped together).The plugin typechecks cleanly against the latest published
@opencode-ai/pluginpackage (tsc --strict). Theimport typeis erased at runtime, so older installed type packages withoutPluginModuleare unaffected.Related: #2162
Investigated whether git-ai drops
.mdfiles from AI stats: it does not — default stats ignore patterns have no Markdown entries, and the OpenCode preset does no extension filtering. Added an integration test (test_opencode_new_markdown_file_gets_ai_attribution) proving a newskill.mdwritten through OpenCode'swritetool hooks gets full AI attribution. While writing it, found the test blame helper'sAI_AUTHOR_NAMESdidn't recognizeopencodeas an AI author; fixed. If #2162 reproduces for the reporter, a plugin that failed to load/display correctly (this issue) is a plausible cause.Test coverage
test_opencode_plugin_default_export_is_module_with_id(new, TDD — failed before the fix): asserts the module default export withid: "git-ai"and the retained named export.test_opencode_plugin_content_is_valid_typescriptupdated for the new imports/default export.test_opencode_new_markdown_file_gets_ai_attribution(new): end-to-end OpenCode-preset checkpoint flow on a new.mdfile, asserting committed line attribution.task lint, andtask fmtpass.🤖 Generated with Claude Code