Repository navigation
fix(opencode): translate canonical hook matchers to OpenCode tool names - #3950
Merged
Merged
Conversation
OpenCode 2.x reports lowercase tool names (read, write, edit, shell) and tests hook matchers case-sensitively, so canonical matchers such as Read|Edit|Write never fired. Translate Read, Write, Edit and Bash to their OpenCode names in the generated V2 plugin and warn about capitalized names with no OpenCode equivalent. Closes #3944 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
… per matcher Apply the canonical tool name translation to the V1 plugin generator shared by opencodev1, Kilo and MiMo Code (Read/Write/Edit/Bash to read/write/edit/bash), leaving the slash-command matcher of userPromptExpansion as written. Translate and warn once per distinct matcher of an event, and reword the warning to say the name is not translated by rulesync. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
The plugins test matchers unanchored, so a translated Write also matched OpenCode's todowrite and Read matched todoread. Anchor a translated plain-name matcher as ^(?:...)$ to keep Claude Code's exact-name semantics, leaving regex-style and untranslated matchers as written. Quote the event name in the untranslated-name warning, add a MiMo Code test, and document the anchoring and that Edit/Write guards do not cover patch/apply_patch. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
…encode-matchers # Conflicts: # src/generated/docs-content.ts
Owner
Author
|
@dyoshikawa Thank you! |
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.
Closes #3944
Summary
OpenCode reports lowercase tool ids and the generated plugins test matchers case-sensitively, so canonical matchers such as
Read|Edit|Writewere copied as-is intorulesync-hooks.jsand never fired.Following the Antigravity / Cortex Code pattern, both plugin generators now rewrite whole canonical names in tool matchers via
replaceMatcherNames, through a sharedcreateOpencodeMatcherTranslatorinopencode-style-generator.ts:opencode(V2 plugin):Read->read,Write->write,Edit->edit,Bash->shell(the V2 name; the existing{ shell: "bash", subagent: "task" }alias still lets a V1-stylebashmatcher fire)opencodev1, Kilo and MiMo Code (V1 plugin): the same, withBash->bash, the id the V1 shell events already gate on (input.tool === "bash"). Nothing in the code suggests Kilo or MiMo Code use different tool ids, so none of them is excluded.The plugins test matchers unanchored, so a translated plain-name matcher (only
[A-Za-z0-9_]names joined by|) is anchored as^(?:...)$, keeping Claude Code's exact-name semantics:Writebecomes^(?:write)$and no longer also matchestodowrite(which a blocking file guard would otherwise abort). Regex-style and untranslated matchers are written as-is.Only matchers tested against the tool id are translated; the
userPromptExpansionmatcher (tested against the slash command name) is left as written. Each distinct matcher of an event is translated once, and any capitalized name left over (e.g.MultiEdit,Glob) gets onecapitalizedMatcherNameswarning saying it is not translated by rulesync and will likely never match. Partial names (ReadFile,mcp__srv__Read) and lowercase names are untouched. No other name mappings are added.docs/reference/file-formats.mddocuments the translation, the anchoring, and that translatedEdit/Writeguards do not cover OpenCode'spatch/apply_patchtools.OpenCode hooks have no import path (
toRulesyncHooksthrows), so there is no reverse mapping to add.Tests
opencode-hooks.test.ts(V2) andopencodev1-hooks.test.ts(V1): the compiled matchers of a generated plugin showWritematcheswritebut nottodowrite,Read|Edit|Writematchesread/edit/writebut nottodoread/todowrite/multiedit, and a regex matcher (^Wr) is unchanged.^Bash$->^shell$/^bash$,\bRead\btranslated butReadFile/mcp__srv__Readuntouched, override (opencode.hooks/opencodev1.hooks) matchers, slash-command matcher untouched, one warning per distinct matcher.kilo-hooks.test.tsandmimocode-hooks.test.ts: the V1 translation path and warning; existing expectations updated to the anchored lowercase output.pnpm cicheckpasses.🤖 Generated with Claude Code
https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4