Skip to content

Export OpenCode plugin module with id so the UI shows its name - #2171

Open
svarlamov-git-ai wants to merge 1 commit into
mainfrom
fix/2153-1787153951
Open

Export OpenCode plugin module with id so the UI shows its name#2171
svarlamov-git-ai wants to merge 1 commit into
mainfrom
fix/2153-1787153951

Conversation

@svarlamov-git-ai

@svarlamov-git-ai svarlamov-git-ai commented Aug 19, 2026

Copy link
Copy Markdown

Fixes #2153

Problem

The OpenCode plugin only exported a plain plugin function (what OpenCode now calls the legacy format), so OpenCode had no id to display and fell back to showing the plugin as file:///.../.config/opencode/plugins/git-ai.ts in 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) and aisdk hooks — it has no tool.execute.before/after hooks. 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/readPluginId in packages/opencode/src/plugin/shared.ts — file-based plugins are expected to export an id):

const GitAiPluginModule: PluginModule = {
  id: "git-ai",
  server: GitAiPlugin,
}

export default GitAiPluginModule

The named GitAiPlugin export 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 puts GitAiPlugin before default, so the plugin still registers there. Current OpenCode detects the default-exported module, uses its id, and registers server() 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/plugin package (tsc --strict). The import type is erased at runtime, so older installed type packages without PluginModule are unaffected.

Related: #2162

Investigated whether git-ai drops .md files 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 new skill.md written through OpenCode's write tool hooks gets full AI attribution. While writing it, found the test blame helper's AI_AUTHOR_NAMES didn't recognize opencode as 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 with id: "git-ai" and the retained named export.
  • test_opencode_plugin_content_is_valid_typescript updated 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 .md file, asserting committed line attribution.
  • Full test suite, task lint, and task fmt pass.

🤖 Generated with Claude Code


Open in Devin Review

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>

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

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.

Name of plugin not shown in OpenCode

2 participants