Skip to content

feat: port the plugin to OpenCode v2 and drop v1 support - #4

Draft
devadathanmb wants to merge 2 commits into
mainfrom
v2-migration
Draft

devadathanmb wants to merge 2 commits into
mainfrom
v2-migration

Conversation

@devadathanmb

Copy link
Copy Markdown
Owner

Summary

  • Ports the plugin to the OpenCode v2 plugin API and drops OpenCode v1 support (breaking change for a major release).
    • src/index.ts is a thin Effect-API shell: it registers the session context, compaction, title and generate hooks plus an MCP transform, and logs through the host logger tagged plugin=easy-vision (OpenCode discards plugin console output).
    • @opencode/* imports are type-only; effect is an optional peer that the host supplies at runtime, so the published package depends only on strip-json-comments. A root index.js bridge supports local-directory loading.
  • Rewrites images in outgoing model context instead of chat history: images in every user message become saved paths, only the latest user message gets tool guidance, and {userText} contains only the user's typed text (no skill bodies or attached-file contents). Unmatched models, other project locations and image-free requests are untouched; failures become model-visible notes.
  • Safer image files: content-hashed, atomically written 0600 files; an existing file is reused only if it is a regular file owned by the current user with the expected size (planted symlinks are replaced), and reuse refreshes its mtime so startup cleanup never deletes an image in use.
  • MCP Code Mode handling: the plugin turns off Code Mode for the server providing imageAnalysisTool so the model can call it directly (new disableCodeMode option). An explicit codemode setting wins, an ambiguous server match changes nothing, and if the tool stays behind Code Mode the prompt routes the model through execute.
  • Config changes: one config store per plugin instance, default imageAnalysisTool is now MiniMax_understand_image, and the legacy opencode-minimax-easy-vision config filenames, temp directory and UUID cleanup are removed.
  • Tests: a TypeScript Vitest suite with one test file per module, type-checked in CI with coverage thresholds. It covers config precedence and validation, the shipped example config, image source handling and file-safety rules, transform/prompt behavior, Code Mode server matching, request routing, the Effect shell's logging and hooks, and the package contract. scripts/v2-spike/ runs the plugin inside a real OpenCode binary and asserts the tool route with codemode false, true and unset.
  • Tooling and docs: a justfile (including check, runtime-pack and a confirmation-gated release); README adds v1 pinning and an "Upgrading from 1.x" guide; CONFIGURATION, AGENT_SETUP, CONTRIBUTING, AGENTS and the example config are updated for v2.

- Replace the v1 `experimental.chat.messages.transform` hook with an Effect-based plugin in `src/index.ts` that registers the session `context`, `compaction`, `title` and `generate` hooks plus an MCP transform. Logs go through the host Effect logger, tagged `plugin=easy-vision`.
- Rewrite images across all user messages in outgoing context (`src/transform.ts`, `src/request.ts`): each image becomes its saved path, only the latest user message gets tool guidance, `{userText}` excludes skill bodies and attached-file contents, and failures become model-visible notes. Requests for other locations, unmatched models or messages without images are left untouched.
- Handle v2 media sources in `src/images.ts`: save bytes, base64 and data URLs to content-hashed files written atomically with mode 0600; reuse an existing file only if it is a regular file owned by the current user with the expected size, refreshing its mtime so cleanup keeps files in use, and otherwise replace it. Pass file and HTTP(S) URLs through, and reject provider refs, private-header and expired URLs without leaking details. `src/file-lock.ts` serializes writes and cleanup per path.
- Detect direct, Code Mode or unavailable tool exposure (`src/v2.ts`) and turn off MCP Code Mode for the server providing `imageAnalysisTool` (`src/codemode.ts`), controlled by the new `disableCodeMode` option. An explicit `codemode` setting is respected, and nothing changes when the tool name could belong to more than one server.
- Give each plugin instance its own config store (`createConfigStore`), change the default `imageAnalysisTool` to `MiniMax_understand_image`, and remove the legacy `opencode-minimax-easy-vision` config filenames, legacy temp directory and UUID cleanup pattern.
- Keep `@opencode/*` imports type-only, make `effect` an optional peer dependency, add the root `index.js` bridge for local-directory loading and `exports`, and require Node >=22.18.
- Add a Vitest suite in TypeScript with one test file per module, shared fixtures in `test/helpers.ts`, a package-contract test, coverage thresholds in `vitest.config.ts` and test type-checking via `tsconfig.test.json`. CI now type-checks tests and enforces coverage.
- Add end-to-end fixture scripts under `scripts/v2-spike/` that run the plugin inside a real OpenCode binary and assert the tool route for `codemode: false`, `codemode: true` and unset MCP servers.
- Update README (v1 pinning, upgrading from 1.x, Code Mode, logs), CONFIGURATION, AGENT_SETUP, CONTRIBUTING, AGENTS and the example config for v2.

BREAKING CHANGE: requires OpenCode v2; OpenCode v1 users must pin `opencode-easy-vision@1`. The default `imageAnalysisTool` is now `MiniMax_understand_image`, and `opencode-minimax-easy-vision.json(c)` config files are no longer read.
- Add `justfile` recipes for install, build, test (with Vitest arg passthrough), watch, coverage, typecheck, fmt, fmt-check, clean and `check`, which mirrors CI.
- Add `runtime` and `runtime-pack` recipes that run the end-to-end fixture against the checkout and against an npm-packed tarball installed in a clean project.
- Add a confirmation-gated `release` recipe that runs `check`, `npm version` and `git push --follow-tags`.
- Switch the command sections of AGENTS.md and CONTRIBUTING.md to just recipes, and correct the Husky note to say formatting covers `src/` and `test/`.

This branch has not been deployed

No deployments
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.

1 participant