Skip to content

[Suggestion] Migrate model-usage plugin to OpenCode v2 #47

Closed

Description

@Wikijito7

Is your feature request related to a problem? Please describe.

The plugin currently targets the legacy OpenCode plugin API. OpenCode v2 changes plugin entrypoints, TUI APIs, configuration, event handling, storage, and server hooks.

Affected areas include:

  • model-usage.tsx
  • model-usage-server.ts
  • model-usage/sidebar.tsx
  • model-usage/usage.tsx
  • model-usage/analyze.tsx
  • model-usage/wlib/
  • Global tui.json and opencode.json
  • The related persona-injector plugin

Describe the solution you'd like

Migrate the plugin to the OpenCode v2 API while preserving as much functionality as possible.

Implementation plan:

  • Replace legacy server exports with Plugin.define({ id, setup }).
  • Replace legacy server hook registration with v2 session.hook and tool.hook.
  • Replace experimental.chat.system.transform with the v2 context hook where possible.
  • Decide how to handle system snapshot ordering and final prompt capture.
  • Replace tool.definition capture or remove the Tool Defs feature if no supported v2 API exists.
  • Replace the { id, tui } TUI module with the v2 CLI plugin setup API.
  • Replace api.slots.register with context.ui.slot.
  • Replace api.keymap.registerLayer with context.keymap.layer.
  • Update command metadata and slash-command definitions.
  • Replace legacy dialog APIs with context.ui.dialog.show, set, and clear.
  • Update wlib keymap, dialog, theme, and export helpers.
  • Replace api.state and api.event usage with v2 context.data.
  • Update event names and payload handling.
  • Replace direct internal SQLite reads with supported v2 client/data APIs.
  • Review plugin-owned JSON persistence and migrate to v2 storage where appropriate.
  • Preserve or redesign the shared persona-injector system snapshot contract.
  • Replace tui.json registration with v2 opencode.json, cli.json, or plugins/tui/ discovery.
  • Migrate legacy configuration keys such as agent, provider, permission, and MCP registration as required by v2.
  • Add or update package metadata if the plugin is distributed as an npm package.
  • Run unit tests and typechecking.
  • Verify loading and behavior with the exact opencode2 beta build.
  • Verify /usage, /analyze, sidebar rendering, keyboard shortcuts, exports, and quota fetching.

Acceptance criteria

  • The plugin loads without legacy API warnings or errors in opencode2.
  • /usage and /analyze remain available.
  • Sidebar usage and quota indicators render correctly.
  • Dialog navigation, resizing, scrolling, exports, and shortcuts work.
  • Historical usage data works without relying on unstable internal database paths.
  • Unsupported features are documented clearly.
  • Existing tests pass.

Additional context

The v2 documentation is currently beta and may change:

The tool.definition hook and exact final system-prompt observation semantics appear to have no direct v2 equivalent and require explicit design decisions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions