Repository navigation
feat: port the plugin to OpenCode v2 and drop v1 support - #4
Draft
devadathanmb wants to merge 2 commits into
Draft
devadathanmb wants to merge 2 commits into
devadathanmb wants to merge 2 commits into
Conversation
- 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
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.
Summary
src/index.tsis a thin Effect-API shell: it registers the sessioncontext,compaction,titleandgeneratehooks plus an MCP transform, and logs through the host logger taggedplugin=easy-vision(OpenCode discards pluginconsoleoutput).@opencode/*imports are type-only;effectis an optional peer that the host supplies at runtime, so the published package depends only onstrip-json-comments. A rootindex.jsbridge supports local-directory loading.{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.0600files; 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.imageAnalysisToolso the model can call it directly (newdisableCodeModeoption). An explicitcodemodesetting wins, an ambiguous server match changes nothing, and if the tool stays behind Code Mode the prompt routes the model throughexecute.imageAnalysisToolis nowMiniMax_understand_image, and the legacyopencode-minimax-easy-visionconfig filenames, temp directory and UUID cleanup are removed.scripts/v2-spike/runs the plugin inside a real OpenCode binary and asserts the tool route withcodemodefalse, true and unset.justfile(includingcheck,runtime-packand a confirmation-gatedrelease); README adds v1 pinning and an "Upgrading from 1.x" guide; CONFIGURATION, AGENT_SETUP, CONTRIBUTING, AGENTS and the example config are updated for v2.